GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Entity Class Reference

Public Member Functions

 __construct (Level $level, CompoundTag $nbt)
 
 getHeight ()
 
 getWidth ()
 
 getLength ()
 
 setScale ($scale)
 
 getScale ()
 
 getDropExpMin ()
 
 getDropExpMax ()
 
 getNameTag ()
 
 isNameTagVisible ()
 
 isNameTagAlwaysVisible ()
 
 setNameTag ($name)
 
 setNameTagVisible ($value=true)
 
 setNameTagAlwaysVisible ($value=true)
 
 isSneaking ()
 
 setSneaking ($value=true)
 
 isSprinting ()
 
 setSprinting ($value=true)
 
 isGliding ()
 
 setGliding ($value=true)
 
 isImmobile ()
 
 setImmobile ($value=true)
 
 canClimb ()
 
 setCanClimb (bool $value)
 
 canClimbWalls ()
 
 setCanClimbWalls (bool $value=true)
 
 getOwningEntityId ()
 
 getOwningEntity ()
 
 setOwningEntity (Entity $owner)
 
 getEffects ()
 
 removeAllEffects ()
 
 removeEffect ($effectId)
 
 getEffect ($effectId)
 
 hasEffect ($effectId)
 
 addEffect (Effect $effect)
 
 getSaveId ()
 
 saveNBT ()
 
 getViewers ()
 
 spawnTo (Player $player)
 
 sendPotionEffects (Player $player)
 
 sendData ($player, array $data=null)
 
 despawnFrom (Player $player, bool $send=true)
 
 attack ($damage, EntityDamageEvent $source)
 
 heal ($amount, EntityRegainHealthEvent $source)
 
 getHealth ()
 
 isAlive ()
 
 setHealth ($amount)
 
 setLastDamageCause (EntityDamageEvent $type)
 
 getLastDamageCause ()
 
 getAttributeMap ()
 
 getMaxHealth ()
 
 setMaxHealth ($amount)
 
 canCollideWith (Entity $entity)
 
 entityBaseTick ($tickDiff=1)
 
 getDirectionVector ()
 
 getDirectionPlane ()
 
 onUpdate ($currentTick)
 
 scheduleUpdate ()
 
 isOnFire ()
 
 setOnFire ($seconds)
 
 isFireProof ()
 
 getDirection ()
 
 extinguish ()
 
 canTriggerWalking ()
 
 resetFallDistance ()
 
 getBoundingBox ()
 
 fall ($fallDistance)
 
 handleLavaMovement ()
 
 getEyeHeight ()
 
 moveFlying ()
 
 onCollideWithPlayer (Human $entityPlayer)
 
 getPosition ()
 
 getLocation ()
 
 isInsideOfPortal ()
 
 isInsideOfWater ()
 
 isInsideOfSolid ()
 
 isInsideOfFire ()
 
 fastMove ($dx, $dy, $dz)
 
 move ($dx, $dy, $dz)
 
 getBlocksAround ()
 
 setPositionAndRotation (Vector3 $pos, $yaw, $pitch)
 
 setRotation ($yaw, $pitch)
 
 setLocation (Location $pos)
 
 setPosition (Vector3 $pos)
 
 getMotion ()
 
 setMotion (Vector3 $motion)
 
 isOnGround ()
 
 kill ()
 
 teleport (Vector3 $pos, $yaw=null, $pitch=null)
 
 getId ()
 
 respawnToAll ()
 
 spawnToAll ()
 
 despawnFromAll ()
 
 close ()
 
 setDataProperty ($id, $type, $value)
 
 linkEntity (Entity $entity)
 
 sendLinkedData ()
 
 setLinked ($type=0, Entity $entity)
 
 getLinkedEntity ()
 
 getLinkedType ()
 
 getDataProperty ($id)
 
 getDataPropertyType ($id)
 
 setDataFlag ($propertyId, $id, $value=true, $type=self::DATA_TYPE_LONG)
 
 getDataFlag ($propertyId, $id)
 
 __destruct ()
 
 setMetadata ($metadataKey, MetadataValue $metadataValue)
 
 getMetadata ($metadataKey)
 
 hasMetadata ($metadataKey)
 
 removeMetadata ($metadataKey, Plugin $plugin)
 
 __toString ()
 
- Public Member Functions inherited from Location
 __construct ($x=0, $y=0, $z=0, $yaw=0.0, $pitch=0.0, Level $level=null)
 
 asLocation ()
 
 add ($x, $y=0, $z=0, $yaw=0, $pitch=0)
 
 getYaw ()
 
 getPitch ()
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 
- Public Member Functions inherited from Position
 __construct ($x=0, $y=0, $z=0, Level $level=null)
 
 asPosition ()
 
 add ($x, $y=0, $z=0)
 
 getLevel ()
 
 setLevel (Level $level=null)
 
 isValid ()
 
 getSide ($side, $step=1)
 
 __toString ()
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
- Public Member Functions inherited from Vector3
 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 

Static Public Member Functions

static init ()
 
static createEntity ($type, Level $level, CompoundTag $nbt,... $args)
 
static registerEntity ($className, $force=false)
 
- Static Public Member Functions inherited from Location
static fromObject (Vector3 $pos, Level $level=null, $yaw=0.0, $pitch=0.0)
 
- Static Public Member Functions inherited from Position
static fromObject (Vector3 $pos, Level $level=null)
 
- Static Public Member Functions inherited from Vector3
static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 

Data Fields

const NETWORK_ID = -1
 
const DATA_TYPE_BYTE = 0
 
const DATA_TYPE_SHORT = 1
 
const DATA_TYPE_INT = 2
 
const DATA_TYPE_FLOAT = 3
 
const DATA_TYPE_STRING = 4
 
const DATA_TYPE_SLOT = 5
 
const DATA_TYPE_POS = 6
 
const DATA_TYPE_LONG = 7
 
const DATA_TYPE_VECTOR3F = 8
 
const DATA_FLAGS = 0
 
const DATA_HEALTH = 1
 
const DATA_VARIANT = 2
 
const DATA_COLOR = 3
 
const DATA_COLOUR = 3
 
const DATA_NAMETAG = 4
 
const DATA_OWNER_EID = 5
 
const DATA_TARGET_EID = 6
 
const DATA_AIR = 7
 
const DATA_POTION_COLOR = 8
 
const DATA_POTION_AMBIENT = 9
 
const DATA_HURT_TIME = 11
 
const DATA_HURT_DIRECTION = 12
 
const DATA_PADDLE_TIME_LEFT = 13
 
const DATA_PADDLE_TIME_RIGHT = 14
 
const DATA_EXPERIENCE_VALUE = 15
 
const DATA_MINECART_DISPLAY_BLOCK = 16
 
const DATA_MINECART_DISPLAY_OFFSET = 17
 
const DATA_MINECART_HAS_DISPLAY = 18
 
const DATA_ENDERMAN_HELD_ITEM_ID = 23
 
const DATA_ENDERMAN_HELD_ITEM_DAMAGE = 24
 
const DATA_ENTITY_AGE = 25
 
const DATA_FIREBALL_POWER_X = 30
 
const DATA_FIREBALL_POWER_Y = 31
 
const DATA_FIREBALL_POWER_Z = 32
 
const DATA_POTION_AUX_VALUE = 37
 
const DATA_LEAD_HOLDER_EID = 38
 
const DATA_SCALE = 39
 
const DATA_INTERACTIVE_TAG = 40
 
const DATA_NPC_SKIN_ID = 41
 
const DATA_URL_TAG = 42
 
const DATA_MAX_AIR = 43
 
const DATA_MARK_VARIANT = 44
 
const DATA_BLOCK_TARGET = 48
 
const DATA_WITHER_INVULNERABLE_TICKS = 49
 
const DATA_WITHER_TARGET_1 = 50
 
const DATA_WITHER_TARGET_2 = 51
 
const DATA_WITHER_TARGET_3 = 52
 
const DATA_BOUNDING_BOX_WIDTH = 54
 
const DATA_BOUNDING_BOX_HEIGHT = 55
 
const DATA_FUSE_LENGTH = 56
 
const DATA_RIDER_SEAT_POSITION = 57
 
const DATA_RIDER_ROTATION_LOCKED = 58
 
const DATA_RIDER_MAX_ROTATION = 59
 
const DATA_RIDER_MIN_ROTATION = 60
 
const DATA_AREA_EFFECT_CLOUD_RADIUS = 61
 
const DATA_AREA_EFFECT_CLOUD_WAITING = 62
 
const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63
 
const DATA_SHULKER_ATTACH_FACE = 65
 
const DATA_SHULKER_ATTACH_POS = 67
 
const DATA_TRADING_PLAYER_EID = 68
 
const DATA_COMMAND_BLOCK_COMMAND = 71
 
const DATA_COMMAND_BLOCK_LAST_OUTPUT = 72
 
const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73
 
const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74
 
const DATA_STRENGTH = 75
 
const DATA_MAX_STRENGTH = 76
 
const DATA_FLAG_ONFIRE = 0
 
const DATA_FLAG_SNEAKING = 1
 
const DATA_FLAG_RIDING = 2
 
const DATA_FLAG_SPRINTING = 3
 
const DATA_FLAG_ACTION = 4
 
const DATA_FLAG_INVISIBLE = 5
 
const DATA_FLAG_TEMPTED = 6
 
const DATA_FLAG_INLOVE = 7
 
const DATA_FLAG_SADDLED = 8
 
const DATA_FLAG_POWERED = 9
 
const DATA_FLAG_IGNITED = 10
 
const DATA_FLAG_BABY = 11
 
const DATA_FLAG_CONVERTING = 12
 
const DATA_FLAG_CRITICAL = 13
 
const DATA_FLAG_CAN_SHOW_NAMETAG = 14
 
const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15
 
const DATA_FLAG_IMMOBILE = 16
 
const DATA_FLAG_NO_AI = 16
 
const DATA_FLAG_SILENT = 17
 
const DATA_FLAG_WALLCLIMBING = 18
 
const DATA_FLAG_CAN_CLIMB = 19
 
const DATA_FLAG_SWIMMER = 20
 
const DATA_FLAG_CAN_FLY = 21
 
const DATA_FLAG_RESTING = 22
 
const DATA_FLAG_SITTING = 23
 
const DATA_FLAG_ANGRY = 24
 
const DATA_FLAG_INTERESTED = 25
 
const DATA_FLAG_CHARGED = 26
 
const DATA_FLAG_TAMED = 27
 
const DATA_FLAG_LEASHED = 28
 
const DATA_FLAG_SHEARED = 29
 
const DATA_FLAG_GLIDING = 30
 
const DATA_FLAG_ELDER = 31
 
const DATA_FLAG_MOVING = 32
 
const DATA_FLAG_BREATHING = 33
 
const DATA_FLAG_CHESTED = 34
 
const DATA_FLAG_STACKABLE = 35
 
const DATA_FLAG_SHOWBASE = 36
 
const DATA_FLAG_REARING = 37
 
const DATA_FLAG_VIBRATING = 38
 
const DATA_FLAG_IDLING = 39
 
const DATA_FLAG_EVOKER_SPELL = 40
 
const DATA_FLAG_CHARGE_ATTACK = 41
 
const DATA_FLAG_LINGER = 45
 
const SOUTH = 0
 
const WEST = 1
 
const NORTH = 2
 
const EAST = 3
 
 $passenger = null
 
 $vehicle = null
 
 $chunk
 
 $lastX = null
 
 $lastY = null
 
 $lastZ = null
 
 $motionX
 
 $motionY
 
 $motionZ
 
 $temporalVector
 
 $lastMotionX
 
 $lastMotionY
 
 $lastMotionZ
 
 $lastYaw
 
 $lastPitch
 
 $boundingBox
 
 $onGround
 
 $inBlock = false
 
 $positionChanged
 
 $motionChanged
 
 $deadTicks = 0
 
 $height
 
 $eyeHeight = null
 
 $width
 
 $length
 
 $keepMovement = false
 
 $fallDistance = 0
 
 $ticksLived = 0
 
 $lastUpdate
 
 $maxFireTicks
 
 $fireTicks = 0
 
 $namedtag
 
 $canCollide = true
 
 $isCollided = false
 
 $isCollidedHorizontally = false
 
 $isCollidedVertically = false
 
 $noDamageTicks
 
 $closed = false
 
 $dropExp = [0, 0]
 
- Data Fields inherited from Location
 $yaw
 
 $pitch
 
- Data Fields inherited from Position
 $level = null
 
- Data Fields inherited from Vector3
const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 

Static Public Attributes

static $entityCount = 1
 

Protected Member Functions

 recalculateEffectColor ()
 
 initEntity ()
 
 addAttributes ()
 
 checkObstruction ($x, $y, $z)
 
 updateMovement ()
 
 updateFallState ($distanceThisTick, $onGround)
 
 switchLevel (Level $targetLevel)
 
 checkGroundState ($movX, $movY, $movZ, $dx, $dy, $dz)
 
 checkBlockCollision ()
 
 checkChunks ()
 

Protected Attributes

 $hasSpawned = []
 
 $effects = []
 
 $id
 
 $dataFlags = 0
 
 $dataProperties
 
 $lastDamageCause = null
 
 $age = 0
 
 $ySize = 0
 
 $stepHeight = 0
 
 $isStatic = false
 
 $justCreated
 
 $attributeMap
 
 $gravity
 
 $drag
 
 $server
 
 $timings
 
 $isPlayer = false
 
 $linkedEntity = null
 
 $linkedType = null
 
 $riding = null
 
 $activatedPressurePlates = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
CompoundTag  $nbt 
)

Entity constructor.

Parameters
Level$level
CompoundTag$nbt
415  {
416  $this->timings = Timings::getEntityTimings($this);
417 
418  $this->isPlayer = $this instanceof Player;
419 
420  $this->temporalVector = new Vector3();
421 
422  if($this->eyeHeight === null){
423  $this->eyeHeight = $this->height / 2 + 0.1;
424  }
425 
426  $this->id = Entity::$entityCount++;
427  $this->justCreated = true;
428  $this->namedtag = $nbt;
429 
430  $this->chunk = $level->getChunk($this->namedtag["Pos"][0] >> 4, $this->namedtag["Pos"][2] >> 4);
431  assert($this->chunk !== null);
432  $this->setLevel($level);
433  $this->server = $level->getServer();
434 
435  $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
436  $this->setPositionAndRotation(
437  $this->temporalVector->setComponents(
438  $this->namedtag["Pos"][0],
439  $this->namedtag["Pos"][1],
440  $this->namedtag["Pos"][2]
441  ),
442  $this->namedtag->Rotation[0],
443  $this->namedtag->Rotation[1]
444  );
445  $this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
446 
447  assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
448 
449  if(!isset($this->namedtag->FallDistance)){
450  $this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
451  }
452  $this->fallDistance = $this->namedtag["FallDistance"];
453 
454  if(!isset($this->namedtag->Fire)){
455  $this->namedtag->Fire = new ShortTag("Fire", 0);
456  }
457  $this->fireTicks = $this->namedtag["Fire"];
458 
459  if(!isset($this->namedtag->Air)){
460  $this->namedtag->Air = new ShortTag("Air", 300);
461  }
462  $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]);
463 
464  if(!isset($this->namedtag->OnGround)){
465  $this->namedtag->OnGround = new ByteTag("OnGround", 0);
466  }
467  $this->onGround = $this->namedtag["OnGround"] > 0 ? true : false;
468 
469  if(!isset($this->namedtag->Invulnerable)){
470  $this->namedtag->Invulnerable = new ByteTag("Invulnerable", 0);
471  }
472  $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
473 
474  $this->attributeMap = new AttributeMap();
475 
476  $this->chunk->addEntity($this);
477  $this->level->addEntity($this);
478  $this->initEntity();
479  $this->lastUpdate = $this->server->getTick();
480  $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
481 
482  $this->scheduleUpdate();
483 
484  }

◆ __destruct()

__destruct ( )
2393  {
2394  $this->close();
2395  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string
2434  {
2435  return (new \ReflectionClass($this))->getShortName() . "(" . $this->getId() . ")";
2436  }

◆ addAttributes()

addAttributes ( )
protected
980  {
981  }

◆ addEffect()

addEffect ( Effect  $effect)
Parameters
Effect$effect
Returns
bool
778  {
779  Server::getInstance()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($this, $effect));
780  if($ev->isCancelled()){
781  return false;
782  }
783  if($effect->getId() === Effect::HEALTH_BOOST){
784  $this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1));
785  }
786  if($effect->getId() === Effect::ABSORPTION and $this instanceof Human){
787  $this->setAbsorption(4 * ($effect->getAmplifier() + 1));
788  }
789 
790  if(isset($this->effects[$effect->getId()])){
791  $oldEffect = $this->effects[$effect->getId()];
792  if(($effect->getAmplifier() <= ($oldEffect->getAmplifier())) and $effect->getDuration() < $oldEffect->getDuration()){
793  return false;
794  }
795  $effect->add($this, true, $oldEffect);
796  }else{
797  $effect->add($this, false);
798  }
799 
800  $this->effects[$effect->getId()] = $effect;
801 
802  $this->recalculateEffectColor();
803 
804  return true;
805  }

◆ attack()

attack (   $damage,
EntityDamageEvent  $source 
)
Parameters
float$damage
EntityDamageEvent$source
Returns
bool
1061  {
1063  and ($source->getCause() === EntityDamageEvent::CAUSE_FIRE
1064  or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK
1065  or $source->getCause() === EntityDamageEvent::CAUSE_LAVA)
1066  ){
1067  $source->setCancelled();
1068  }
1069 
1070  $this->server->getPluginManager()->callEvent($source);
1071  if($source->isCancelled()){
1072  return false;
1073  }
1074  $this->setLastDamageCause($source);
1075 
1076  if($this instanceof Human){
1077  $damage = round($source->getFinalDamage());
1078  if($this->getAbsorption() > 0){
1079  $absorption = $this->getAbsorption() - $damage;
1080  $this->setAbsorption($absorption <= 0 ? 0 : $absorption);
1081  $this->setHealth($this->getHealth() + $absorption);
1082  }else{
1083  $this->setHealth($this->getHealth() - $damage);
1084  }
1085  }else{
1086  $this->setHealth($this->getHealth() - round($source->getFinalDamage()));
1087  }
1088 
1089  return true;
1090  }

◆ canClimb()

canClimb ( )

Returns whether the entity is able to climb blocks such as ladders or vines.

Returns
bool
647  : bool{
648  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB);
649  }

◆ canClimbWalls()

canClimbWalls ( )

Returns whether this entity is climbing a block. By default this is only true if the entity is climbing a ladder or vine or similar block.

Returns
bool
665  : bool{
666  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING);
667  }

◆ canCollideWith()

canCollideWith ( Entity  $entity)
Parameters
Entity$entity
Returns
bool
1182  {
1183  return !$this->justCreated and $entity !== $this;
1184  }

◆ canTriggerWalking()

canTriggerWalking ( )
Returns
bool
1513  {
1514  return true;
1515  }

◆ checkBlockCollision()

checkBlockCollision ( )
protected
1959  {
1960  $vector = new Vector3(0, 0, 0);
1961 
1962  foreach($blocksaround = $this->getBlocksAround() as $block){
1963  $block->onEntityCollide($this);
1964  $block->addVelocityToEntity($this, $vector);
1965  }
1966 
1967  if($vector->lengthSquared() > 0){
1968  $vector = $vector->normalize();
1969  $d = 0.014;
1970  $this->motionX += $vector->x * $d;
1971  $this->motionY += $vector->y * $d;
1972  $this->motionZ += $vector->z * $d;
1973  }
1974  }

◆ checkChunks()

checkChunks ( )
protected
2003  {
2004  if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){
2005  if($this->chunk !== null){
2006  $this->chunk->removeEntity($this);
2007  }
2008  $this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4, true);
2009 
2010  if(!$this->justCreated){
2011  $newChunk = $this->level->getChunkPlayers($this->x >> 4, $this->z >> 4);
2012  foreach($this->hasSpawned as $player){
2013  if(!isset($newChunk[$player->getLoaderId()])){
2014  $this->despawnFrom($player);
2015  }else{
2016  unset($newChunk[$player->getLoaderId()]);
2017  }
2018  }
2019  foreach($newChunk as $player){
2020  $this->spawnTo($player);
2021  }
2022  }
2023 
2024  if($this->chunk === null){
2025  return;
2026  }
2027 
2028  $this->chunk->addEntity($this);
2029  }
2030  }

◆ checkGroundState()

checkGroundState (   $movX,
  $movY,
  $movZ,
  $dx,
  $dy,
  $dz 
)
protected
Parameters
$movX
$movY
$movZ
$dx
$dy
$dz
1923  {
1924  $this->isCollidedVertically = $movY != $dy;
1925  $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
1926  $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
1927  $this->onGround = ($movY != $dy and $movY < 0);
1928  }

◆ checkObstruction()

checkObstruction (   $x,
  $y,
  $z 
)
protected
Parameters
$x
$y
$z
Returns
bool
1193  {
1194  $i = Math::floorFloat($x);
1195  $j = Math::floorFloat($y);
1196  $k = Math::floorFloat($z);
1197 
1198  $diffX = $x - $i;
1199  $diffY = $y - $j;
1200  $diffZ = $z - $k;
1201 
1202  if(Block::$solid[$this->level->getBlockIdAt($i, $j, $k)]){
1203  $flag = !Block::$solid[$this->level->getBlockIdAt($i - 1, $j, $k)];
1204  $flag1 = !Block::$solid[$this->level->getBlockIdAt($i + 1, $j, $k)];
1205  $flag2 = !Block::$solid[$this->level->getBlockIdAt($i, $j - 1, $k)];
1206  $flag3 = !Block::$solid[$this->level->getBlockIdAt($i, $j + 1, $k)];
1207  $flag4 = !Block::$solid[$this->level->getBlockIdAt($i, $j, $k - 1)];
1208  $flag5 = !Block::$solid[$this->level->getBlockIdAt($i, $j, $k + 1)];
1209 
1210  $direction = -1;
1211  $limit = 9999;
1212 
1213  if($flag){
1214  $limit = $diffX;
1215  $direction = 0;
1216  }
1217 
1218  if($flag1 and 1 - $diffX < $limit){
1219  $limit = 1 - $diffX;
1220  $direction = 1;
1221  }
1222 
1223  if($flag2 and $diffY < $limit){
1224  $limit = $diffY;
1225  $direction = 2;
1226  }
1227 
1228  if($flag3 and 1 - $diffY < $limit){
1229  $limit = 1 - $diffY;
1230  $direction = 3;
1231  }
1232 
1233  if($flag4 and $diffZ < $limit){
1234  $limit = $diffZ;
1235  $direction = 4;
1236  }
1237 
1238  if($flag5 and 1 - $diffZ < $limit){
1239  $direction = 5;
1240  }
1241 
1242  $force = lcg_value() * 0.2 + 0.1;
1243 
1244  if($direction === 0){
1245  $this->motionX = -$force;
1246 
1247  return true;
1248  }
1249 
1250  if($direction === 1){
1251  $this->motionX = $force;
1252 
1253  return true;
1254  }
1255 
1256  if($direction === 2){
1257  $this->motionY = -$force;
1258 
1259  return true;
1260  }
1261 
1262  if($direction === 3){
1263  $this->motionY = $force;
1264 
1265  return true;
1266  }
1267 
1268  if($direction === 4){
1269  $this->motionZ = -$force;
1270 
1271  return true;
1272  }
1273 
1274  if($direction === 5){
1275  $this->motionZ = $force;
1276 
1277  return true;
1278  }
1279  }
1280 
1281  return false;
1282  }

◆ close()

close ( )
2196  {
2197  if(!$this->closed){
2198  $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
2199  $this->closed = true;
2201  $this->despawnFromAll();
2202  if($this->linkedType != 0){
2203  $this->linkedEntity->setLinked(0, $this);
2204  }
2205  if($this->chunk !== null){
2206  $this->chunk->removeEntity($this);
2207  $this->chunk = null;
2208  }
2209  if($this->getLevel() !== null){
2210  $this->getLevel()->removeEntity($this);
2211  //$this->setLevel(null);
2212  }
2213 
2214  $this->namedtag = null;
2215  }
2216 
2217  $this->activatedPressurePlates = [];
2218 
2219  if($this->attributeMap != null){
2220  $this->attributeMap = null;
2221  }
2222  }

◆ createEntity()

static createEntity (   $type,
Level  $level,
CompoundTag  $nbt,
  $args 
)
static
Parameters
int | string$type
Level$level
CompoundTag$nbt
$args
Returns
Entity|Projectile
846  {
847  if(isset(self::$knownEntities[$type])){
848  $class = self::$knownEntities[$type];
849 
850  return new $class($level, $nbt, ...$args);
851  }
852 
853  return null;
854  }

◆ despawnFrom()

despawnFrom ( Player  $player,
bool  $send = true 
)
Parameters
Player$player
bool$send
1044  {
1045  if(isset($this->hasSpawned[$player->getLoaderId()])){
1046  if($send){
1047  $pk = new RemoveEntityPacket();
1048  $pk->eid = $this->id;
1049  $player->dataPacket($pk);
1050  }
1051  unset($this->hasSpawned[$player->getLoaderId()]);
1052  }
1053  }

◆ despawnFromAll()

despawnFromAll ( )
2190  {
2191  foreach($this->hasSpawned as $player){
2192  $this->despawnFrom($player);
2193  }
2194  }

◆ entityBaseTick()

entityBaseTick (   $tickDiff = 1)
Parameters
int$tickDiff
Returns
bool
1289  {
1290 
1291  Timings::$timerEntityBaseTick->startTiming();
1292  //TODO: check vehicles
1293 
1294  $this->blocksAround = null;
1295  $this->justCreated = false;
1296 
1297  if(!$this->isAlive()){
1298  $this->removeAllEffects();
1299  $this->despawnFromAll();
1300  if(!$this->isPlayer){
1301  $this->close();
1302  }
1303 
1304  Timings::$timerEntityBaseTick->stopTiming();
1305 
1306  return false;
1307  }
1308 
1309  if(count($this->effects) > 0){
1310  foreach($this->effects as $effect){
1311  if($effect->canTick()){
1312  $effect->applyEffect($this);
1313  }
1314  $effect->setDuration($effect->getDuration() - $tickDiff);
1315  if($effect->getDuration() <= 0){
1316  $this->removeEffect($effect->getId());
1317  }
1318  }
1319  }
1320 
1321  $hasUpdate = false;
1322 
1323  $this->checkBlockCollision();
1324 
1325  if($this->y <= -16 and $this->isAlive()){
1326  $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
1327  $this->attack($ev->getFinalDamage(), $ev);
1328  $hasUpdate = true;
1329  }
1330 
1331  if($this->fireTicks > 0){
1332  if($this->isFireProof()){
1333  if($this->fireTicks > 1){
1334  $this->fireTicks = 1;
1335  }else{
1336  $this->fireTicks -= 1;
1337  }
1338  }else{
1339  if(!$this->hasEffect(Effect::FIRE_RESISTANCE) and (($this->fireTicks % 20) === 0 or $tickDiff > 20)){
1340  $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
1341  $this->attack($ev->getFinalDamage(), $ev);
1342  }
1343  $this->fireTicks -= $tickDiff;
1344  }
1345 
1346  if($this->fireTicks <= 0 && $this->fireTicks > -10){
1347  $this->extinguish();
1348  }else{
1349  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, true);
1350  $hasUpdate = true;
1351  }
1352  }
1353 
1354  if($this->noDamageTicks > 0){
1355  $this->noDamageTicks -= $tickDiff;
1356  if($this->noDamageTicks < 0){
1357  $this->noDamageTicks = 0;
1358  }
1359  }
1360 
1361  $this->age += $tickDiff;
1362  $this->ticksLived += $tickDiff;
1363 
1364  Timings::$timerEntityBaseTick->stopTiming();
1365 
1366  return $hasUpdate;
1367  }

◆ extinguish()

extinguish ( )
1505  {
1506  $this->fireTicks = 0;
1507  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, false);
1508  }

◆ fall()

fall (   $fallDistance)
Parameters
$fallDistance
1548  {
1549  if($this instanceof Player and $this->isSpectator()){
1550  return;
1551  }
1552  if($fallDistance > 3){
1553  $this->getLevel()->addParticle(new DestroyBlockParticle($this, $this->getLevel()->getBlock($this->floor()->subtract(0, 1, 0))));
1554  }
1555  if($this->isInsideOfWater()){
1556  return;
1557  }
1558  $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getAmplifier() + 1 : 0));
1559 
1560  //Get the block directly beneath the player's feet, check if it is a slime block
1561  if($this->getLevel()->getBlock($this->floor()->subtract(0, 1, 0)) instanceof SlimeBlock){
1562  $damage = 0;
1563  }
1564  //TODO Improve
1565  if($this instanceof Player){
1566  if($this->getInventory()->getChestplate() instanceof Elytra){
1567  $damage = 0;
1568  }
1569  }
1570  if($damage > 0){
1571  $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
1572  $this->attack($ev->getFinalDamage(), $ev);
1573  }
1574  }

◆ fastMove()

fastMove (   $dx,
  $dy,
  $dz 
)
Parameters
$dx
$dy
$dz
Returns
bool
1707  {
1708  if($dx == 0 and $dz == 0 and $dy == 0){
1709  return true;
1710  }
1711 
1712  Timings::$entityMoveTimer->startTiming();
1713 
1714  /*$newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz);
1715 
1716  $list = $this->level->getCollisionCubes($this, $newBB, false);
1717 
1718  if(count($list) === 0){
1719  $this->boundingBox = $newBB;
1720  }*/
1721 
1722  $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
1723  $this->y = $this->boundingBox->minY - $this->ySize;
1724  $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
1725 
1726  $this->checkChunks();
1727 
1728  if(!$this->onGround or $dy != 0){
1729  $bb = clone $this->boundingBox;
1730  $bb->minY -= 0.75;
1731  $this->onGround = false;
1732  if(!$this->level->getBlock(new Vector3($this->x, $this->y - 1, $this->z))->isTransparent())
1733  $this->onGround = true;
1734  /*
1735  if(count($this->level->getCollisionBlocks($bb)) > 0){
1736  $this->onGround = true;
1737  }*/
1738  }
1739  $this->isCollided = $this->onGround;
1740  $this->updateFallState($dy, $this->onGround);
1741 
1742 
1743  Timings::$entityMoveTimer->stopTiming();
1744 
1745  return true;
1746  }

◆ getAttributeMap()

getAttributeMap ( )
Returns
AttributeMap
1159  {
1160  return $this->attributeMap;
1161  }

◆ getBlocksAround()

getBlocksAround ( )
Returns
array|null|Block[]
1933  {
1934  if($this->blocksAround === null){
1935  $minX = Math::floorFloat($this->boundingBox->minX);
1936  $minY = Math::floorFloat($this->boundingBox->minY);
1937  $minZ = Math::floorFloat($this->boundingBox->minZ);
1938  $maxX = Math::ceilFloat($this->boundingBox->maxX);
1939  $maxY = Math::ceilFloat($this->boundingBox->maxY);
1940  $maxZ = Math::ceilFloat($this->boundingBox->maxZ);
1941 
1942  $this->blocksAround = [];
1943 
1944  for($z = $minZ; $z <= $maxZ; ++$z){
1945  for($x = $minX; $x <= $maxX; ++$x){
1946  for($y = $minY; $y <= $maxY; ++$y){
1947  $block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z));
1948  if($block->hasEntityCollision()){
1949  $this->blocksAround[Level::blockHash($block->x, $block->y, $block->z)] = $block;
1950  }
1951  }
1952  }
1953  }
1954  }
1955 
1956  return $this->blocksAround;
1957  }

◆ getBoundingBox()

getBoundingBox ( )
Returns
AxisAlignedBB
1541  {
1542  return $this->boundingBox;
1543  }

◆ getDataFlag()

getDataFlag (   $propertyId,
  $id 
)
Parameters
int$propertyId
int$id
Returns
bool
2389  {
2390  return (((int) $this->getDataProperty($propertyId)) & (1 << $id)) > 0;
2391  }

◆ getDataProperty()

getDataProperty (   $id)
Parameters
int$id
Returns
mixed
2356  {
2357  return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null;
2358  }

◆ getDataPropertyType()

getDataPropertyType (   $id)
Parameters
int$id
Returns
int
2365  {
2366  return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][0] : null;
2367  }

◆ getDirection()

getDirection ( )
Returns
int|null
1487  {
1488  $rotation = ($this->yaw - 90) % 360;
1489  if($rotation < 0){
1490  $rotation += 360.0;
1491  }
1492  if((0 <= $rotation and $rotation < 45) or (315 <= $rotation and $rotation < 360)){
1493  return 2; //North
1494  }elseif(45 <= $rotation and $rotation < 135){
1495  return 3; //East
1496  }elseif(135 <= $rotation and $rotation < 225){
1497  return 0; //South
1498  }elseif(225 <= $rotation and $rotation < 315){
1499  return 1; //West
1500  }else{
1501  return null;
1502  }
1503  }

◆ getDirectionPlane()

getDirectionPlane ( )
Returns
Vector2
1410  {
1411  return (new Vector2(-cos(deg2rad($this->yaw) - M_PI_2), -sin(deg2rad($this->yaw) - M_PI_2)))->normalize();
1412  }

◆ getDirectionVector()

getDirectionVector ( )
Returns
Vector3
1398  {
1399  $y = -sin(deg2rad($this->pitch));
1400  $xz = cos(deg2rad($this->pitch));
1401  $x = -$xz * sin(deg2rad($this->yaw));
1402  $z = $xz * cos(deg2rad($this->yaw));
1403 
1404  return $this->temporalVector->setComponents($x, $y, $z)->normalize();
1405  }

◆ getDropExpMax()

getDropExpMax ( )
Returns
int
535  : int{
536  return $this->dropExp[1];
537  }

◆ getDropExpMin()

getDropExpMin ( )
Returns
int
528  : int{
529  return $this->dropExp[0];
530  }

◆ getEffect()

getEffect (   $effectId)
Parameters
$effectId
Returns
null|Effect
760  {
761  return isset($this->effects[$effectId]) ? $this->effects[$effectId] : null;
762  }

◆ getEffects()

getEffects ( )
Returns
Effect[]
719  {
720  return $this->effects;
721  }

◆ getEyeHeight()

getEyeHeight ( )
Returns
float|int|null
1583  {
1584  return $this->eyeHeight;
1585  }

◆ getHealth()

getHealth ( )
Returns
int
1109  {
1110  return $this->health;
1111  }

◆ getHeight()

getHeight ( )
Returns
mixed
491  {
492  return $this->height;
493  }

◆ getId()

getId ( )
Returns
int
2168  {
2169  return $this->id;
2170  }

◆ getLastDamageCause()

getLastDamageCause ( )
Returns
EntityDamageEvent|null
1152  {
1153  return $this->lastDamageCause;
1154  }

◆ getLength()

getLength ( )
Returns
mixed
505  {
506  return $this->length;
507  }

◆ getLinkedEntity()

getLinkedEntity ( )
Returns
Entity
2340  {
2341  return $this->linkedEntity;
2342  }

◆ getLinkedType()

getLinkedType ( )
Returns
null
2347  {
2348  return $this->linkedType;
2349  }

◆ getLocation()

getLocation ( )
Returns
Location
1638  {
1639  return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->level);
1640  }

◆ getMaxHealth()

getMaxHealth ( )
Returns
int
1166  {
1167  return $this->maxHealth + ($this->hasEffect(Effect::HEALTH_BOOST) ? 4 * ($this->getEffect(Effect::HEALTH_BOOST)->getAmplifier() + 1) : 0);
1168  }

◆ getMetadata()

getMetadata (   $metadataKey)
Parameters
string$metadataKey
Returns
MetadataValue[]

Implements Metadatable.

2410  {
2411  return $this->server->getEntityMetadata()->getMetadata($this, $metadataKey);
2412  }

◆ getMotion()

getMotion ( )
Returns
Vector3
2078  {
2079  return new Vector3($this->motionX, $this->motionY, $this->motionZ);
2080  }

◆ getNameTag()

getNameTag ( )
Returns
string
542  {
543  return $this->getDataProperty(self::DATA_NAMETAG);
544  }

◆ getOwningEntity()

getOwningEntity ( )

Returns the owning entity, or null if the entity was not found.

Returns
Entity|null
690  {
691  $eid = $this->getOwningEntityId();
692  if($eid !== null){
693  return $this->server->findEntity($eid, $this->level);
694  }
695  return null;
696  }

◆ getOwningEntityId()

getOwningEntityId ( )

Returns the entity ID of the owning entity, or null if the entity doesn't have an owner.

Returns
int|string|null
682  {
683  return $this->getDataProperty(self::DATA_OWNER_EID);
684  }

◆ getPosition()

getPosition ( )
Returns
Position
1631  {
1632  return new Position($this->x, $this->y, $this->z, $this->level);
1633  }

◆ getSaveId()

getSaveId ( )

Returns the short save name

Returns
string
885  {
886  return self::$shortNames[static::class];
887  }

◆ getScale()

getScale ( )
Returns
mixed
521  {
522  return $this->getDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT);
523  }

◆ getViewers()

getViewers ( )
Returns
Player[]
986  {
987  return $this->hasSpawned;
988  }

◆ getWidth()

getWidth ( )
Returns
mixed
498  {
499  return $this->width;
500  }

◆ handleLavaMovement()

handleLavaMovement ( )
1576  { //TODO
1577 
1578  }

◆ hasEffect()

hasEffect (   $effectId)
Parameters
$effectId
Returns
bool
769  {
770  return isset($this->effects[$effectId]);
771  }

◆ hasMetadata()

hasMetadata (   $metadataKey)
Parameters
string$metadataKey
Returns
bool

Implements Metadatable.

2419  {
2420  return $this->server->getEntityMetadata()->hasMetadata($this, $metadataKey);
2421  }

◆ heal()

heal (   $amount,
EntityRegainHealthEvent  $source 
)
Parameters
float$amount
EntityRegainHealthEvent$source
1097  {
1098  $this->server->getPluginManager()->callEvent($source);
1099  if($source->isCancelled()){
1100  return;
1101  }
1102 
1103  $this->setHealth($this->getHealth() + $source->getAmount());
1104  }

◆ init()

static init ( )
static
222  {
223  Entity::registerEntity(Arrow::class);
224  Entity::registerEntity(Bat::class);
225  Entity::registerEntity(Blaze::class);
226  Entity::registerEntity(Boat::class);
227  Entity::registerEntity(CaveSpider::class);
228  Entity::registerEntity(Chicken::class);
229  Entity::registerEntity(Cow::class);
230  Entity::registerEntity(Creeper::class);
231  Entity::registerEntity(Donkey::class);
232  Entity::registerEntity(DroppedItem::class);
233  Entity::registerEntity(Egg::class);
234  Entity::registerEntity(ElderGuardian::class);
235  Entity::registerEntity(Enderman::class);
236  Entity::registerEntity(Endermite::class);
237  Entity::registerEntity(EnderDragon::class);
238  Entity::registerEntity(EnderPearl::class);
239  Entity::registerEntity(Evoker::class);
240  Entity::registerEntity(FallingSand::class);
241  Entity::registerEntity(FishingHook::class);
242  Entity::registerEntity(Ghast::class);
243  Entity::registerEntity(Guardian::class);
244  Entity::registerEntity(Horse::class);
245  Entity::registerEntity(Husk::class);
246  Entity::registerEntity(IronGolem::class);
247  Entity::registerEntity(LavaSlime::class); //Magma Cube
248  Entity::registerEntity(Lightning::class);
249  Entity::registerEntity(Llama::class);
250  Entity::registerEntity(Minecart::class);
251  Entity::registerEntity(MinecartChest::class);
252  Entity::registerEntity(MinecartHopper::class);
253  Entity::registerEntity(MinecartTNT::class);
254  Entity::registerEntity(Mooshroom::class);
255  Entity::registerEntity(Mule::class);
256  Entity::registerEntity(Ocelot::class);
257  Entity::registerEntity(Painting::class);
258  Entity::registerEntity(Pig::class);
259  Entity::registerEntity(PigZombie::class);
260  Entity::registerEntity(PolarBear::class);
261  Entity::registerEntity(PrimedTNT::class);
262  Entity::registerEntity(Rabbit::class);
263  Entity::registerEntity(Sheep::class);
264  Entity::registerEntity(Shulker::class);
265  Entity::registerEntity(Silverfish::class);
266  Entity::registerEntity(Skeleton::class);
267  Entity::registerEntity(SkeletonHorse::class);
268  Entity::registerEntity(Slime::class);
269  Entity::registerEntity(Snowball::class);
270  Entity::registerEntity(SnowGolem::class);
271  Entity::registerEntity(Spider::class);
272  Entity::registerEntity(Squid::class);
273  Entity::registerEntity(Stray::class);
274  Entity::registerEntity(ThrownExpBottle::class);
275  Entity::registerEntity(ThrownPotion::class);
276  Entity::registerEntity(Vex::class);
277  Entity::registerEntity(Villager::class);
278  Entity::registerEntity(Vindicator::class);
279  Entity::registerEntity(Witch::class);
280  Entity::registerEntity(Wither::class);
281  Entity::registerEntity(WitherSkeleton::class);
282  Entity::registerEntity(Wolf::class);
283  Entity::registerEntity(XPOrb::class);
284  Entity::registerEntity(Zombie::class);
285  Entity::registerEntity(ZombieHorse::class);
286  Entity::registerEntity(ZombieVillager::class);
287 
288  Entity::registerEntity(Human::class, true);
289  }

◆ initEntity()

initEntity ( )
protected
944  {
945  if(!($this->namedtag instanceof CompoundTag)){
946  throw new \InvalidArgumentException("Expecting CompoundTag, received " . get_class($this->namedtag));
947  }
948 
949  if(isset($this->namedtag->CustomName)){
950  $this->setNameTag($this->namedtag["CustomName"]);
951  if(isset($this->namedtag->CustomNameVisible)){
952  $this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0);
953  }
954  if(isset($this->namedtag->CustomNameAlwaysVisible)){
955  $this->setNameTagAlwaysVisible($this->namedtag["CustomNameAlwaysVisible"] > 0);
956  }
957  }
958 
959  $this->scheduleUpdate();
960 
961  $this->addAttributes();
962 
963  if(isset($this->namedtag->ActiveEffects)){
964  foreach($this->namedtag->ActiveEffects->getValue() as $e){
965  $amplifier = $e["Amplifier"] & 0xff; //0-255 only
966 
967  $effect = Effect::getEffect($e["Id"]);
968  if($effect === null){
969  continue;
970  }
971 
972  $effect->setAmplifier($amplifier)->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0);
973 
974  $this->addEffect($effect);
975  }
976  }
977 
978  }

◆ isAlive()

isAlive ( )
Returns
bool
1116  {
1117  return $this->health > 0;
1118  }

◆ isFireProof()

isFireProof ( )
Returns
bool
1480  : bool{
1481  return false;
1482  }

◆ isGliding()

isGliding ( )
Returns
bool
616  {
617  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IDLING);
618  }

◆ isImmobile()

isImmobile ( )
Returns
bool
631  : bool{
632  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE);
633  }

◆ isInsideOfFire()

isInsideOfFire ( )
Returns
bool
1690  {
1691  foreach($this->getBlocksAround() as $block){
1692  if($block instanceof Fire){
1693  return true;
1694  }
1695  }
1696 
1697  return false;
1698  }

◆ isInsideOfPortal()

isInsideOfPortal ( )
Returns
bool
1645  {
1646  $blocks = $this->getBlocksAround();
1647 
1648  foreach($blocks as $block){
1649  if($block instanceof Portal){
1650  return true;
1651  }
1652  }
1653 
1654  return false;
1655  }

◆ isInsideOfSolid()

isInsideOfSolid ( )
Returns
bool
1675  {
1676  $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
1677 
1678  $bb = $block->getBoundingBox();
1679 
1680  if($bb !== null and $block->isSolid() and !$block->isTransparent() and $bb->intersectsWith($this->getBoundingBox())){
1681  return true;
1682  }
1683 
1684  return false;
1685  }

◆ isInsideOfWater()

isInsideOfWater ( )
Returns
bool
1660  {
1661  $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
1662 
1663  if($block instanceof Water){
1664  $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
1665 
1666  return $y < $f;
1667  }
1668 
1669  return false;
1670  }

◆ isNameTagAlwaysVisible()

isNameTagAlwaysVisible ( )
Returns
bool
556  {
557  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG);
558  }

◆ isNameTagVisible()

isNameTagVisible ( )
Returns
bool
549  {
550  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG);
551  }

◆ isOnFire()

isOnFire ( )
Returns
bool
1463  {
1464  return $this->fireTicks > 0;
1465  }

◆ isOnGround()

isOnGround ( )
Returns
bool
2109  {
2110  return $this->onGround === true;
2111  }

◆ isSneaking()

isSneaking ( )
Returns
bool
584  {
585  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING);
586  }

◆ isSprinting()

isSprinting ( )
Returns
bool
598  {
599  return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING);
600  }

◆ kill()

kill ( )
2113  {
2114  $this->health = 0;
2115  $this->removeAllEffects();
2116  $this->scheduleUpdate();
2117 
2118  if($this->getLevel()->getServer()->expEnabled){
2119  $exp = mt_rand($this->getDropExpMin(), $this->getDropExpMax());
2120  if($exp > 0) $this->getLevel()->spawnXPOrb($this, $exp);
2121  }
2122  }

◆ linkEntity()

linkEntity ( Entity  $entity)
Parameters
Entity$entity
Returns
bool
2248  {
2249  return $this->setLinked(1, $entity);
2250  }

◆ move()

move (   $dx,
  $dy,
  $dz 
)
Parameters
$dx
$dy
$dz
Returns
bool
1755  {
1756 
1757  if($dx == 0 and $dz == 0 and $dy == 0){
1758  return true;
1759  }
1760 
1761  if($this->keepMovement){
1762  $this->boundingBox->offset($dx, $dy, $dz);
1763  $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
1764  $this->onGround = $this->isPlayer ? true : false;
1765 
1766  return true;
1767  }else{
1768 
1769  Timings::$entityMoveTimer->startTiming();
1770 
1771  $this->ySize *= 0.4;
1772 
1773  /*
1774  if($this->isColliding){ //With cobweb?
1775  $this->isColliding = false;
1776  $dx *= 0.25;
1777  $dy *= 0.05;
1778  $dz *= 0.25;
1779  $this->motionX = 0;
1780  $this->motionY = 0;
1781  $this->motionZ = 0;
1782  }
1783  */
1784 
1785  $movX = $dx;
1786  $movY = $dy;
1787  $movZ = $dz;
1788 
1789  $axisalignedbb = clone $this->boundingBox;
1790 
1791  /*$sneakFlag = $this->onGround and $this instanceof Player;
1792 
1793  if($sneakFlag){
1794  for($mov = 0.05; $dx != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
1795  if($dx < $mov and $dx >= -$mov){
1796  $dx = 0;
1797  }elseif($dx > 0){
1798  $dx -= $mov;
1799  }else{
1800  $dx += $mov;
1801  }
1802  }
1803 
1804  for(; $dz != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
1805  if($dz < $mov and $dz >= -$mov){
1806  $dz = 0;
1807  }elseif($dz > 0){
1808  $dz -= $mov;
1809  }else{
1810  $dz += $mov;
1811  }
1812  }
1813 
1814  //TODO: big messy loop
1815  }*/
1816 
1817  assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
1818 
1819  $list = $this->level->getCollisionCubes($this, $this->level->getTickRate() > 1 ? $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false);
1820 
1821  foreach($list as $bb){
1822  $dy = $bb->calculateYOffset($this->boundingBox, $dy);
1823  }
1824 
1825  $this->boundingBox->offset(0, $dy, 0);
1826 
1827  $fallingFlag = ($this->onGround or ($dy != $movY and $movY < 0));
1828 
1829  foreach($list as $bb){
1830  $dx = $bb->calculateXOffset($this->boundingBox, $dx);
1831  }
1832 
1833  $this->boundingBox->offset($dx, 0, 0);
1834 
1835  foreach($list as $bb){
1836  $dz = $bb->calculateZOffset($this->boundingBox, $dz);
1837  }
1838 
1839  $this->boundingBox->offset(0, 0, $dz);
1840 
1841 
1842  if($this->stepHeight > 0 and $fallingFlag and $this->ySize < 0.05 and ($movX != $dx or $movZ != $dz)){
1843  $cx = $dx;
1844  $cy = $dy;
1845  $cz = $dz;
1846  $dx = $movX;
1847  $dy = $this->stepHeight;
1848  $dz = $movZ;
1849 
1850  $axisalignedbb1 = clone $this->boundingBox;
1851 
1852  $this->boundingBox->setBB($axisalignedbb);
1853 
1854  $list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
1855 
1856  foreach($list as $bb){
1857  $dy = $bb->calculateYOffset($this->boundingBox, $dy);
1858  }
1859 
1860  $this->boundingBox->offset(0, $dy, 0);
1861 
1862  foreach($list as $bb){
1863  $dx = $bb->calculateXOffset($this->boundingBox, $dx);
1864  }
1865 
1866  $this->boundingBox->offset($dx, 0, 0);
1867 
1868  foreach($list as $bb){
1869  $dz = $bb->calculateZOffset($this->boundingBox, $dz);
1870  }
1871 
1872  $this->boundingBox->offset(0, 0, $dz);
1873 
1874  if(($cx ** 2 + $cz ** 2) >= ($dx ** 2 + $dz ** 2)){
1875  $dx = $cx;
1876  $dy = $cy;
1877  $dz = $cz;
1878  $this->boundingBox->setBB($axisalignedbb1);
1879  }else{
1880  $this->ySize += 0.5;
1881  }
1882 
1883  }
1884 
1885  $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
1886  $this->y = $this->boundingBox->minY - $this->ySize;
1887  $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
1888 
1889  $this->checkChunks();
1890 
1891  $this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz);
1892  $this->updateFallState($dy, $this->onGround);
1893 
1894  if($movX != $dx){
1895  $this->motionX = 0;
1896  }
1897 
1898  if($movY != $dy){
1899  $this->motionY = 0;
1900  }
1901 
1902  if($movZ != $dz){
1903  $this->motionZ = 0;
1904  }
1905 
1906 
1907  //TODO: vehicle collision events (first we need to spawn them!)
1908 
1909  Timings::$entityMoveTimer->stopTiming();
1910 
1911  return true;
1912  }
1913  }

◆ moveFlying()

moveFlying ( )
1587  { //TODO
1588 
1589  }

◆ onCollideWithPlayer()

onCollideWithPlayer ( Human  $entityPlayer)
Parameters
Human$entityPlayer
1594  {
1595 
1596  }

◆ onUpdate()

onUpdate (   $currentTick)
Parameters
$currentTick
Returns
bool
1419  {
1420  if($this->closed){
1421  return false;
1422  }
1423 
1424  if(!$this->isAlive()){
1425  ++$this->deadTicks;
1426  if($this->deadTicks >= 10){
1427  $this->despawnFromAll();
1428  if(!$this->isPlayer){
1429  $this->close();
1430  }
1431  }
1432 
1433  return $this->deadTicks < 10;
1434  }
1435 
1436  $tickDiff = $currentTick - $this->lastUpdate;
1437  if($tickDiff <= 0){
1438  return false;
1439  }
1440 
1441  $this->lastUpdate = $currentTick;
1442 
1443  $this->timings->startTiming();
1444 
1445  $hasUpdate = $this->entityBaseTick($tickDiff);
1446 
1447  $this->updateMovement();
1448 
1449  $this->timings->stopTiming();
1450 
1451  //if($this->isStatic())
1452  return $hasUpdate;
1453  //return !($this instanceof Player);
1454  }

◆ recalculateEffectColor()

recalculateEffectColor ( )
protected
807  {
808  //TODO: add transparency values
809  $color = [0, 0, 0]; //RGB
810  $count = 0;
811  $ambient = true;
812  foreach($this->effects as $effect){
813  if($effect->isVisible()){
814  $c = $effect->getColor();
815  $color[0] += $c[0] * ($effect->getAmplifier() + 1);
816  $color[1] += $c[1] * ($effect->getAmplifier() + 1);
817  $color[2] += $c[2] * ($effect->getAmplifier() + 1);
818  $count += $effect->getAmplifier() + 1;
819  if(!$effect->isAmbient()){
820  $ambient = false;
821  }
822  }
823  }
824 
825  if($count > 0){
826  $r = ($color[0] / $count) & 0xff;
827  $g = ($color[1] / $count) & 0xff;
828  $b = ($color[2] / $count) & 0xff;
829 
830  $this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0xff000000 | ($r << 16) | ($g << 8) | $b);
832  }else{
835  }
836  }

◆ registerEntity()

static registerEntity (   $className,
  $force = false 
)
static
Parameters
$className
bool$force
Returns
bool
862  {
863  $class = new \ReflectionClass($className);
864  if(is_a($className, Entity::class, true) and !$class->isAbstract()){
865  if($className::NETWORK_ID !== -1){
866  self::$knownEntities[$className::NETWORK_ID] = $className;
867  }elseif(!$force){
868  return false;
869  }
870 
871  self::$knownEntities[$class->getShortName()] = $className;
872  self::$shortNames[$className] = $class->getShortName();
873 
874  return true;
875  }
876 
877  return false;
878  }

◆ removeAllEffects()

removeAllEffects ( )
723  {
724  foreach($this->effects as $effect){
725  $this->removeEffect($effect->getId());
726  }
727  }

◆ removeEffect()

removeEffect (   $effectId)
Parameters
$effectId
Returns
bool
734  {
735  Server::getInstance()->getPluginManager()->callEvent($ev = new EntityEffectRemoveEvent($this, $effectId));
736  if($ev->isCancelled()){
737  return false;
738  }
739  if(isset($this->effects[$effectId])){
740  $effect = $this->effects[$effectId];
741  unset($this->effects[$effectId]);
742  $effect->remove($this);
743  if($effectId === Effect::ABSORPTION and $this instanceof Human){
744  $this->setAbsorption(0);
745  }
746 
747  $this->recalculateEffectColor();
748 
749  return true;
750  }
751 
752  return false;
753  }

◆ removeMetadata()

removeMetadata (   $metadataKey,
Plugin  $plugin 
)
Parameters
string$metadataKey
Plugin$plugin

Implements Metadatable.

2427  {
2428  $this->server->getEntityMetadata()->removeMetadata($this, $metadataKey, $plugin);
2429  }

◆ resetFallDistance()

resetFallDistance ( )
1517  {
1518  $this->fallDistance = 0;
1519  }

◆ respawnToAll()

respawnToAll ( )
2172  {
2173  foreach($this->hasSpawned as $key => $player){
2174  unset($this->hasSpawned[$key]);
2175  $this->spawnTo($player);
2176  }
2177  }

◆ saveNBT()

saveNBT ( )
889  {
890  if(!($this instanceof Player)){
891  $this->namedtag->id = new StringTag("id", $this->getSaveId());
892  if($this->getNameTag() !== ""){
893  $this->namedtag->CustomName = new StringTag("CustomName", $this->getNameTag());
894  $this->namedtag->CustomNameVisible = new StringTag("CustomNameVisible", $this->isNameTagVisible());
895  $this->namedtag->CustomNameAlwaysVisible = new StringTag("CustomNameAlwaysVisible", $this->isNameTagAlwaysVisible());
896  }else{
897  unset($this->namedtag->CustomName);
898  unset($this->namedtag->CustomNameVisible);
899  unset($this->namedtag->CustomNameAlwaysVisible);
900  }
901  }
902 
903  $this->namedtag->Pos = new ListTag("Pos", [
904  new DoubleTag(0, $this->x),
905  new DoubleTag(1, $this->y),
906  new DoubleTag(2, $this->z)
907  ]);
908 
909  $this->namedtag->Motion = new ListTag("Motion", [
910  new DoubleTag(0, $this->motionX),
911  new DoubleTag(1, $this->motionY),
912  new DoubleTag(2, $this->motionZ)
913  ]);
914 
915  $this->namedtag->Rotation = new ListTag("Rotation", [
916  new FloatTag(0, $this->yaw),
917  new FloatTag(1, $this->pitch)
918  ]);
919 
920  $this->namedtag->FallDistance = new FloatTag("FallDistance", $this->fallDistance);
921  $this->namedtag->Fire = new ShortTag("Fire", $this->fireTicks);
922  $this->namedtag->Air = new ShortTag("Air", $this->getDataProperty(self::DATA_AIR));
923  $this->namedtag->OnGround = new ByteTag("OnGround", $this->onGround == true ? 1 : 0);
924  $this->namedtag->Invulnerable = new ByteTag("Invulnerable", $this->invulnerable == true ? 1 : 0);
925 
926  if(count($this->effects) > 0){
927  $effects = [];
928  foreach($this->effects as $effect){
929  $effects[$effect->getId()] = new CompoundTag($effect->getId(), [
930  "Id" => new ByteTag("Id", $effect->getId()),
931  "Amplifier" => new ByteTag("Amplifier", $effect->getAmplifier()),
932  "Duration" => new IntTag("Duration", $effect->getDuration()),
933  "Ambient" => new ByteTag("Ambient", 0),
934  "ShowParticles" => new ByteTag("ShowParticles", $effect->isVisible() ? 1 : 0)
935  ]);
936  }
937 
938  $this->namedtag->ActiveEffects = new ListTag("ActiveEffects", $effects);
939  }else{
940  unset($this->namedtag->ActiveEffects);
941  }
942  }

◆ scheduleUpdate()

scheduleUpdate ( )
final
1456  {
1457  $this->level->updateEntities[$this->id] = $this;
1458  }

◆ sendData()

sendData (   $player,
array  $data = null 
)
Parameters
Player[]|Player$player
array$dataProperly formatted entity data, defaults to everything
1020  {
1021  if(!is_array($player)){
1022  $player = [$player];
1023  }
1024 
1025  $pk = new SetEntityDataPacket();
1026  $pk->eid = $this->getId();
1027  $pk->metadata = $data === null ? $this->dataProperties : $data;
1028 
1029  foreach($player as $p){
1030  if($p === $this){
1031  continue;
1032  }
1033  $p->dataPacket(clone $pk);
1034  }
1035  if($this instanceof Player){
1036  $this->dataPacket($pk);
1037  }
1038  }

◆ sendLinkedData()

sendLinkedData ( )
2252  {
2253  if($this->linkedEntity instanceof Entity){
2254  $this->setLinked($this->linkedType, $this->linkedEntity);
2255  }
2256  }

◆ sendPotionEffects()

sendPotionEffects ( Player  $player)
Parameters
Player$player
1002  {
1003  foreach($this->effects as $effect){
1004  $pk = new MobEffectPacket();
1005  $pk->eid = $this->id;
1006  $pk->effectId = $effect->getId();
1007  $pk->amplifier = $effect->getAmplifier();
1008  $pk->particles = $effect->isVisible();
1009  $pk->duration = $effect->getDuration();
1010  $pk->eventId = MobEffectPacket::EVENT_ADD;
1011 
1012  $player->dataPacket($pk);
1013  }
1014  }

◆ setCanClimb()

setCanClimb ( bool  $value)

Sets whether the entity is able to climb climbable blocks.

Parameters
bool$value
656  {
657  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB, $value);
658  }

◆ setCanClimbWalls()

setCanClimbWalls ( bool  $value = true)

Sets whether the entity is climbing a block. If true, the entity can climb anything.

Parameters
bool$value
674  {
675  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING, $value);
676  }

◆ setDataFlag()

setDataFlag (   $propertyId,
  $id,
  $value = true,
  $type = self::DATA_TYPE_LONG 
)
Parameters
$propertyId
$id
bool$value
int$type
2375  {
2376  if($this->getDataFlag($propertyId, $id) !== $value){
2377  $flags = (int) $this->getDataProperty($propertyId);
2378  $flags ^= 1 << $id;
2379  $this->setDataProperty($propertyId, $type, $flags);
2380  }
2381  }

◆ setDataProperty()

setDataProperty (   $id,
  $type,
  $value 
)
Parameters
int$id
int$type
mixed$value
Returns
bool
2231  {
2232  if($this->getDataProperty($id) !== $value){
2233  $this->dataProperties[$id] = [$type, $value];
2234 
2235  $this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]);
2236 
2237  return true;
2238  }
2239 
2240  return false;
2241  }

◆ setGliding()

setGliding (   $value = true)
Parameters
bool$value
623  {
624  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_GLIDING, (bool) $value);
625  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IDLING, (bool) $value);
626  }

◆ setHealth()

setHealth (   $amount)

Sets the health of the Entity. This won't send any update to the players

Parameters
int$amount
1125  {
1126  $amount = (int) $amount;
1127  if($amount === $this->health){
1128  return;
1129  }
1130 
1131  if($amount <= 0){
1132  if($this->isAlive()){
1133  $this->kill();
1134  }
1135  }elseif($amount <= $this->getMaxHealth() or $amount < $this->health){
1136  $this->health = (int) $amount;
1137  }else{
1138  $this->health = $this->getMaxHealth();
1139  }
1140  }

◆ setImmobile()

setImmobile (   $value = true)
Parameters
bool$value
638  {
639  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value);
640  }

◆ setLastDamageCause()

setLastDamageCause ( EntityDamageEvent  $type)
Parameters
EntityDamageEvent$type
1145  {
1146  $this->lastDamageCause = $type;
1147  }

◆ setLinked()

setLinked (   $type = 0,
Entity  $entity 
)
Parameters
int$type
Entity$entity
Returns
bool
2264  {
2265  if($entity instanceof Boat or $entity instanceof Minecart){
2266  $this->setDataProperty(57, 8, [0, 1, 0]); //This is a fast hack for Boat. TODO: Improve it
2267  }
2268 
2269  if($type != 0 and $entity === null){
2270  return false;
2271  }
2272  if($entity === $this){
2273  return false;
2274  }
2275  switch($type){
2276  case 0:
2277  if($this->linkedType == 0){
2278  return true;
2279  }
2280  $this->linkedType = 0;
2281  $pk = new SetEntityLinkPacket();
2282  $pk->from = $entity->getId();
2283  $pk->to = $this->getId();
2284  $pk->type = 3;
2285  $this->server->broadcastPacket($this->level->getPlayers(), $pk);
2286  if($this instanceof Player){
2287  $pk = new SetEntityLinkPacket();
2288  $pk->from = $entity->getId();
2289  $pk->to = 0;
2290  $pk->type = 3;
2291  $this->dataPacket($pk);
2292  }
2293  if($this->linkedEntity->getLinkedType()){
2294  $this->linkedEntity->setLinked(0, $this);
2295  }
2296  $this->linkedEntity = null;
2297 
2298  return true;
2299  case 1:
2300  if(!$entity->isAlive()){
2301  return false;
2302  }
2303  $this->linkedEntity = $entity;
2304  $this->linkedType = 1;
2305  $entity->linkedEntity = $this;
2306  $entity->linkedType = 1;
2307  $pk = new SetEntityLinkPacket();
2308  $pk->from = $entity->getId();
2309  $pk->to = $this->getId();
2310  $pk->type = 2;
2311  $this->server->broadcastPacket($this->level->getPlayers(), $pk);
2312  if($this instanceof Player){
2313  $pk = new SetEntityLinkPacket();
2314  $pk->from = $entity->getId();
2315  $pk->to = 0;
2316  $pk->type = 2;
2317  $this->dataPacket($pk);
2318  }
2319 
2320  return true;
2321  case 2:
2322  if(!$entity->isAlive()){
2323  return false;
2324  }
2325  if($entity->getLinkedEntity() !== $this){
2326  return $entity->linkEntity($this);
2327  }
2328  $this->linkedEntity = $entity;
2329  $this->linkedType = 2;
2330 
2331  return true;
2332  default:
2333  return false;
2334  }
2335  }

◆ setLocation()

setLocation ( Location  $pos)
Parameters
Location$pos
Returns
bool
2037  {
2038  if($this->closed){
2039  return false;
2040  }
2041 
2042  $this->setPositionAndRotation($pos, $pos->yaw, $pos->pitch);
2043 
2044  return true;
2045  }

◆ setMaxHealth()

setMaxHealth (   $amount)
Parameters
int$amount
1173  {
1174  $this->maxHealth = (int) $amount;
1175  }

◆ setMetadata()

setMetadata (   $metadataKey,
MetadataValue  $metadataValue 
)
Parameters
string$metadataKey
MetadataValue$metadataValue

Implements Metadatable.

2401  {
2402  $this->server->getEntityMetadata()->setMetadata($this, $metadataKey, $metadataValue);
2403  }

◆ setMotion()

setMotion ( Vector3  $motion)
Parameters
Vector3$motion
Returns
bool
2087  {
2088  if(!$this->justCreated){
2089  $this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion));
2090  if($ev->isCancelled()){
2091  return false;
2092  }
2093  }
2094 
2095  $this->motionX = $motion->x;
2096  $this->motionY = $motion->y;
2097  $this->motionZ = $motion->z;
2098 
2099  if(!$this->justCreated){
2100  $this->updateMovement();
2101  }
2102 
2103  return true;
2104  }

◆ setNameTag()

setNameTag (   $name)
Parameters
string$name
563  {
564  $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $name);
565  }

◆ setNameTagAlwaysVisible()

setNameTagAlwaysVisible (   $value = true)
Parameters
bool$value
577  {
578  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
579  }

◆ setNameTagVisible()

setNameTagVisible (   $value = true)
Parameters
bool$value
570  {
571  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value);
572  }

◆ setOnFire()

setOnFire (   $seconds)
Parameters
$seconds
1470  {
1471  $ticks = $seconds * 20;
1472  if($ticks > $this->fireTicks){
1473  $this->fireTicks = $ticks;
1474  }
1475  }

◆ setOwningEntity()

setOwningEntity ( Entity  $owner)

Sets the owner of the entity.

Parameters
Entity$owner
Exceptions
705  {
706  if($owner->closed){
707  throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used");
708  return false;
709  }
710 
711  $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId());
712  return true;
713  }

◆ setPosition()

setPosition ( Vector3  $pos)
Parameters
Vector3$pos
Returns
bool
2052  {
2053  if($this->closed){
2054  return false;
2055  }
2056 
2057  if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
2058  if($this->switchLevel($pos->getLevel()) === false){
2059  return false;
2060  }
2061  }
2062 
2063  $this->x = $pos->x;
2064  $this->y = $pos->y;
2065  $this->z = $pos->z;
2066 
2067  $radius = $this->width / 2;
2068  $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
2069 
2070  $this->checkChunks();
2071 
2072  return true;
2073  }

◆ setPositionAndRotation()

setPositionAndRotation ( Vector3  $pos,
  $yaw,
  $pitch 
)
Parameters
Vector3$pos
$yaw
$pitch
Returns
bool
1983  {
1984  if($this->setPosition($pos) === true){
1985  $this->setRotation($yaw, $pitch);
1986 
1987  return true;
1988  }
1989 
1990  return false;
1991  }

◆ setRotation()

setRotation (   $yaw,
  $pitch 
)
Parameters
$yaw
$pitch
1997  {
1998  $this->yaw = $yaw;
1999  $this->pitch = $pitch;
2000  $this->scheduleUpdate();
2001  }

◆ setScale()

setScale (   $scale)
Parameters
$scale
514  {
515  $this->setDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT, $scale);
516  }

◆ setSneaking()

setSneaking (   $value = true)
Parameters
bool$value
591  {
592  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, (bool) $value);
593  }

◆ setSprinting()

setSprinting (   $value = true)
Parameters
bool$value
605  {
606  if($value !== $this->isSprinting()){
607  $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value);
608  $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED);
609  $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3));
610  }
611  }

◆ spawnTo()

spawnTo ( Player  $player)
Parameters
Player$player
993  {
994  if(!isset($this->hasSpawned[$player->getLoaderId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){
995  $this->hasSpawned[$player->getLoaderId()] = $player;
996  }
997  }

◆ spawnToAll()

spawnToAll ( )
2179  {
2180  if($this->chunk === null or $this->closed){
2181  return;
2182  }
2183  foreach($this->level->getChunkPlayers($this->chunk->getX(), $this->chunk->getZ()) as $player){
2184  if($player->isOnline()){
2185  $this->spawnTo($player);
2186  }
2187  }
2188  }

◆ switchLevel()

switchLevel ( Level  $targetLevel)
protected
Parameters
Level$targetLevel
Returns
bool
1603  {
1604  if($this->closed){
1605  return false;
1606  }
1607 
1608  if($this->isValid()){
1609  $this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
1610  if($ev->isCancelled()){
1611  return false;
1612  }
1613 
1614  $this->level->removeEntity($this);
1615  if($this->chunk !== null){
1616  $this->chunk->removeEntity($this);
1617  }
1618  $this->despawnFromAll();
1619  }
1620 
1621  $this->setLevel($targetLevel);
1622  $this->level->addEntity($this);
1623  $this->chunk = null;
1624 
1625  return true;
1626  }

◆ teleport()

teleport ( Vector3  $pos,
  $yaw = null,
  $pitch = null 
)
Parameters
Vector3 | Position | Location$pos
float$yaw
float$pitch
Returns
bool
2131  {
2132  if($pos instanceof Location){
2133  $yaw = $yaw === null ? $pos->yaw : $yaw;
2134  $pitch = $pitch === null ? $pos->pitch : $pitch;
2135  }
2136  $from = Position::fromObject($this, $this->level);
2137  $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
2138  $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
2139  if($ev->isCancelled()){
2140  return false;
2141  }
2142  $this->ySize = 0;
2143  $pos = $ev->getTo();
2144 
2145  $this->setMotion($this->temporalVector->setComponents(0, 0, 0));
2146  if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false){
2147  $this->resetFallDistance();
2148  $this->onGround = true;
2149 
2150  $this->lastX = $this->x;
2151  $this->lastY = $this->y;
2152  $this->lastZ = $this->z;
2153 
2154  $this->lastYaw = $this->yaw;
2155  $this->lastPitch = $this->pitch;
2156 
2157  $this->updateMovement();
2158 
2159  return true;
2160  }
2161 
2162  return false;
2163  }

◆ updateFallState()

updateFallState (   $distanceThisTick,
  $onGround 
)
protected
Parameters
$distanceThisTick
$onGround
1525  {
1526  if($onGround === true){
1527  if($this->fallDistance > 0){
1528  if($this instanceof Living){
1529  $this->fall($this->fallDistance);
1530  }
1531  $this->resetFallDistance();
1532  }
1533  }elseif($distanceThisTick < 0){
1534  $this->fallDistance -= $distanceThisTick;
1535  }
1536  }

◆ updateMovement()

updateMovement ( )
protected
1369  {
1370  $diffPosition = ($this->x - $this->lastX) ** 2 + ($this->y - $this->lastY) ** 2 + ($this->z - $this->lastZ) ** 2;
1371  $diffRotation = ($this->yaw - $this->lastYaw) ** 2 + ($this->pitch - $this->lastPitch) ** 2;
1372 
1373  $diffMotion = ($this->motionX - $this->lastMotionX) ** 2 + ($this->motionY - $this->lastMotionY) ** 2 + ($this->motionZ - $this->lastMotionZ) ** 2;
1374 
1375  if($diffPosition > 0.04 or $diffRotation > 2.25 and ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.00001)){ //0.2 ** 2, 1.5 ** 2
1376  $this->lastX = $this->x;
1377  $this->lastY = $this->y;
1378  $this->lastZ = $this->z;
1379 
1380  $this->lastYaw = $this->yaw;
1381  $this->lastPitch = $this->pitch;
1382 
1383  $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
1384  }
1385 
1386  if($diffMotion > 0.0025 or ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.05 ** 2
1387  $this->lastMotionX = $this->motionX;
1388  $this->lastMotionY = $this->motionY;
1389  $this->lastMotionZ = $this->motionZ;
1390 
1391  $this->level->addEntityMotion($this->chunk->getX(), $this->chunk->getZ(), $this->id, $this->motionX, $this->motionY, $this->motionZ);
1392  }
1393  }

Field Documentation

◆ $activatedPressurePlates

$activatedPressurePlates = []
protected

◆ $age

$age = 0
protected

◆ $attributeMap

$attributeMap
protected

◆ $boundingBox

$boundingBox

◆ $canCollide

$canCollide = true

◆ $chunk

$chunk

◆ $closed

$closed = false

◆ $dataFlags

$dataFlags = 0
protected

◆ $dataProperties

$dataProperties
protected
Initial value:
= [
self::DATA_FLAGS => [self::DATA_TYPE_LONG, 0]

◆ $deadTicks

$deadTicks = 0

◆ $drag

$drag
protected

◆ $dropExp

$dropExp = [0, 0]

◆ $effects

$effects = []
protected

◆ $entityCount

$entityCount = 1
static

◆ $eyeHeight

$eyeHeight = null

◆ $fallDistance

$fallDistance = 0

◆ $fireTicks

$fireTicks = 0

◆ $gravity

$gravity
protected

◆ $hasSpawned

$hasSpawned = []
protected

◆ $height

$height

◆ $id

$id
protected

◆ $inBlock

$inBlock = false

◆ $isCollided

$isCollided = false

◆ $isCollidedHorizontally

$isCollidedHorizontally = false

◆ $isCollidedVertically

$isCollidedVertically = false

◆ $isPlayer

$isPlayer = false
protected

◆ $isStatic

$isStatic = false
protected

◆ $justCreated

$justCreated
protected

◆ $keepMovement

$keepMovement = false

◆ $lastDamageCause

$lastDamageCause = null
protected

◆ $lastMotionX

$lastMotionX

◆ $lastMotionY

$lastMotionY

◆ $lastMotionZ

$lastMotionZ

◆ $lastPitch

$lastPitch

◆ $lastUpdate

$lastUpdate

◆ $lastX

$lastX = null

◆ $lastY

$lastY = null

◆ $lastYaw

$lastYaw

◆ $lastZ

$lastZ = null

◆ $length

◆ $linkedEntity

$linkedEntity = null
protected

◆ $linkedType

$linkedType = null
protected

0 no linked 1 linked other 2 be linked

◆ $maxFireTicks

$maxFireTicks

◆ $motionChanged

$motionChanged

◆ $motionX

$motionX

◆ $motionY

$motionY

◆ $motionZ

$motionZ

◆ $namedtag

$namedtag

◆ $noDamageTicks

$noDamageTicks

◆ $onGround

$onGround

◆ $passenger

$passenger = null

◆ $positionChanged

$positionChanged

◆ $riding

$riding = null
protected

◆ $server

$server
protected

◆ $stepHeight

$stepHeight = 0
protected

◆ $temporalVector

$temporalVector

◆ $ticksLived

$ticksLived = 0

◆ $timings

$timings
protected

◆ $vehicle

$vehicle = null

◆ $width

$width

◆ $ySize

$ySize = 0
protected

◆ DATA_AIR

const DATA_AIR = 7

◆ DATA_AREA_EFFECT_CLOUD_PARTICLE_ID

const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63

◆ DATA_AREA_EFFECT_CLOUD_RADIUS

const DATA_AREA_EFFECT_CLOUD_RADIUS = 61

◆ DATA_AREA_EFFECT_CLOUD_WAITING

const DATA_AREA_EFFECT_CLOUD_WAITING = 62

◆ DATA_BLOCK_TARGET

const DATA_BLOCK_TARGET = 48

◆ DATA_BOUNDING_BOX_HEIGHT

const DATA_BOUNDING_BOX_HEIGHT = 55

◆ DATA_BOUNDING_BOX_WIDTH

const DATA_BOUNDING_BOX_WIDTH = 54

◆ DATA_COLOR

const DATA_COLOR = 3

◆ DATA_COLOUR

const DATA_COLOUR = 3

◆ DATA_COMMAND_BLOCK_COMMAND

const DATA_COMMAND_BLOCK_COMMAND = 71

◆ DATA_COMMAND_BLOCK_LAST_OUTPUT

const DATA_COMMAND_BLOCK_LAST_OUTPUT = 72

◆ DATA_COMMAND_BLOCK_TRACK_OUTPUT

const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73

◆ DATA_CONTROLLING_RIDER_SEAT_NUMBER

const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74

◆ DATA_ENDERMAN_HELD_ITEM_DAMAGE

const DATA_ENDERMAN_HELD_ITEM_DAMAGE = 24

◆ DATA_ENDERMAN_HELD_ITEM_ID

const DATA_ENDERMAN_HELD_ITEM_ID = 23

◆ DATA_ENTITY_AGE

const DATA_ENTITY_AGE = 25

◆ DATA_EXPERIENCE_VALUE

const DATA_EXPERIENCE_VALUE = 15

◆ DATA_FIREBALL_POWER_X

const DATA_FIREBALL_POWER_X = 30

◆ DATA_FIREBALL_POWER_Y

const DATA_FIREBALL_POWER_Y = 31

◆ DATA_FIREBALL_POWER_Z

const DATA_FIREBALL_POWER_Z = 32

◆ DATA_FLAG_ACTION

const DATA_FLAG_ACTION = 4

◆ DATA_FLAG_ALWAYS_SHOW_NAMETAG

const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15

◆ DATA_FLAG_ANGRY

const DATA_FLAG_ANGRY = 24

◆ DATA_FLAG_BABY

const DATA_FLAG_BABY = 11

◆ DATA_FLAG_BREATHING

const DATA_FLAG_BREATHING = 33

◆ DATA_FLAG_CAN_CLIMB

const DATA_FLAG_CAN_CLIMB = 19

◆ DATA_FLAG_CAN_FLY

const DATA_FLAG_CAN_FLY = 21

◆ DATA_FLAG_CAN_SHOW_NAMETAG

const DATA_FLAG_CAN_SHOW_NAMETAG = 14

◆ DATA_FLAG_CHARGE_ATTACK

const DATA_FLAG_CHARGE_ATTACK = 41

◆ DATA_FLAG_CHARGED

const DATA_FLAG_CHARGED = 26

◆ DATA_FLAG_CHESTED

const DATA_FLAG_CHESTED = 34

◆ DATA_FLAG_CONVERTING

const DATA_FLAG_CONVERTING = 12

◆ DATA_FLAG_CRITICAL

const DATA_FLAG_CRITICAL = 13

◆ DATA_FLAG_ELDER

const DATA_FLAG_ELDER = 31

◆ DATA_FLAG_EVOKER_SPELL

const DATA_FLAG_EVOKER_SPELL = 40

◆ DATA_FLAG_GLIDING

const DATA_FLAG_GLIDING = 30

◆ DATA_FLAG_IDLING

const DATA_FLAG_IDLING = 39

◆ DATA_FLAG_IGNITED

const DATA_FLAG_IGNITED = 10

◆ DATA_FLAG_IMMOBILE

const DATA_FLAG_IMMOBILE = 16

◆ DATA_FLAG_INLOVE

const DATA_FLAG_INLOVE = 7

◆ DATA_FLAG_INTERESTED

const DATA_FLAG_INTERESTED = 25

◆ DATA_FLAG_INVISIBLE

const DATA_FLAG_INVISIBLE = 5

◆ DATA_FLAG_LEASHED

const DATA_FLAG_LEASHED = 28

◆ DATA_FLAG_LINGER

const DATA_FLAG_LINGER = 45

◆ DATA_FLAG_MOVING

const DATA_FLAG_MOVING = 32

◆ DATA_FLAG_NO_AI

const DATA_FLAG_NO_AI = 16

◆ DATA_FLAG_ONFIRE

const DATA_FLAG_ONFIRE = 0

◆ DATA_FLAG_POWERED

const DATA_FLAG_POWERED = 9

◆ DATA_FLAG_REARING

const DATA_FLAG_REARING = 37

◆ DATA_FLAG_RESTING

const DATA_FLAG_RESTING = 22

◆ DATA_FLAG_RIDING

const DATA_FLAG_RIDING = 2

◆ DATA_FLAG_SADDLED

const DATA_FLAG_SADDLED = 8

◆ DATA_FLAG_SHEARED

const DATA_FLAG_SHEARED = 29

◆ DATA_FLAG_SHOWBASE

const DATA_FLAG_SHOWBASE = 36

◆ DATA_FLAG_SILENT

const DATA_FLAG_SILENT = 17

◆ DATA_FLAG_SITTING

const DATA_FLAG_SITTING = 23

◆ DATA_FLAG_SNEAKING

const DATA_FLAG_SNEAKING = 1

◆ DATA_FLAG_SPRINTING

const DATA_FLAG_SPRINTING = 3

◆ DATA_FLAG_STACKABLE

const DATA_FLAG_STACKABLE = 35

◆ DATA_FLAG_SWIMMER

const DATA_FLAG_SWIMMER = 20

◆ DATA_FLAG_TAMED

const DATA_FLAG_TAMED = 27

◆ DATA_FLAG_TEMPTED

const DATA_FLAG_TEMPTED = 6

◆ DATA_FLAG_VIBRATING

const DATA_FLAG_VIBRATING = 38

◆ DATA_FLAG_WALLCLIMBING

const DATA_FLAG_WALLCLIMBING = 18

◆ DATA_FLAGS

const DATA_FLAGS = 0

◆ DATA_FUSE_LENGTH

const DATA_FUSE_LENGTH = 56

◆ DATA_HEALTH

const DATA_HEALTH = 1

◆ DATA_HURT_DIRECTION

const DATA_HURT_DIRECTION = 12

◆ DATA_HURT_TIME

const DATA_HURT_TIME = 11

◆ DATA_INTERACTIVE_TAG

const DATA_INTERACTIVE_TAG = 40

◆ DATA_LEAD_HOLDER_EID

const DATA_LEAD_HOLDER_EID = 38

◆ DATA_MARK_VARIANT

const DATA_MARK_VARIANT = 44

◆ DATA_MAX_AIR

const DATA_MAX_AIR = 43

◆ DATA_MAX_STRENGTH

const DATA_MAX_STRENGTH = 76

◆ DATA_MINECART_DISPLAY_BLOCK

const DATA_MINECART_DISPLAY_BLOCK = 16

◆ DATA_MINECART_DISPLAY_OFFSET

const DATA_MINECART_DISPLAY_OFFSET = 17

◆ DATA_MINECART_HAS_DISPLAY

const DATA_MINECART_HAS_DISPLAY = 18

◆ DATA_NAMETAG

const DATA_NAMETAG = 4

◆ DATA_NPC_SKIN_ID

const DATA_NPC_SKIN_ID = 41

◆ DATA_OWNER_EID

const DATA_OWNER_EID = 5

◆ DATA_PADDLE_TIME_LEFT

const DATA_PADDLE_TIME_LEFT = 13

◆ DATA_PADDLE_TIME_RIGHT

const DATA_PADDLE_TIME_RIGHT = 14

◆ DATA_POTION_AMBIENT

const DATA_POTION_AMBIENT = 9

◆ DATA_POTION_AUX_VALUE

const DATA_POTION_AUX_VALUE = 37

◆ DATA_POTION_COLOR

const DATA_POTION_COLOR = 8

◆ DATA_RIDER_MAX_ROTATION

const DATA_RIDER_MAX_ROTATION = 59

◆ DATA_RIDER_MIN_ROTATION

const DATA_RIDER_MIN_ROTATION = 60

◆ DATA_RIDER_ROTATION_LOCKED

const DATA_RIDER_ROTATION_LOCKED = 58

◆ DATA_RIDER_SEAT_POSITION

const DATA_RIDER_SEAT_POSITION = 57

◆ DATA_SCALE

const DATA_SCALE = 39

◆ DATA_SHULKER_ATTACH_FACE

const DATA_SHULKER_ATTACH_FACE = 65

◆ DATA_SHULKER_ATTACH_POS

const DATA_SHULKER_ATTACH_POS = 67

◆ DATA_STRENGTH

const DATA_STRENGTH = 75

◆ DATA_TARGET_EID

const DATA_TARGET_EID = 6

◆ DATA_TRADING_PLAYER_EID

const DATA_TRADING_PLAYER_EID = 68

◆ DATA_TYPE_BYTE

const DATA_TYPE_BYTE = 0

◆ DATA_TYPE_FLOAT

const DATA_TYPE_FLOAT = 3

◆ DATA_TYPE_INT

const DATA_TYPE_INT = 2

◆ DATA_TYPE_LONG

const DATA_TYPE_LONG = 7

◆ DATA_TYPE_POS

const DATA_TYPE_POS = 6

◆ DATA_TYPE_SHORT

const DATA_TYPE_SHORT = 1

◆ DATA_TYPE_SLOT

const DATA_TYPE_SLOT = 5

◆ DATA_TYPE_STRING

const DATA_TYPE_STRING = 4

◆ DATA_TYPE_VECTOR3F

const DATA_TYPE_VECTOR3F = 8

◆ DATA_URL_TAG

const DATA_URL_TAG = 42

◆ DATA_VARIANT

const DATA_VARIANT = 2

◆ DATA_WITHER_INVULNERABLE_TICKS

const DATA_WITHER_INVULNERABLE_TICKS = 49

◆ DATA_WITHER_TARGET_1

const DATA_WITHER_TARGET_1 = 50

◆ DATA_WITHER_TARGET_2

const DATA_WITHER_TARGET_2 = 51

◆ DATA_WITHER_TARGET_3

const DATA_WITHER_TARGET_3 = 52

◆ EAST

const EAST = 3

◆ NETWORK_ID

const NETWORK_ID = -1

◆ NORTH

const NORTH = 2

◆ SOUTH

const SOUTH = 0

◆ WEST

const WEST = 1

The documentation for this class was generated from the following file: