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

Public Member Functions

 getSkinData ()
 
 getSkinId ()
 
 getUniqueId ()
 
 getRawUniqueId ()
 
 setSkin ($str, $skinId)
 
 getFood ()
 
 setFood (float $new)
 
 getMaxFood ()
 
 addFood (float $amount)
 
 getSaturation ()
 
 setSaturation (float $saturation)
 
 addSaturation (float $amount)
 
 getExhaustion ()
 
 setExhaustion (float $exhaustion)
 
 exhaust (float $amount, int $cause=PlayerExhaustEvent::CAUSE_CUSTOM)
 
 getXpLevel ()
 
 setXpLevel (int $level)
 
 addXpLevel (int $level)
 
 takeXpLevel (int $level)
 
 getXpProgress ()
 
 setXpProgress (float $progress)
 
 getTotalXp ()
 
 setTotalXp (int $xp, bool $syncLevel=false)
 
 addXp (int $xp, bool $syncLevel=false)
 
 takeXp (int $xp, bool $syncLevel=false)
 
 getRemainderXp ()
 
 getFilledXp ()
 
 recalculateXpProgress ()
 
 getXpSeed ()
 
 resetXpCooldown ()
 
 canPickupXp ()
 
 getInventory ()
 
 getEnderChestInventory ()
 
 getFloatingInventory ()
 
 getTransactionQueue ()
 
 getAbsorption ()
 
 setAbsorption (int $absorption)
 
 entityBaseTick ($tickDiff=1, $EnchantL=0)
 
 getName ()
 
 getDrops ()
 
 saveNBT ()
 
 spawnTo (Player $player)
 
 close ()
 
- Public Member Functions inherited from Creature
 onUpdate ($tick)
 
 willMove ($distance=36)
 
 attack ($damage, EntityDamageEvent $source)
 
 ifjump (Level $level, Vector3 $v3, $hate=false, $reason=false)
 
 whatBlock (Level $level, $v3)
 
 getMyYaw ($mx, $mz)
 
 getMyPitch (Vector3 $from, Vector3 $to)
 
- Public Member Functions inherited from Living
 setHealth ($amount)
 
 saveNBT ()
 
 getName ()
 
 hasLineOfSight (Entity $entity)
 
 heal ($amount, EntityRegainHealthEvent $source)
 
 attack ($damage, EntityDamageEvent $source)
 
 knockBack (Entity $attacker, $damage, $x, $z, $base=0.4)
 
 kill ()
 
 entityBaseTick ($tickDiff=1, $EnchantL=0)
 
 getDrops ()
 
 getLineOfSight ($maxDistance, $maxLength=0, array $transparent=[])
 
 getTargetBlock ($maxDistance, array $transparent=[])
 
- Public Member Functions inherited from Entity
 __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 getTotalXpRequirement (int $level)
 
static getLevelXpRequirement (int $level)
 
static getLevelFromXp (int $xp)
 
- Static Public Member Functions inherited from Entity
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 DATA_PLAYER_FLAG_SLEEP = 1
 
const DATA_PLAYER_FLAG_DEAD = 2
 
const DATA_PLAYER_FLAGS = 27
 
const DATA_PLAYER_BED_POSITION = 29
 
 $width = 0.6
 
 $length = 0.6
 
 $height = 1.8
 
 $eyeHeight = 1.62
 
- Data Fields inherited from Creature
 $attackingTick = 0
 
- Data Fields inherited from Entity
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
 

Protected Member Functions

 initEntity ()
 
 addAttributes ()
 
- Protected Member Functions inherited from Living
 initEntity ()
 
- Protected Member Functions inherited from Entity
 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

 $inventory
 
 $enderChestInventory
 
 $floatingInventory
 
 $transactionQueue = null
 
 $uuid
 
 $rawUUID
 
 $skinId
 
 $skin
 
 $foodTickTimer = 0
 
 $totalXp = 0
 
 $xpSeed
 
 $xpCooldown = 0
 
- Protected Attributes inherited from Living
 $gravity = 0.08
 
 $drag = 0.02
 
 $attackTime = 0
 
 $invisible = false
 
- Protected Attributes inherited from Entity
 $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 = []
 

Additional Inherited Members

- Static Public Attributes inherited from Entity
static $entityCount = 1
 

Member Function Documentation

◆ addAttributes()

addAttributes ( )
protected
617  {
618  parent::addAttributes();
619 
620  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::SATURATION));
621  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXHAUSTION));
622  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HUNGER));
623  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXPERIENCE_LEVEL));
624  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXPERIENCE));
625  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH));
626  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::MOVEMENT_SPEED));
627  $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION));
628  }

◆ addFood()

addFood ( float  $amount)
Parameters
float$amount
164  {
165  $attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
166  $amount += $attr->getValue();
167  $amount = max(min($amount, $attr->getMaxValue()), $attr->getMinValue());
168  $this->setFood($amount);
169  }

◆ addSaturation()

addSaturation ( float  $amount)
Parameters
float$amount
193  {
194  $attr = $this->attributeMap->getAttribute(Attribute::SATURATION);
195  $attr->setValue($attr->getValue() + $amount, true);
196  }

◆ addXp()

addXp ( int  $xp,
bool  $syncLevel = false 
)
Parameters
int$xp
bool$syncLevel
Returns
bool
372  : bool{
373  return $this->setTotalXp($this->totalXp + $xp, $syncLevel);
374  }

◆ addXpLevel()

addXpLevel ( int  $level)
Parameters
int$level
Returns
bool
278  : bool{
279  return $this->setXpLevel($this->getXpLevel() + $level);
280  }

◆ canPickupXp()

canPickupXp ( )
Returns
bool
423  : bool{
424  return microtime(true) - $this->xpCooldown > 0.5;
425  }

◆ close()

close ( )
804  {
805  if(!$this->closed){
806  if($this->getFloatingInventory() instanceof FloatingInventory){
807  foreach($this->getFloatingInventory()->getContents() as $craftingItem){
808  $this->level->dropItem($this, $craftingItem);
809  }
810  }else{
811  $this->server->getLogger()->debug("Attempted to drop a null crafting inventory\n");
812  }
813  if(!($this instanceof Player) or $this->loggedIn){
814  foreach($this->inventory->getViewers() as $viewer){
815  $viewer->removeWindow($this->inventory);
816  }
817  }
818  parent::close();
819  }
820  }

◆ entityBaseTick()

entityBaseTick (   $tickDiff = 1,
  $EnchantL = 0 
)
Parameters
int$tickDiff
int$EnchantL
Returns
bool
636  {
637  if($this->getInventory() instanceof PlayerInventory){
638  $EnchantL = $this->getInventory()->getHelmet()->getEnchantmentLevel(Enchantment::TYPE_WATER_BREATHING);
639  }
640  $hasUpdate = parent::entityBaseTick($tickDiff, $EnchantL);
641 
642  if($this->isAlive()){
643  $food = $this->getFood();
644  $health = $this->getHealth();
645  if($food >= 18){
646  $this->foodTickTimer++;
647  if($this->foodTickTimer >= 80 and $health < $this->getMaxHealth()){
648  $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
650  $this->foodTickTimer = 0;
651 
652  }
653  }elseif($food === 0){
654  $this->foodTickTimer++;
655  if($this->foodTickTimer >= 80){
656  $diff = $this->server->getDifficulty();
657  $can = false;
658  if($diff === 1){
659  $can = $health > 10;
660  }elseif($diff === 2){
661  $can = $health > 1;
662  }elseif($diff === 3){
663  $can = true;
664  }
665  if($can){
666  $this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
667  }
668  }
669  }
670  if($food <= 6){
671  if($this->isSprinting()){
672  $this->setSprinting(false);
673  }
674  }
675  }
676 
677  return $hasUpdate;
678  }

◆ exhaust()

exhaust ( float  $amount,
int  $cause = PlayerExhaustEvent::CAUSE_CUSTOM 
)

Increases a human's exhaustion level.

Parameters
float$amount
int$cause
Returns
float the amount of exhaustion level increased
223  : float{
224  $this->server->getPluginManager()->callEvent($ev = new PlayerExhaustEvent($this, $amount, $cause));
225  if($ev->isCancelled()){
226  return 0.0;
227  }
228 
229  $exhaustion = $this->getExhaustion();
230  $exhaustion += $ev->getAmount();
231 
232  while($exhaustion >= 4.0){
233  $exhaustion -= 4.0;
234 
235  $saturation = $this->getSaturation();
236  if($saturation > 0){
237  $saturation = max(0, $saturation - 1.0);
238  $this->setSaturation($saturation);
239  }else{
240  $food = $this->getFood();
241  if($food > 0){
242  $food--;
243  $this->setFood($food);
244  }
245  }
246  }
247  $this->setExhaustion($exhaustion);
248 
249  return $ev->getAmount();
250  }

◆ getAbsorption()

getAbsorption ( )
Returns
int
606  : int{
607  return $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue();
608  }

◆ getDrops()

getDrops ( )
Returns
array
690  {
691  $drops = [];
692  if($this->inventory !== null){
693  foreach($this->inventory->getContents() as $item){
694  $drops[] = $item;
695  }
696  }
697 
698  return $drops;
699  }

◆ getEnderChestInventory()

getEnderChestInventory ( )
Returns
EnderChestInventory
508  {
510  }

◆ getExhaustion()

getExhaustion ( )
Returns
float
201  : float{
202  return $this->attributeMap->getAttribute(Attribute::EXHAUSTION)->getValue();
203  }

◆ getFilledXp()

getFilledXp ( )
Returns
int
396  : int{
397  return self::getLevelXpRequirement($this->getXpLevel()) * $this->getXpProgress();
398  }

◆ getFloatingInventory()

getFloatingInventory ( )
Returns
FloatingInventory
515  {
517  }

◆ getFood()

getFood ( )
Returns
float
126  : float{
127  return $this->attributeMap->getAttribute(Attribute::HUNGER)->getValue();
128  }

◆ getInventory()

getInventory ( )
Returns
PlayerInventory

Implements InventoryHolder.

501  {
502  return $this->inventory;
503  }

◆ getLevelFromXp()

static getLevelFromXp ( int  $xp)
static

Converts a quantity of exp into a level and a progress percentage

Parameters
int$xp
Returns
int[]

These values are correct up to and including level 16

Modify the coefficients to fit the relevant equation

Levels 16-31

Level 32+

470  : array{
471  $xp &= 0x7fffffff;
472 
474  $a = 1;
475  $b = 6;
476  $c = -$xp;
477  if($xp > self::getTotalXpRequirement(16)){
479  if($xp <= self::getTotalXpRequirement(31)){
481  $a = 2.5;
482  $b = -40.5;
483  $c += 360;
484  }else{
486  $a = 4.5;
487  $b = -162.5;
488  $c += 2220;
489  }
490  }
491 
492  $answer = max(Math::solveQuadratic($a, $b, $c)); //Use largest result value
493  $level = floor($answer);
494  $progress = $answer - $level;
495  return [$level, $progress];
496  }

◆ getLevelXpRequirement()

static getLevelXpRequirement ( int  $level)
static

Returns the amount of exp required to complete the specified level.

Parameters
int$level
Returns
int
452  : int{
453  if($level <= 16){
454  return (2 * $level) + 7;
455  }elseif($level <= 31){
456  return (5 * $level) - 38;
457  }elseif($level <= 21863){
458  return (9 * $level) - 158;
459  }
460  return PHP_INT_MAX;
461  }

◆ getMaxFood()

getMaxFood ( )
Returns
float
157  : float{
158  return $this->attributeMap->getAttribute(Attribute::HUNGER)->getMaxValue();
159  }

◆ getName()

getName ( )
Returns
string
683  {
684  return $this->getNameTag();
685  }

◆ getRawUniqueId()

getRawUniqueId ( )
Returns
string
110  {
111  return $this->rawUUID;
112  }

◆ getRemainderXp()

getRemainderXp ( )
Returns
int
389  : int{
390  return self::getLevelXpRequirement($this->getXpLevel()) - $this->getFilledXp();
391  }

◆ getSaturation()

getSaturation ( )
Returns
float
174  : float{
175  return $this->attributeMap->getAttribute(Attribute::SATURATION)->getValue();
176  }

◆ getSkinData()

getSkinData ( )
Returns
mixed
89  {
90  return $this->skin;
91  }

◆ getSkinId()

getSkinId ( )
Returns
mixed
96  {
97  return $this->skinId;
98  }

◆ getTotalXp()

getTotalXp ( )
Returns
int
311  : int{
312  return $this->totalXp;
313  }

◆ getTotalXpRequirement()

static getTotalXpRequirement ( int  $level)
static

Returns the total amount of exp required to reach the specified level.

Parameters
int$level
Returns
int
434  : int{
435  if($level <= 16){
436  return ($level ** 2) + (6 * $level);
437  }elseif($level <= 31){
438  return (2.5 * ($level ** 2)) - (40.5 * $level) + 360;
439  }elseif($level <= 21863){
440  return (4.5 * ($level ** 2)) - (162.5 * $level) + 2220;
441  }
442  return PHP_INT_MAX; //prevent float returns for invalid levels on 32-bit systems
443  }

◆ getTransactionQueue()

getTransactionQueue ( )
Returns
SimpleTransactionQueue
522  {
523  //Is creating the transaction queue ondemand a good idea? I think only if it's destroyed afterwards. hmm...
524  if($this->transactionQueue === null){
525  //Potential for crashes here if a plugin attempts to use this, say for an NPC plugin or something...
526  $this->transactionQueue = new SimpleTransactionQueue($this);
527  }
529  }

◆ getUniqueId()

getUniqueId ( )
Returns
UUID|null
103  {
104  return $this->uuid;
105  }

◆ getXpLevel()

getXpLevel ( )
Returns
int
255  : int{
256  return (int) $this->attributeMap->getAttribute(Attribute::EXPERIENCE_LEVEL)->getValue();
257  }

◆ getXpProgress()

getXpProgress ( )
Returns
float
294  : float{
295  return $this->attributeMap->getAttribute(Attribute::EXPERIENCE)->getValue();
296  }

◆ getXpSeed()

getXpSeed ( )
Returns
int
411  : int{
412  //TODO: use this for randomizing enchantments in enchanting tables
413  return $this->xpSeed;
414  }

◆ initEntity()

initEntity ( )
protected
531  {
532  $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE);
533  $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false);
534 
535  $inventoryContents = ($this->namedtag->Inventory ?? null);
536  $this->inventory = new PlayerInventory($this, $inventoryContents);
537  $this->enderChestInventory = new EnderChestInventory($this, ($this->namedtag->EnderChestInventory ?? null));
538 
539  //Virtual inventory for desktop GUI crafting and anti-cheat transaction processing
540  $this->floatingInventory = new FloatingInventory($this);
541 
542  if($this instanceof Player){
543  $this->addWindow($this->inventory, 0);
544  }else{
545  if(isset($this->namedtag->NameTag)){
546  $this->setNameTag($this->namedtag["NameTag"]);
547  }
548 
549  if(isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag){
550  $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]);
551  }
552 
553  $this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag());
554  }
555 
556  parent::initEntity();
557 
558  if(!isset($this->namedtag->foodLevel) or !($this->namedtag->foodLevel instanceof IntTag)){
559  $this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
560  }else{
561  $this->setFood($this->namedtag["foodLevel"]);
562  }
563 
564  if(!isset($this->namedtag->foodExhaustionLevel) or !($this->namedtag->foodExhaustionLevel instanceof IntTag)){
565  $this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
566  }else{
567  $this->setExhaustion($this->namedtag["foodExhaustionLevel"]);
568  }
569 
570  if(!isset($this->namedtag->foodSaturationLevel) or !($this->namedtag->foodSaturationLevel instanceof IntTag)){
571  $this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
572  }else{
573  $this->setSaturation($this->namedtag["foodSaturationLevel"]);
574  }
575 
576  if(!isset($this->namedtag->foodTickTimer) or !($this->namedtag->foodTickTimer instanceof IntTag)){
577  $this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
578  }else{
579  $this->foodTickTimer = $this->namedtag["foodTickTimer"];
580  }
581 
582  if(!isset($this->namedtag->XpLevel) or !($this->namedtag->XpLevel instanceof IntTag)){
583  $this->namedtag->XpLevel = new IntTag("XpLevel", 0);
584  }
585  $this->setXpLevel($this->namedtag["XpLevel"]);
586 
587  if(!isset($this->namedtag->XpP) or !($this->namedtag->XpP instanceof FloatTag)){
588  $this->namedtag->XpP = new FloatTag("XpP", 0);
589  }
590  $this->setXpProgress($this->namedtag["XpP"]);
591 
592  if(!isset($this->namedtag->XpTotal) or !($this->namedtag->XpTotal instanceof IntTag)){
593  $this->namedtag->XpTotal = new IntTag("XpTotal", 0);
594  }
595  $this->totalXp = $this->namedtag["XpTotal"];
596 
597  if(!isset($this->namedtag->XpSeed) or !($this->namedtag->XpSeed instanceof IntTag)){
598  $this->namedtag->XpSeed = new IntTag("XpSeed", mt_rand(PHP_INT_MIN, PHP_INT_MAX));
599  }
600  $this->xpSeed = $this->namedtag["XpSeed"];
601  }

◆ recalculateXpProgress()

recalculateXpProgress ( )
Returns
float
403  : float{
404  $this->setXpProgress($progress = $this->getRemainderXp() / self::getLevelXpRequirement($this->getXpLevel()));
405  return $progress;
406  }

◆ resetXpCooldown()

resetXpCooldown ( )
416  {
417  $this->xpCooldown = microtime(true);
418  }

◆ saveNBT()

saveNBT ( )
701  {
702  parent::saveNBT();
703  $this->namedtag->Inventory = new ListTag("Inventory", []);
704  $this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
705  if($this->inventory !== null){
706 
707  //Hotbar
708  for($slot = 0; $slot < $this->inventory->getHotbarSize(); ++$slot){
709  $inventorySlotIndex = $this->inventory->getHotbarSlotIndex($slot);
710  $item = $this->inventory->getItem($inventorySlotIndex);
711  $tag = $item->nbtSerialize($slot);
712  $tag->TrueSlot = new ByteTag("TrueSlot", $inventorySlotIndex);
713  $this->namedtag->Inventory[$slot] = $tag;
714  }
715 
716  //Normal inventory
717  $slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
718  for($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot){
719  $item = $this->inventory->getItem($slot - $this->inventory->getHotbarSize());
720  //As NBT, real inventory slots are slots 9-44, NOT 0-35
721  $this->namedtag->Inventory[$slot] = $item->nbtSerialize($slot);
722  }
723 
724  //Armour
725  for($slot = 100; $slot < 104; ++$slot){
726  $item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
727  if($item instanceof ItemItem and $item->getId() !== ItemItem::AIR){
728  $this->namedtag->Inventory[$slot] = $item->nbtSerialize($slot);
729  }
730  }
731  }
732 
733  $this->namedtag->EnderChestInventory = new ListTag("EnderChestInventory", []);
734  $this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
735  if($this->enderChestInventory !== null){
736  for($slot = 0; $slot < $this->enderChestInventory->getSize(); $slot++){
737  if(($item = $this->enderChestInventory->getItem($slot)) instanceof ItemItem){
738  $this->namedtag->EnderChestInventory[$slot] = $item->nbtSerialize($slot);
739  }
740  }
741  }
742 
743  if(strlen($this->getSkinData()) > 0){
744  $this->namedtag->Skin = new CompoundTag("Skin", [
745  "Data" => new StringTag("Data", $this->getSkinData()),
746  "Name" => new StringTag("Name", $this->getSkinId())
747  ]);
748  }
749 
750  //Xp
751  $this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
752  $this->namedtag->XpTotal = new IntTag("XpTotal", $this->getTotalXp());
753  $this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
754  $this->namedtag->XpSeed = new IntTag("XpSeed", $this->getXpSeed());
755 
756  //Food
757  $this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
758  $this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
759  $this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
760  $this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
761  }

◆ setAbsorption()

setAbsorption ( int  $absorption)
Parameters
int$absorption
613  {
614  $this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption);
615  }

◆ setExhaustion()

setExhaustion ( float  $exhaustion)

WARNING: This method does not check if exhausted and does not consume saturation/food. Use Human::exhaust() for this purpose.

Parameters
float$exhaustion
211  {
212  $this->attributeMap->getAttribute(Attribute::EXHAUSTION)->setValue($exhaustion);
213  }

◆ setFood()

setFood ( float  $new)

WARNING: This method does not check if full and may throw an exception if out of bounds. Use Human::addFood() for this purpose

Parameters
float$new
Exceptions
138  {
139  $attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
140  $old = $attr->getValue();
141  $attr->setValue($new);
142  // ranges: 18-20 (regen), 7-17 (none), 1-6 (no sprint), 0 (health depletion)
143  foreach([17, 6, 0] as $bound){
144  if(($old > $bound) !== ($new > $bound)){
145  $reset = true;
146  }
147  }
148  if(isset($reset)){
149  $this->foodTickTimer = 0;
150  }
151 
152  }

◆ setSaturation()

setSaturation ( float  $saturation)

WARNING: This method does not check if saturated and may throw an exception if out of bounds. Use Human::addSaturation() for this purpose

Parameters
float$saturation
Exceptions
186  {
187  $this->attributeMap->getAttribute(Attribute::SATURATION)->setValue($saturation);
188  }

◆ setSkin()

setSkin (   $str,
  $skinId 
)
Parameters
string$str
string$skinId
118  {
119  $this->skin = $str;
120  $this->skinId = $skinId;
121  }

◆ setTotalXp()

setTotalXp ( int  $xp,
bool  $syncLevel = false 
)

Changes the total exp of a player

Parameters
int$xp
bool$syncLevelThis will reset the level to be in sync with the total. Usually you don't want to do this, because it'll mess up use of xp in anvils and enchanting tables.
Returns
bool
324  : bool{
325  $xp &= 0x7fffffff;
326  if($xp === $this->totalXp){
327  return false;
328  }
329  if(!$syncLevel){
330  $level = $this->getXpLevel();
331  $diff = $xp - $this->totalXp + $this->getFilledXp();
332  if($diff > 0){ //adding xp
333  while($diff > ($v = self::getLevelXpRequirement($level))){
334  $diff -= $v;
335  if(++$level >= 21863){
336  $diff = $v; //fill exp bar
337  break;
338  }
339  }
340  }else{ //taking xp
341  while($diff < ($v = self::getLevelXpRequirement($level - 1))){
342  $diff += $v;
343  if(--$level <= 0){
344  $diff = 0;
345  break;
346  }
347  }
348  }
349  $progress = ($diff / $v);
350  }else{
351  $values = self::getLevelFromXp($xp);
352  $level = $values[0];
353  $progress = $values[1];
354  }
355 
356  $this->server->getPluginManager()->callEvent($ev = new PlayerExperienceChangeEvent($this, $level, $progress));
357  if(!$ev->isCancelled()){
358  $this->totalXp = $xp;
359  $this->setXpLevel($ev->getExpLevel());
360  $this->setXpProgress($ev->getProgress());
361  return true;
362  }
363  return false;
364  }

◆ setXpLevel()

setXpLevel ( int  $level)
Parameters
int$level
Returns
bool
264  : bool{
265  $this->server->getPluginManager()->callEvent($ev = new PlayerExperienceChangeEvent($this, $level, $this->getXpProgress()));
266  if(!$ev->isCancelled()){
267  $this->attributeMap->getAttribute(Attribute::EXPERIENCE_LEVEL)->setValue($ev->getExpLevel());
268  return true;
269  }
270  return false;
271  }

◆ setXpProgress()

setXpProgress ( float  $progress)
Parameters
float$progress
Returns
bool
303  : bool{
304  $this->attributeMap->getAttribute(Attribute::EXPERIENCE)->setValue($progress);
305  return true;
306  }

◆ spawnTo()

spawnTo ( Player  $player)
Parameters
Player$player
766  {
767  if(strlen($this->skin) < 64 * 32 * 4){
768  $e = new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set");
769  $this->server->getLogger()->logException($e);
770  $this->close();
771  }elseif($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])){
772  $this->hasSpawned[$player->getLoaderId()] = $player;
773 
774  if(!($this instanceof Player)){
775  $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinId, $this->skin, [$player]);
776  }
777 
778  $pk = new AddPlayerPacket();
779  $pk->uuid = $this->getUniqueId();
780  $pk->username = $this->getName();
781  $pk->eid = $this->getId();
782  $pk->x = $this->x;
783  $pk->y = $this->y;
784  $pk->z = $this->z;
785  $pk->speedX = $this->motionX;
786  $pk->speedY = $this->motionY;
787  $pk->speedZ = $this->motionZ;
788  $pk->yaw = $this->yaw;
789  $pk->pitch = $this->pitch;
790  $pk->item = $this->getInventory()->getItemInHand();
791  $pk->metadata = $this->dataProperties;
792  $player->dataPacket($pk);
793 
794  $this->sendLinkedData();
795 
796  $this->inventory->sendArmorContents($player);
797 
798  if(!($this instanceof Player)){
799  $this->server->removePlayerListData($this->getUniqueId(), [$player]);
800  }
801  }
802  }

◆ takeXp()

takeXp ( int  $xp,
bool  $syncLevel = false 
)
Parameters
int$xp
bool$syncLevel
Returns
bool
382  : bool{
383  return $this->setTotalXp($this->totalXp - $xp, $syncLevel);
384  }

◆ takeXpLevel()

takeXpLevel ( int  $level)
Parameters
int$level
Returns
bool
287  : bool{
288  return $this->setXpLevel($this->getXpLevel() - $level);
289  }

Field Documentation

◆ $enderChestInventory

$enderChestInventory
protected

◆ $eyeHeight

$eyeHeight = 1.62

◆ $floatingInventory

$floatingInventory
protected

◆ $foodTickTimer

$foodTickTimer = 0
protected

◆ $height

$height = 1.8

◆ $inventory

$inventory
protected

◆ $length

$length = 0.6

◆ $rawUUID

$rawUUID
protected

◆ $skin

$skin
protected

◆ $skinId

$skinId
protected

◆ $totalXp

$totalXp = 0
protected

◆ $transactionQueue

$transactionQueue = null
protected

◆ $uuid

$uuid
protected

◆ $width

$width = 0.6

◆ $xpCooldown

$xpCooldown = 0
protected

◆ $xpSeed

$xpSeed
protected

◆ DATA_PLAYER_BED_POSITION

const DATA_PLAYER_BED_POSITION = 29

◆ DATA_PLAYER_FLAG_DEAD

const DATA_PLAYER_FLAG_DEAD = 2

◆ DATA_PLAYER_FLAG_SLEEP

const DATA_PLAYER_FLAG_SLEEP = 1

◆ DATA_PLAYER_FLAGS

const DATA_PLAYER_FLAGS = 27

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