mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
small slimes cannot attack a player
This commit is contained in:
parent
447638816e
commit
612e09e0cc
3 changed files with 33 additions and 23 deletions
|
|
@ -22,6 +22,7 @@ class EntityAPI{
|
||||||
|
|
||||||
|
|
||||||
public function commandHandler($cmd, $args, $issuer, $alias){
|
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||||
|
//todo "MOB_".strtoupper($args[0]);
|
||||||
$mob = [
|
$mob = [
|
||||||
"chicken" => 10,
|
"chicken" => 10,
|
||||||
"cow" => 11,
|
"cow" => 11,
|
||||||
|
|
@ -54,7 +55,8 @@ class EntityAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_int($args[0])) $type = $args[0];
|
if(is_int($args[0])) $type = $args[0];
|
||||||
else $type = $mob[strtolower($args[0])];
|
elseif(isset($mob[strtolower($args[0])])) $type = $mob[strtolower($args[0])];
|
||||||
|
else return "Unknown mob.";
|
||||||
if($type < 10 || $type > 39){
|
if($type < 10 || $type > 39){
|
||||||
return "Unknown mob.";
|
return "Unknown mob.";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,19 @@
|
||||||
/**
|
/**
|
||||||
* A Tempt but for Monsters
|
* A Tempt but for Monsters
|
||||||
*/
|
*/
|
||||||
class TaskAttackPlayer extends TaskTempt
|
class TaskAttackPlayer extends TaskTempt{
|
||||||
{
|
|
||||||
public $attackTime = 0;
|
public $attackTime = 0;
|
||||||
public function onStart(EntityAI $ai)
|
|
||||||
{
|
public function onStart(EntityAI $ai){
|
||||||
$this->selfCounter = 1;
|
$this->selfCounter = 1;
|
||||||
}
|
}
|
||||||
public function onUpdate(EntityAI $ai)
|
|
||||||
{
|
public function onUpdate(EntityAI $ai){
|
||||||
if(!($this->target instanceof Entity) || ($ai->entity instanceof Spider && $ai->entity->level->isDay()) || ($this->target instanceof Entity && !$this->target->isPlayer()) || (Utils::distance_noroot($this->target, $ai->entity) > 256) || $this->target->level->getName() != $ai->entity->level->getName()){
|
if(!($this->target instanceof Entity)
|
||||||
|
|| ($ai->entity instanceof Spider && $ai->entity->level->isDay())
|
||||||
|
|| ($this->target instanceof Entity && !$this->target->isPlayer())
|
||||||
|
|| (Utils::distance_noroot($this->target, $ai->entity) > 256)
|
||||||
|
|| $this->target->level->getName() != $ai->entity->level->getName()){
|
||||||
$this->reset();
|
$this->reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -21,21 +24,27 @@ class TaskAttackPlayer extends TaskTempt
|
||||||
$mult = $ai->entity instanceof Spider ? 1 : 2;
|
$mult = $ai->entity instanceof Spider ? 1 : 2;
|
||||||
$radius = ($ai->entity->width * $mult)*($ai->entity->width * $mult);
|
$radius = ($ai->entity->width * $mult)*($ai->entity->width * $mult);
|
||||||
if(Utils::distance_noroot($this->target, $ai->entity) <= $radius && $this->attackTime <= 0){
|
if(Utils::distance_noroot($this->target, $ai->entity) <= $radius && $this->attackTime <= 0){
|
||||||
$ai->entity->attackEntity($this->target);
|
if($ai->entity instanceof Slime && $ai->entity->getSlimeSize() == 1){
|
||||||
$this->attackTime = 20;
|
$this->attackTime = 20;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$ai->entity->attackEntity($this->target);
|
||||||
|
$this->attackTime = 20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--$this->attackTime;
|
--$this->attackTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
public function canBeExecuted(EntityAI $ai)
|
|
||||||
{
|
public function canBeExecuted(EntityAI $ai){
|
||||||
$target = $this->findTarget($ai->entity, 16);
|
$target = $this->findTarget($ai->entity, 16);
|
||||||
if(($ai->entity instanceof Spider && !$ai->entity->level->isDay()) || $target instanceof Entity && $target->class === ENTITY_PLAYER && $target->isPlayer()){
|
if(($ai->entity instanceof Spider && !$ai->entity->level->isDay())
|
||||||
|
|| $target instanceof Entity
|
||||||
|
&& $target->class === ENTITY_PLAYER
|
||||||
|
&& $target->isPlayer()){
|
||||||
$this->target = $target; //TODO get rid of it
|
$this->target = $target; //TODO get rid of it
|
||||||
$ai->entity->target = $target;
|
$ai->entity->target = $target;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Slime extends Monster
|
class Slime extends Monster{
|
||||||
{
|
|
||||||
const TYPE = MOB_SLIME;
|
const TYPE = MOB_SLIME;
|
||||||
protected $size;
|
public $size;
|
||||||
|
|
||||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
$this->setName("Slime");
|
$this->setName("Slime");
|
||||||
|
|
@ -26,9 +26,9 @@ class Slime extends Monster
|
||||||
$xOff = (($cnt % 2) - 0.5) * $s / 4;
|
$xOff = (($cnt % 2) - 0.5) * $s / 4;
|
||||||
$zOff = (($cnt / 2) - 0.5) * $s / 4;
|
$zOff = (($cnt / 2) - 0.5) * $s / 4;
|
||||||
$e = $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
$e = $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||||
"x" => $this->x+$xOff,
|
"x" => $this->x + $xOff,
|
||||||
"y"=> $this->y + 1,
|
"y"=> $this->y + 1,
|
||||||
"z" => $this->z+$zOff,
|
"z" => $this->z + $zOff,
|
||||||
"Size" => (int) ($s / 2)
|
"Size" => (int) ($s / 2)
|
||||||
]);
|
]);
|
||||||
$this->server->api->entity->spawnToAll($e);
|
$this->server->api->entity->spawnToAll($e);
|
||||||
|
|
@ -39,7 +39,7 @@ class Slime extends Monster
|
||||||
|
|
||||||
public function setSlimeSize($i){
|
public function setSlimeSize($i){
|
||||||
$this->size = $i;
|
$this->size = $i;
|
||||||
$this->setSize(0.6*$i, 0.6*$i);
|
$this->setSize(0.6 * $i, 0.6 * $i);
|
||||||
$this->setHealth($i * $i);
|
$this->setHealth($i * $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,8 +49,7 @@ class Slime extends Monster
|
||||||
return $sd;
|
return $sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata()
|
public function getMetadata(){
|
||||||
{
|
|
||||||
$ret = parent::getMetadata();
|
$ret = parent::getMetadata();
|
||||||
$ret[16]["value"] = $this->size;
|
$ret[16]["value"] = $this->size;
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue