Move a giant heap of network garbage out of Entity

This commit is contained in:
Dylan K. Taylor 2019-04-26 18:52:38 +01:00
parent ea8c723092
commit 854a2f5135
19 changed files with 488 additions and 339 deletions

View File

@ -104,6 +104,9 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\SetTitlePacket;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags;
use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissionAttachment;
use pocketmine\permission\PermissionAttachmentInfo;
@ -877,12 +880,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
* @return bool
*/
public function isUsingItem() : bool{
return $this->getGenericFlag(self::DATA_FLAG_ACTION) and $this->startAction > -1;
return $this->getGenericFlag(EntityMetadataFlags::ACTION) and $this->startAction > -1;
}
public function setUsingItem(bool $value){
$this->startAction = $value ? $this->server->getTick() : -1;
$this->setGenericFlag(self::DATA_FLAG_ACTION, $value);
$this->setGenericFlag(EntityMetadataFlags::ACTION, $value);
}
/**
@ -1197,8 +1200,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->sleeping = clone $pos;
$this->propertyManager->setBlockPos(self::DATA_PLAYER_BED_POSITION, $pos);
$this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, true);
$this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, $pos);
$this->setPlayerFlag(PlayerMetadataFlags::SLEEP, true);
$this->setSpawn($pos);
@ -1216,8 +1219,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
(new PlayerBedLeaveEvent($this, $b))->call();
$this->sleeping = null;
$this->propertyManager->setBlockPos(self::DATA_PLAYER_BED_POSITION, null);
$this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false);
$this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, null);
$this->setPlayerFlag(PlayerMetadataFlags::SLEEP, false);
$this->level->setSleepTicks(0);

View File

@ -24,9 +24,11 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
abstract class Animal extends Creature implements Ageable{
public function isBaby() : bool{
return $this->getGenericFlag(self::DATA_FLAG_BABY);
return $this->getGenericFlag(EntityMetadataFlags::BABY);
}
}

View File

@ -25,6 +25,7 @@ namespace pocketmine\entity;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use function assert;
use function is_float;
use function is_int;
@ -46,7 +47,7 @@ class DataPropertyManager{
* @return int|null
*/
public function getByte(int $key) : ?int{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_BYTE);
$value = $this->getPropertyValue($key, EntityMetadataTypes::BYTE);
assert(is_int($value) or $value === null);
return $value;
}
@ -57,7 +58,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setByte(int $key, int $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_BYTE, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::BYTE, $value, $force);
}
/**
@ -66,7 +67,7 @@ class DataPropertyManager{
* @return int|null
*/
public function getShort(int $key) : ?int{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_SHORT);
$value = $this->getPropertyValue($key, EntityMetadataTypes::SHORT);
assert(is_int($value) or $value === null);
return $value;
}
@ -77,7 +78,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setShort(int $key, int $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_SHORT, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::SHORT, $value, $force);
}
/**
@ -86,7 +87,7 @@ class DataPropertyManager{
* @return int|null
*/
public function getInt(int $key) : ?int{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_INT);
$value = $this->getPropertyValue($key, EntityMetadataTypes::INT);
assert(is_int($value) or $value === null);
return $value;
}
@ -97,7 +98,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setInt(int $key, int $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_INT, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::INT, $value, $force);
}
/**
@ -106,7 +107,7 @@ class DataPropertyManager{
* @return float|null
*/
public function getFloat(int $key) : ?float{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_FLOAT);
$value = $this->getPropertyValue($key, EntityMetadataTypes::FLOAT);
assert(is_float($value) or $value === null);
return $value;
}
@ -117,7 +118,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setFloat(int $key, float $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_FLOAT, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::FLOAT, $value, $force);
}
/**
@ -126,7 +127,7 @@ class DataPropertyManager{
* @return null|string
*/
public function getString(int $key) : ?string{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_STRING);
$value = $this->getPropertyValue($key, EntityMetadataTypes::STRING);
assert(is_string($value) or $value === null);
return $value;
}
@ -137,7 +138,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setString(int $key, string $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_STRING, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::STRING, $value, $force);
}
/**
@ -146,7 +147,7 @@ class DataPropertyManager{
* @return null|Item
*/
public function getItem(int $key) : ?Item{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_SLOT);
$value = $this->getPropertyValue($key, EntityMetadataTypes::SLOT);
assert($value instanceof Item or $value === null);
return $value;
@ -158,7 +159,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setItem(int $key, Item $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_SLOT, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::SLOT, $value, $force);
}
/**
@ -167,7 +168,7 @@ class DataPropertyManager{
* @return null|Vector3
*/
public function getBlockPos(int $key) : ?Vector3{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_POS);
$value = $this->getPropertyValue($key, EntityMetadataTypes::POS);
assert($value instanceof Vector3 or $value === null);
return $value;
}
@ -178,7 +179,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setBlockPos(int $key, ?Vector3 $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_POS, $value ? $value->floor() : null, $force);
$this->setPropertyValue($key, EntityMetadataTypes::POS, $value ? $value->floor() : null, $force);
}
/**
@ -187,7 +188,7 @@ class DataPropertyManager{
* @return int|null
*/
public function getLong(int $key) : ?int{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_LONG);
$value = $this->getPropertyValue($key, EntityMetadataTypes::LONG);
assert(is_int($value) or $value === null);
return $value;
}
@ -198,7 +199,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setLong(int $key, int $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_LONG, $value, $force);
$this->setPropertyValue($key, EntityMetadataTypes::LONG, $value, $force);
}
/**
@ -207,7 +208,7 @@ class DataPropertyManager{
* @return null|Vector3
*/
public function getVector3(int $key) : ?Vector3{
$value = $this->getPropertyValue($key, Entity::DATA_TYPE_VECTOR3F);
$value = $this->getPropertyValue($key, EntityMetadataTypes::VECTOR3F);
assert($value instanceof Vector3 or $value === null);
return $value;
}
@ -218,7 +219,7 @@ class DataPropertyManager{
* @param bool $force
*/
public function setVector3(int $key, ?Vector3 $value, bool $force = false) : void{
$this->setPropertyValue($key, Entity::DATA_TYPE_VECTOR3F, $value ? $value->asVector3() : null, $force);
$this->setPropertyValue($key, EntityMetadataTypes::VECTOR3F, $value ? $value->asVector3() : null, $force);
}
/**

View File

@ -58,6 +58,9 @@ use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\SetEntityDataPacket;
use pocketmine\network\mcpe\protocol\SetEntityMotionPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
@ -84,221 +87,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public const NETWORK_ID = -1;
public const DATA_TYPE_BYTE = 0;
public const DATA_TYPE_SHORT = 1;
public const DATA_TYPE_INT = 2;
public const DATA_TYPE_FLOAT = 3;
public const DATA_TYPE_STRING = 4;
public const DATA_TYPE_SLOT = 5;
public const DATA_TYPE_POS = 6;
public const DATA_TYPE_LONG = 7;
public const DATA_TYPE_VECTOR3F = 8;
/*
* Readers beware: this isn't a nice list. Some of the properties have different types for different entities, and
* are used for entirely different things.
*/
public const DATA_FLAGS = 0;
public const DATA_HEALTH = 1; //int (minecart/boat)
public const DATA_VARIANT = 2; //int
public const DATA_COLOR = 3, DATA_COLOUR = 3; //byte
public const DATA_NAMETAG = 4; //string
public const DATA_OWNER_EID = 5; //long
public const DATA_TARGET_EID = 6; //long
public const DATA_AIR = 7; //short
public const DATA_POTION_COLOR = 8; //int (ARGB!)
public const DATA_POTION_AMBIENT = 9; //byte
/* 10 (byte) */
public const DATA_HURT_TIME = 11; //int (minecart/boat)
public const DATA_HURT_DIRECTION = 12; //int (minecart/boat)
public const DATA_PADDLE_TIME_LEFT = 13; //float
public const DATA_PADDLE_TIME_RIGHT = 14; //float
public const DATA_EXPERIENCE_VALUE = 15; //int (xp orb)
public const DATA_MINECART_DISPLAY_BLOCK = 16; //int (id | (data << 16))
public const DATA_HORSE_FLAGS = 16; //int
/* 16 (byte) used by wither skull */
public const DATA_MINECART_DISPLAY_OFFSET = 17; //int
public const DATA_SHOOTER_ID = 17; //long (used by arrows)
public const DATA_MINECART_HAS_DISPLAY = 18; //byte (must be 1 for minecart to show block inside)
public const DATA_HORSE_TYPE = 19; //byte
/* 20 (unknown)
* 21 (unknown) */
public const DATA_CHARGE_AMOUNT = 22; //int8, used for ghasts and also crossbow charging
public const DATA_ENDERMAN_HELD_ITEM_ID = 23; //short
public const DATA_ENTITY_AGE = 24; //short
/* 25 (int) used by horse, (byte) used by witch */
public const DATA_PLAYER_FLAGS = 26; //byte
public const DATA_PLAYER_INDEX = 27; //int, used for marker colours and agent nametag colours
public const DATA_PLAYER_BED_POSITION = 28; //blockpos
public const DATA_FIREBALL_POWER_X = 29; //float
public const DATA_FIREBALL_POWER_Y = 30;
public const DATA_FIREBALL_POWER_Z = 31;
/* 32 (unknown)
* 33 (float) fishing bobber
* 34 (float) fishing bobber
* 35 (float) fishing bobber */
public const DATA_POTION_AUX_VALUE = 36; //short
public const DATA_LEAD_HOLDER_EID = 37; //long
public const DATA_SCALE = 38; //float
public const DATA_HAS_NPC_COMPONENT = 39; //byte (???)
public const DATA_SKIN_ID = 40; //string
public const DATA_NPC_SKIN_ID = 41; //string
public const DATA_URL_TAG = 42; //string
public const DATA_MAX_AIR = 43; //short
public const DATA_MARK_VARIANT = 44; //int
public const DATA_CONTAINER_TYPE = 45; //byte (ContainerComponent)
public const DATA_CONTAINER_BASE_SIZE = 46; //int (ContainerComponent)
public const DATA_CONTAINER_EXTRA_SLOTS_PER_STRENGTH = 47; //int (used for llamas, inventory size is baseSize + thisProp * strength)
public const DATA_BLOCK_TARGET = 48; //block coords (ender crystal)
public const DATA_WITHER_INVULNERABLE_TICKS = 49; //int
public const DATA_WITHER_TARGET_1 = 50; //long
public const DATA_WITHER_TARGET_2 = 51; //long
public const DATA_WITHER_TARGET_3 = 52; //long
/* 53 (short) */
public const DATA_BOUNDING_BOX_WIDTH = 54; //float
public const DATA_BOUNDING_BOX_HEIGHT = 55; //float
public const DATA_FUSE_LENGTH = 56; //int
public const DATA_RIDER_SEAT_POSITION = 57; //vector3f
public const DATA_RIDER_ROTATION_LOCKED = 58; //byte
public const DATA_RIDER_MAX_ROTATION = 59; //float
public const DATA_RIDER_MIN_ROTATION = 60; //float
public const DATA_AREA_EFFECT_CLOUD_RADIUS = 61; //float
public const DATA_AREA_EFFECT_CLOUD_WAITING = 62; //int
public const DATA_AREA_EFFECT_CLOUD_PARTICLE_ID = 63; //int
/* 64 (int) shulker-related */
public const DATA_SHULKER_ATTACH_FACE = 65; //byte
/* 66 (short) shulker-related */
public const DATA_SHULKER_ATTACH_POS = 67; //block coords
public const DATA_TRADING_PLAYER_EID = 68; //long
/* 70 (byte) command-block */
public const DATA_COMMAND_BLOCK_COMMAND = 71; //string
public const DATA_COMMAND_BLOCK_LAST_OUTPUT = 72; //string
public const DATA_COMMAND_BLOCK_TRACK_OUTPUT = 73; //byte
public const DATA_CONTROLLING_RIDER_SEAT_NUMBER = 74; //byte
public const DATA_STRENGTH = 75; //int
public const DATA_MAX_STRENGTH = 76; //int
/* 77 (int) */
public const DATA_LIMITED_LIFE = 78;
public const DATA_ARMOR_STAND_POSE_INDEX = 79; //int
public const DATA_ENDER_CRYSTAL_TIME_OFFSET = 80; //int
public const DATA_ALWAYS_SHOW_NAMETAG = 81; //byte: -1 = default, 0 = only when looked at, 1 = always
public const DATA_COLOR_2 = 82; //byte
/* 83 (unknown) */
public const DATA_SCORE_TAG = 84; //string
public const DATA_BALLOON_ATTACHED_ENTITY = 85; //int64, entity unique ID of owner
public const DATA_PUFFERFISH_SIZE = 86; //byte
public const DATA_BOAT_BUBBLE_TIME = 87; //int (time in bubble column)
public const DATA_PLAYER_AGENT_EID = 88; //long
/* 89 (float) related to panda sitting
* 90 (float) related to panda sitting */
public const DATA_EAT_COUNTER = 91; //int (used by pandas)
public const DATA_FLAGS2 = 92; //long (extended data flags)
/* 93 (float) related to panda lying down
* 94 (float) related to panda lying down */
public const DATA_AREA_EFFECT_CLOUD_DURATION = 95; //int
public const DATA_AREA_EFFECT_CLOUD_SPAWN_TIME = 96; //int
public const DATA_AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 97; //float, usually negative
public const DATA_AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 98; //float
public const DATA_AREA_EFFECT_CLOUD_PICKUP_COUNT = 99; //int
public const DATA_INTERACTIVE_TAG = 100; //string (button text)
public const DATA_TRADE_TIER = 101; //int
public const DATA_MAX_TRADE_TIER = 102; //int
public const DATA_TRADE_XP = 103; //int
public const DATA_FLAG_ONFIRE = 0;
public const DATA_FLAG_SNEAKING = 1;
public const DATA_FLAG_RIDING = 2;
public const DATA_FLAG_SPRINTING = 3;
public const DATA_FLAG_ACTION = 4;
public const DATA_FLAG_INVISIBLE = 5;
public const DATA_FLAG_TEMPTED = 6;
public const DATA_FLAG_INLOVE = 7;
public const DATA_FLAG_SADDLED = 8;
public const DATA_FLAG_POWERED = 9;
public const DATA_FLAG_IGNITED = 10;
public const DATA_FLAG_BABY = 11;
public const DATA_FLAG_CONVERTING = 12;
public const DATA_FLAG_CRITICAL = 13;
public const DATA_FLAG_CAN_SHOW_NAMETAG = 14;
public const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15;
public const DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16;
public const DATA_FLAG_SILENT = 17;
public const DATA_FLAG_WALLCLIMBING = 18;
public const DATA_FLAG_CAN_CLIMB = 19;
public const DATA_FLAG_SWIMMER = 20;
public const DATA_FLAG_CAN_FLY = 21;
public const DATA_FLAG_WALKER = 22;
public const DATA_FLAG_RESTING = 23;
public const DATA_FLAG_SITTING = 24;
public const DATA_FLAG_ANGRY = 25;
public const DATA_FLAG_INTERESTED = 26;
public const DATA_FLAG_CHARGED = 27;
public const DATA_FLAG_TAMED = 28;
public const DATA_FLAG_ORPHANED = 29;
public const DATA_FLAG_LEASHED = 30;
public const DATA_FLAG_SHEARED = 31;
public const DATA_FLAG_GLIDING = 32;
public const DATA_FLAG_ELDER = 33;
public const DATA_FLAG_MOVING = 34;
public const DATA_FLAG_BREATHING = 35;
public const DATA_FLAG_CHESTED = 36;
public const DATA_FLAG_STACKABLE = 37;
public const DATA_FLAG_SHOWBASE = 38;
public const DATA_FLAG_REARING = 39;
public const DATA_FLAG_VIBRATING = 40;
public const DATA_FLAG_IDLING = 41;
public const DATA_FLAG_EVOKER_SPELL = 42;
public const DATA_FLAG_CHARGE_ATTACK = 43;
public const DATA_FLAG_WASD_CONTROLLED = 44;
public const DATA_FLAG_CAN_POWER_JUMP = 45;
public const DATA_FLAG_LINGER = 46;
public const DATA_FLAG_HAS_COLLISION = 47;
public const DATA_FLAG_AFFECTED_BY_GRAVITY = 48;
public const DATA_FLAG_FIRE_IMMUNE = 49;
public const DATA_FLAG_DANCING = 50;
public const DATA_FLAG_ENCHANTED = 51;
public const DATA_FLAG_SHOW_TRIDENT_ROPE = 52; // tridents show an animated rope when enchanted with loyalty after they are thrown and return to their owner. To be combined with DATA_OWNER_EID
public const DATA_FLAG_CONTAINER_PRIVATE = 53; //inventory is private, doesn't drop contents when killed if true
public const DATA_FLAG_TRANSFORMING = 54;
public const DATA_FLAG_SPIN_ATTACK = 55;
public const DATA_FLAG_SWIMMING = 56;
public const DATA_FLAG_BRIBED = 57; //dolphins have this set when they go to find treasure for the player
public const DATA_FLAG_PREGNANT = 58;
public const DATA_FLAG_LAYING_EGG = 59;
public const DATA_FLAG_RIDER_CAN_PICK = 60; //???
public const DATA_FLAG_TRANSITION_SITTING = 61;
public const DATA_FLAG_EATING = 62;
public const DATA_FLAG_LAYING_DOWN = 63;
public const DATA_FLAG_SNEEZING = 64;
public const DATA_FLAG_TRUSTING = 65;
public const DATA_FLAG_ROLLING = 66;
public const DATA_FLAG_SCARED = 67;
public const DATA_FLAG_IN_SCAFFOLDING = 68;
public const DATA_FLAG_OVER_SCAFFOLDING = 69;
public const DATA_FLAG_FALL_THROUGH_SCAFFOLDING = 70;
public const DATA_FLAG_BLOCKING = 71; //shield
public const DATA_FLAG_DISABLE_BLOCKING = 72;
//73 is set when a player is attacked while using shield, unclear on purpose
//74 related to shield usage, needs further investigation
public const DATA_FLAG_SLEEPING = 75;
//76 related to sleeping, unclear usage
public const DATA_FLAG_TRADE_INTEREST = 77;
public const DATA_FLAG_DOOR_BREAKER = 78; //...
public const DATA_FLAG_BREAKING_OBSTRUCTION = 79;
public const DATA_FLAG_DOOR_OPENER = 80; //...
public const DATA_FLAG_ILLAGER_CAPTAIN = 81;
public const DATA_FLAG_STUNNED = 82;
public const DATA_FLAG_ROARING = 83;
public const DATA_FLAG_DELAYED_ATTACKING = 84;
public const DATA_FLAG_AVOIDING_MOBS = 85;
//86 used by RangedAttackGoal
//87 used by NearestAttackableTargetGoal
public const DATA_PLAYER_FLAG_SLEEP = 1;
public const DATA_PLAYER_FLAG_DEAD = 2; //TODO: CHECK
/**
* @var Player[]
*/
@ -448,19 +236,19 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->propertyManager = new DataPropertyManager();
$this->propertyManager->setLong(self::DATA_FLAGS, 0);
$this->propertyManager->setShort(self::DATA_MAX_AIR, 400);
$this->propertyManager->setString(self::DATA_NAMETAG, "");
$this->propertyManager->setLong(self::DATA_LEAD_HOLDER_EID, -1);
$this->propertyManager->setFloat(self::DATA_SCALE, 1);
$this->propertyManager->setFloat(self::DATA_BOUNDING_BOX_WIDTH, $this->width);
$this->propertyManager->setFloat(self::DATA_BOUNDING_BOX_HEIGHT, $this->height);
$this->propertyManager->setLong(EntityMetadataProperties::FLAGS, 0);
$this->propertyManager->setShort(EntityMetadataProperties::MAX_AIR, 400);
$this->propertyManager->setString(EntityMetadataProperties::NAMETAG, "");
$this->propertyManager->setLong(EntityMetadataProperties::LEAD_HOLDER_EID, -1);
$this->propertyManager->setFloat(EntityMetadataProperties::SCALE, 1);
$this->propertyManager->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, $this->width);
$this->propertyManager->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, $this->height);
$this->attributeMap = new AttributeMap();
$this->addAttributes();
$this->setGenericFlag(self::DATA_FLAG_AFFECTED_BY_GRAVITY, true);
$this->setGenericFlag(self::DATA_FLAG_HAS_COLLISION, true);
$this->setGenericFlag(EntityMetadataFlags::AFFECTED_BY_GRAVITY, true);
$this->setGenericFlag(EntityMetadataFlags::HAS_COLLISION, true);
$this->initEntity($nbt);
$this->propertyManager->clearDirtyProperties(); //Prevents resending properties that were set during construction
@ -479,21 +267,21 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return string
*/
public function getNameTag() : string{
return $this->propertyManager->getString(self::DATA_NAMETAG);
return $this->propertyManager->getString(EntityMetadataProperties::NAMETAG);
}
/**
* @return bool
*/
public function isNameTagVisible() : bool{
return $this->getGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG);
return $this->getGenericFlag(EntityMetadataFlags::CAN_SHOW_NAMETAG);
}
/**
* @return bool
*/
public function isNameTagAlwaysVisible() : bool{
return $this->getGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG);
return $this->getGenericFlag(EntityMetadataFlags::ALWAYS_SHOW_NAMETAG);
}
@ -501,42 +289,42 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param string $name
*/
public function setNameTag(string $name) : void{
$this->propertyManager->setString(self::DATA_NAMETAG, $name);
$this->propertyManager->setString(EntityMetadataProperties::NAMETAG, $name);
}
/**
* @param bool $value
*/
public function setNameTagVisible(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG, $value);
$this->setGenericFlag(EntityMetadataFlags::CAN_SHOW_NAMETAG, $value);
}
/**
* @param bool $value
*/
public function setNameTagAlwaysVisible(bool $value = true) : void{
$this->propertyManager->setByte(self::DATA_ALWAYS_SHOW_NAMETAG, $value ? 1 : 0);
$this->propertyManager->setByte(EntityMetadataProperties::ALWAYS_SHOW_NAMETAG, $value ? 1 : 0);
}
/**
* @return string|null
*/
public function getScoreTag() : ?string{
return $this->propertyManager->getString(self::DATA_SCORE_TAG);
return $this->propertyManager->getString(EntityMetadataProperties::SCORE_TAG);
}
/**
* @param string $score
*/
public function setScoreTag(string $score) : void{
$this->propertyManager->setString(self::DATA_SCORE_TAG, $score);
$this->propertyManager->setString(EntityMetadataProperties::SCORE_TAG, $score);
}
/**
* @return float
*/
public function getScale() : float{
return $this->propertyManager->getFloat(self::DATA_SCALE);
return $this->propertyManager->getFloat(EntityMetadataProperties::SCALE);
}
/**
@ -554,7 +342,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->recalculateBoundingBox();
$this->propertyManager->setFloat(self::DATA_SCALE, $value);
$this->propertyManager->setFloat(EntityMetadataProperties::SCALE, $value);
}
public function getBoundingBox() : AxisAlignedBB{
@ -575,39 +363,39 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function isSneaking() : bool{
return $this->getGenericFlag(self::DATA_FLAG_SNEAKING);
return $this->getGenericFlag(EntityMetadataFlags::SNEAKING);
}
public function setSneaking(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_SNEAKING, $value);
$this->setGenericFlag(EntityMetadataFlags::SNEAKING, $value);
}
public function isSprinting() : bool{
return $this->getGenericFlag(self::DATA_FLAG_SPRINTING);
return $this->getGenericFlag(EntityMetadataFlags::SPRINTING);
}
public function setSprinting(bool $value = true) : void{
if($value !== $this->isSprinting()){
$this->setGenericFlag(self::DATA_FLAG_SPRINTING, $value);
$this->setGenericFlag(EntityMetadataFlags::SPRINTING, $value);
$attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true);
}
}
public function isImmobile() : bool{
return $this->getGenericFlag(self::DATA_FLAG_IMMOBILE);
return $this->getGenericFlag(EntityMetadataFlags::IMMOBILE);
}
public function setImmobile(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_IMMOBILE, $value);
$this->setGenericFlag(EntityMetadataFlags::IMMOBILE, $value);
}
public function isInvisible() : bool{
return $this->getGenericFlag(self::DATA_FLAG_INVISIBLE);
return $this->getGenericFlag(EntityMetadataFlags::INVISIBLE);
}
public function setInvisible(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_INVISIBLE, $value);
$this->setGenericFlag(EntityMetadataFlags::INVISIBLE, $value);
}
/**
@ -615,7 +403,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return bool
*/
public function canClimb() : bool{
return $this->getGenericFlag(self::DATA_FLAG_CAN_CLIMB);
return $this->getGenericFlag(EntityMetadataFlags::CAN_CLIMB);
}
/**
@ -624,7 +412,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value
*/
public function setCanClimb(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value);
$this->setGenericFlag(EntityMetadataFlags::CAN_CLIMB, $value);
}
/**
@ -633,7 +421,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return bool
*/
public function canClimbWalls() : bool{
return $this->getGenericFlag(self::DATA_FLAG_WALLCLIMBING);
return $this->getGenericFlag(EntityMetadataFlags::WALLCLIMBING);
}
/**
@ -642,7 +430,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value
*/
public function setCanClimbWalls(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_WALLCLIMBING, $value);
$this->setGenericFlag(EntityMetadataFlags::WALLCLIMBING, $value);
}
/**
@ -650,7 +438,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return int|null
*/
public function getOwningEntityId() : ?int{
return $this->propertyManager->getLong(self::DATA_OWNER_EID);
return $this->propertyManager->getLong(EntityMetadataProperties::OWNER_EID);
}
/**
@ -675,11 +463,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*/
public function setOwningEntity(?Entity $owner) : void{
if($owner === null){
$this->propertyManager->removeProperty(self::DATA_OWNER_EID);
$this->propertyManager->removeProperty(EntityMetadataProperties::OWNER_EID);
}elseif($owner->closed){
throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used");
}else{
$this->propertyManager->setLong(self::DATA_OWNER_EID, $owner->getId());
$this->propertyManager->setLong(EntityMetadataProperties::OWNER_EID, $owner->getId());
}
}
@ -688,7 +476,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return int|null
*/
public function getTargetEntityId() : ?int{
return $this->propertyManager->getLong(self::DATA_TARGET_EID);
return $this->propertyManager->getLong(EntityMetadataProperties::TARGET_EID);
}
/**
@ -715,11 +503,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*/
public function setTargetEntity(?Entity $target) : void{
if($target === null){
$this->propertyManager->removeProperty(self::DATA_TARGET_EID);
$this->propertyManager->removeProperty(EntityMetadataProperties::TARGET_EID);
}elseif($target->closed){
throw new \InvalidArgumentException("Supplied target entity is garbage and cannot be used");
}else{
$this->propertyManager->setLong(self::DATA_TARGET_EID, $target->getId());
$this->propertyManager->setLong(EntityMetadataProperties::TARGET_EID, $target->getId());
}
}
@ -771,7 +559,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$nbt->setFloat("FallDistance", $this->fallDistance);
$nbt->setShort("Fire", $this->fireTicks);
$nbt->setShort("Air", $this->propertyManager->getShort(self::DATA_AIR));
$nbt->setShort("Air", $this->propertyManager->getShort(EntityMetadataProperties::AIR));
$nbt->setByte("OnGround", $this->onGround ? 1 : 0);
$nbt->setByte("Invulnerable", $this->invulnerable ? 1 : 0);
@ -781,10 +569,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
protected function initEntity(CompoundTag $nbt) : void{
$this->fireTicks = $nbt->getShort("Fire", 0);
if($this->isOnFire()){
$this->setGenericFlag(self::DATA_FLAG_ONFIRE);
$this->setGenericFlag(EntityMetadataFlags::ONFIRE);
}
$this->propertyManager->setShort(self::DATA_AIR, $nbt->getShort("Air", 300));
$this->propertyManager->setShort(EntityMetadataProperties::AIR, $nbt->getShort("Air", 300));
$this->onGround = $nbt->getByte("OnGround", 0) !== 0;
$this->invulnerable = $nbt->getByte("Invulnerable", 0) !== 0;
@ -973,7 +761,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->setFireTicks($ticks);
}
$this->setGenericFlag(self::DATA_FLAG_ONFIRE, true);
$this->setGenericFlag(EntityMetadataFlags::ONFIRE, true);
}
/**
@ -996,7 +784,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function extinguish() : void{
$this->fireTicks = 0;
$this->setGenericFlag(self::DATA_FLAG_ONFIRE, false);
$this->setGenericFlag(EntityMetadataFlags::ONFIRE, false);
}
public function isFireProof() : bool{
@ -1949,7 +1737,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value
* @param int $propertyType
*/
public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = self::DATA_TYPE_LONG) : void{
public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = EntityMetadataTypes::LONG) : void{
if($this->getDataFlag($propertyId, $flagId) !== $value){
$flags = (int) $this->propertyManager->getPropertyValue($propertyId, $propertyType);
$flags ^= 1 << $flagId;
@ -1975,7 +1763,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @return bool
*/
public function getGenericFlag(int $flagId) : bool{
return $this->getDataFlag($flagId >= 64 ? self::DATA_FLAGS2 : self::DATA_FLAGS, $flagId % 64);
return $this->getDataFlag($flagId >= 64 ? EntityMetadataProperties::FLAGS2 : EntityMetadataProperties::FLAGS, $flagId % 64);
}
/**
@ -1985,7 +1773,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value
*/
public function setGenericFlag(int $flagId, bool $value = true) : void{
$this->setDataFlag($flagId >= 64 ? self::DATA_FLAGS2 : self::DATA_FLAGS, $flagId % 64, $value, self::DATA_TYPE_LONG);
$this->setDataFlag($flagId >= 64 ? EntityMetadataProperties::FLAGS2 : EntityMetadataProperties::FLAGS, $flagId % 64, $value, EntityMetadataTypes::LONG);
}
/**

View File

@ -56,7 +56,10 @@ use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags;
use pocketmine\Player;
use pocketmine\utils\UUID;
use function array_filter;
@ -604,8 +607,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt);
$this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false);
$this->propertyManager->setBlockPos(self::DATA_PLAYER_BED_POSITION, null);
$this->setPlayerFlag(PlayerMetadataFlags::SLEEP, false);
$this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, null);
$this->inventory = new PlayerInventory($this);
$this->enderChestInventory = new EnderChestInventory();
@ -871,7 +874,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$player->sendDataPacket($pk);
//TODO: Hack for MCPE 1.2.13: DATA_NAMETAG is useless in AddPlayerPacket, so it has to be sent separately
$this->sendData($player, [self::DATA_NAMETAG => [self::DATA_TYPE_STRING, $this->getNameTag()]]);
$this->sendData($player, [EntityMetadataProperties::NAMETAG => [EntityMetadataTypes::STRING, $this->getNameTag()]]);
$this->armorInventory->sendContents($player);
@ -903,7 +906,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* @return bool
*/
public function getPlayerFlag(int $flagId) : bool{
return $this->getDataFlag(self::DATA_PLAYER_FLAGS, $flagId);
return $this->getDataFlag(EntityMetadataProperties::PLAYER_FLAGS, $flagId);
}
/**
@ -913,6 +916,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* @param bool $value
*/
public function setPlayerFlag(int $flagId, bool $value = true) : void{
$this->setDataFlag(self::DATA_PLAYER_FLAGS, $flagId, $value, self::DATA_TYPE_BYTE);
$this->setDataFlag(EntityMetadataProperties::PLAYER_FLAGS, $flagId, $value, EntityMetadataTypes::BYTE);
}
}

View File

@ -48,6 +48,8 @@ use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\Player;
use pocketmine\timings\Timings;
use pocketmine\utils\Binary;
@ -341,11 +343,11 @@ abstract class Living extends Entity implements Damageable{
}
if(!empty($colors)){
$this->propertyManager->setInt(Entity::DATA_POTION_COLOR, Color::mix(...$colors)->toARGB());
$this->propertyManager->setByte(Entity::DATA_POTION_AMBIENT, $ambient ? 1 : 0);
$this->propertyManager->setInt(EntityMetadataProperties::POTION_COLOR, Color::mix(...$colors)->toARGB());
$this->propertyManager->setByte(EntityMetadataProperties::POTION_AMBIENT, $ambient ? 1 : 0);
}else{
$this->propertyManager->setInt(Entity::DATA_POTION_COLOR, 0);
$this->propertyManager->setByte(Entity::DATA_POTION_AMBIENT, 0);
$this->propertyManager->setInt(EntityMetadataProperties::POTION_COLOR, 0);
$this->propertyManager->setByte(EntityMetadataProperties::POTION_AMBIENT, 0);
}
}
@ -769,7 +771,7 @@ abstract class Living extends Entity implements Damageable{
* @return bool
*/
public function isBreathing() : bool{
return $this->getGenericFlag(self::DATA_FLAG_BREATHING);
return $this->getGenericFlag(EntityMetadataFlags::BREATHING);
}
/**
@ -779,7 +781,7 @@ abstract class Living extends Entity implements Damageable{
* @param bool $value
*/
public function setBreathing(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_BREATHING, $value);
$this->setGenericFlag(EntityMetadataFlags::BREATHING, $value);
}
/**
@ -789,7 +791,7 @@ abstract class Living extends Entity implements Damageable{
* @return int
*/
public function getAirSupplyTicks() : int{
return $this->propertyManager->getShort(self::DATA_AIR);
return $this->propertyManager->getShort(EntityMetadataProperties::AIR);
}
/**
@ -798,7 +800,7 @@ abstract class Living extends Entity implements Damageable{
* @param int $ticks
*/
public function setAirSupplyTicks(int $ticks) : void{
$this->propertyManager->setShort(self::DATA_AIR, $ticks);
$this->propertyManager->setShort(EntityMetadataProperties::AIR, $ticks);
}
/**
@ -806,7 +808,7 @@ abstract class Living extends Entity implements Damageable{
* @return int
*/
public function getMaxAirSupplyTicks() : int{
return $this->propertyManager->getShort(self::DATA_MAX_AIR);
return $this->propertyManager->getShort(EntityMetadataProperties::MAX_AIR);
}
/**
@ -815,7 +817,7 @@ abstract class Living extends Entity implements Damageable{
* @param int $ticks
*/
public function setMaxAirSupplyTicks(int $ticks) : void{
$this->propertyManager->setShort(self::DATA_MAX_AIR, $ticks);
$this->propertyManager->setShort(EntityMetadataProperties::MAX_AIR, $ticks);
}
/**

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
class Villager extends Creature implements NPC, Ageable{
public const PROFESSION_FARMER = 0;
@ -67,14 +69,14 @@ class Villager extends Creature implements NPC, Ageable{
* @param int $profession
*/
public function setProfession(int $profession) : void{
$this->propertyManager->setInt(self::DATA_VARIANT, $profession);
$this->propertyManager->setInt(EntityMetadataProperties::VARIANT, $profession);
}
public function getProfession() : int{
return $this->propertyManager->getInt(self::DATA_VARIANT);
return $this->propertyManager->getInt(EntityMetadataProperties::VARIANT);
}
public function isBaby() : bool{
return $this->getGenericFlag(self::DATA_FLAG_BABY);
return $this->getGenericFlag(EntityMetadataFlags::BABY);
}
}

View File

@ -24,11 +24,12 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
abstract class WaterAnimal extends Creature implements Ageable{
public function isBaby() : bool{
return $this->getGenericFlag(self::DATA_FLAG_BABY);
return $this->getGenericFlag(EntityMetadataFlags::BABY);
}
public function canBreathe() : bool{

View File

@ -28,6 +28,7 @@ use pocketmine\entity\Human;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\Player;
use function sqrt;
@ -132,14 +133,14 @@ class ExperienceOrb extends Entity{
}
public function getXpValue() : int{
return $this->propertyManager->getInt(self::DATA_EXPERIENCE_VALUE) ?? 0;
return $this->propertyManager->getInt(EntityMetadataProperties::EXPERIENCE_VALUE) ?? 0;
}
public function setXpValue(int $amount) : void{
if($amount <= 0){
throw new \InvalidArgumentException("XP amount must be greater than 0, got $amount");
}
$this->propertyManager->setInt(self::DATA_EXPERIENCE_VALUE, $amount);
$this->propertyManager->setInt(EntityMetadataProperties::EXPERIENCE_VALUE, $amount);
}
public function hasTargetPlayer() : bool{

View File

@ -32,6 +32,7 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use function get_class;
class FallingBlock extends Entity{
@ -70,7 +71,7 @@ class FallingBlock extends Entity{
$this->block = BlockFactory::get($blockId, $damage);
$this->propertyManager->setInt(self::DATA_VARIANT, $this->block->getRuntimeId());
$this->propertyManager->setInt(EntityMetadataProperties::VARIANT, $this->block->getRuntimeId());
}
public function canCollideWith(Entity $entity) : bool{

View File

@ -31,6 +31,8 @@ use pocketmine\level\Explosion;
use pocketmine\level\sound\IgniteSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
class PrimedTNT extends Entity implements Explosive{
public const NETWORK_ID = self::TNT;
@ -63,8 +65,8 @@ class PrimedTNT extends Entity implements Explosive{
$this->fuse = 80;
}
$this->setGenericFlag(self::DATA_FLAG_IGNITED, true);
$this->propertyManager->setInt(self::DATA_FUSE_LENGTH, $this->fuse);
$this->setGenericFlag(EntityMetadataFlags::IGNITED, true);
$this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
$this->level->addSound($this, new IgniteSound());
}
@ -89,7 +91,7 @@ class PrimedTNT extends Entity implements Explosive{
$hasUpdate = parent::entityBaseTick($tickDiff);
if($this->fuse % 5 === 0){ //don't spam it every tick, it's not necessary
$this->propertyManager->setInt(self::DATA_FUSE_LENGTH, $this->fuse);
$this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
}
if(!$this->isFlaggedForDespawn()){

View File

@ -35,6 +35,7 @@ use pocketmine\math\RayTraceResult;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\Player;
use function mt_rand;
use function sqrt;
@ -86,11 +87,11 @@ class Arrow extends Projectile{
}
public function isCritical() : bool{
return $this->getGenericFlag(self::DATA_FLAG_CRITICAL);
return $this->getGenericFlag(EntityMetadataFlags::CRITICAL);
}
public function setCritical(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CRITICAL, $value);
$this->setGenericFlag(EntityMetadataFlags::CRITICAL, $value);
}
public function getResultDamage() : int{

View File

@ -35,6 +35,8 @@ use pocketmine\item\Potion;
use pocketmine\level\particle\PotionSplashParticle;
use pocketmine\level\sound\PotionSplashSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\utils\Color;
use function round;
use function sqrt;
@ -136,14 +138,14 @@ class SplashPotion extends Throwable{
* @return int
*/
public function getPotionId() : int{
return $this->propertyManager->getShort(self::DATA_POTION_AUX_VALUE) ?? 0;
return $this->propertyManager->getShort(EntityMetadataProperties::POTION_AUX_VALUE) ?? 0;
}
/**
* @param int $id
*/
public function setPotionId(int $id) : void{
$this->propertyManager->setShort(self::DATA_POTION_AUX_VALUE, $id);
$this->propertyManager->setShort(EntityMetadataProperties::POTION_AUX_VALUE, $id);
}
/**
@ -151,7 +153,7 @@ class SplashPotion extends Throwable{
* @return bool
*/
public function willLinger() : bool{
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_LINGER);
return $this->getDataFlag(EntityMetadataProperties::FLAGS, EntityMetadataFlags::LINGER);
}
/**
@ -160,7 +162,7 @@ class SplashPotion extends Throwable{
* @param bool $value
*/
public function setLinger(bool $value = true) : void{
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_LINGER, $value);
$this->setDataFlag(EntityMetadataProperties::FLAGS, EntityMetadataFlags::LINGER, $value);
}
/**

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\entity\Entity;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Skin;
use pocketmine\item\ItemFactory;
@ -31,6 +30,9 @@ use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\utils\UUID;
use function str_repeat;
@ -105,11 +107,11 @@ class FloatingTextParticle implements Particle{
$pk->item = ItemFactory::air();
$flags = (
1 << Entity::DATA_FLAG_IMMOBILE
1 << EntityMetadataFlags::IMMOBILE
);
$pk->metadata = [
Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, $flags],
Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0.01] //zero causes problems on debug builds
EntityMetadataProperties::FLAGS => [EntityMetadataTypes::LONG, $flags],
EntityMetadataProperties::SCALE => [EntityMetadataTypes::FLOAT, 0.01] //zero causes problems on debug builds
];
$p[] = $pk;

View File

@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe;
#include <rules/DataPacket.h>
use pocketmine\entity\Attribute;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
@ -36,6 +35,7 @@ use pocketmine\nbt\TreeRoot;
use pocketmine\network\BadPacketException;
use pocketmine\network\mcpe\protocol\types\CommandOriginData;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream;
use pocketmine\utils\UUID;
@ -177,32 +177,32 @@ class NetworkBinaryStream extends BinaryStream{
$type = $this->getUnsignedVarInt();
$value = null;
switch($type){
case Entity::DATA_TYPE_BYTE:
case EntityMetadataTypes::BYTE:
$value = $this->getByte();
break;
case Entity::DATA_TYPE_SHORT:
case EntityMetadataTypes::SHORT:
$value = $this->getSignedLShort();
break;
case Entity::DATA_TYPE_INT:
case EntityMetadataTypes::INT:
$value = $this->getVarInt();
break;
case Entity::DATA_TYPE_FLOAT:
case EntityMetadataTypes::FLOAT:
$value = $this->getLFloat();
break;
case Entity::DATA_TYPE_STRING:
case EntityMetadataTypes::STRING:
$value = $this->getString();
break;
case Entity::DATA_TYPE_SLOT:
case EntityMetadataTypes::SLOT:
$value = $this->getSlot();
break;
case Entity::DATA_TYPE_POS:
case EntityMetadataTypes::POS:
$value = new Vector3();
$this->getSignedBlockPosition($value->x, $value->y, $value->z);
break;
case Entity::DATA_TYPE_LONG:
case EntityMetadataTypes::LONG:
$value = $this->getVarLong();
break;
case Entity::DATA_TYPE_VECTOR3F:
case EntityMetadataTypes::VECTOR3F:
$value = $this->getVector3();
break;
default:
@ -229,25 +229,25 @@ class NetworkBinaryStream extends BinaryStream{
$this->putUnsignedVarInt($key); //data key
$this->putUnsignedVarInt($d[0]); //data type
switch($d[0]){
case Entity::DATA_TYPE_BYTE:
case EntityMetadataTypes::BYTE:
$this->putByte($d[1]);
break;
case Entity::DATA_TYPE_SHORT:
case EntityMetadataTypes::SHORT:
$this->putLShort($d[1]); //SIGNED short!
break;
case Entity::DATA_TYPE_INT:
case EntityMetadataTypes::INT:
$this->putVarInt($d[1]);
break;
case Entity::DATA_TYPE_FLOAT:
case EntityMetadataTypes::FLOAT:
$this->putLFloat($d[1]);
break;
case Entity::DATA_TYPE_STRING:
case EntityMetadataTypes::STRING:
$this->putString($d[1]);
break;
case Entity::DATA_TYPE_SLOT:
case EntityMetadataTypes::SLOT:
$this->putSlot($d[1]);
break;
case Entity::DATA_TYPE_POS:
case EntityMetadataTypes::POS:
$v = $d[1];
if($v !== null){
$this->putSignedBlockPosition($v->x, $v->y, $v->z);
@ -255,10 +255,10 @@ class NetworkBinaryStream extends BinaryStream{
$this->putSignedBlockPosition(0, 0, 0);
}
break;
case Entity::DATA_TYPE_LONG:
case EntityMetadataTypes::LONG:
$this->putVarLong($d[1]);
break;
case Entity::DATA_TYPE_VECTOR3F:
case EntityMetadataTypes::VECTOR3F:
$this->putVector3Nullable($d[1]);
break;
default:

View File

@ -0,0 +1,120 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
final class EntityMetadataFlags{
private function __construct(){
//NOOP
}
public const ONFIRE = 0;
public const SNEAKING = 1;
public const RIDING = 2;
public const SPRINTING = 3;
public const ACTION = 4;
public const INVISIBLE = 5;
public const TEMPTED = 6;
public const INLOVE = 7;
public const SADDLED = 8;
public const POWERED = 9;
public const IGNITED = 10;
public const BABY = 11;
public const CONVERTING = 12;
public const CRITICAL = 13;
public const CAN_SHOW_NAMETAG = 14;
public const ALWAYS_SHOW_NAMETAG = 15;
public const IMMOBILE = 16, NO_AI = 16;
public const SILENT = 17;
public const WALLCLIMBING = 18;
public const CAN_CLIMB = 19;
public const SWIMMER = 20;
public const CAN_FLY = 21;
public const WALKER = 22;
public const RESTING = 23;
public const SITTING = 24;
public const ANGRY = 25;
public const INTERESTED = 26;
public const CHARGED = 27;
public const TAMED = 28;
public const ORPHANED = 29;
public const LEASHED = 30;
public const SHEARED = 31;
public const GLIDING = 32;
public const ELDER = 33;
public const MOVING = 34;
public const BREATHING = 35;
public const CHESTED = 36;
public const STACKABLE = 37;
public const SHOWBASE = 38;
public const REARING = 39;
public const VIBRATING = 40;
public const IDLING = 41;
public const EVOKER_SPELL = 42;
public const CHARGE_ATTACK = 43;
public const WASD_CONTROLLED = 44;
public const CAN_POWER_JUMP = 45;
public const LINGER = 46;
public const HAS_COLLISION = 47;
public const AFFECTED_BY_GRAVITY = 48;
public const FIRE_IMMUNE = 49;
public const DANCING = 50;
public const ENCHANTED = 51;
public const SHOW_TRIDENT_ROPE = 52; // tridents show an animated rope when enchanted with loyalty after they are thrown and return to their owner. To be combined with DATA_OWNER_EID
public const CONTAINER_PRIVATE = 53; //inventory is private, doesn't drop contents when killed if true
public const TRANSFORMING = 54;
public const SPIN_ATTACK = 55;
public const SWIMMING = 56;
public const BRIBED = 57; //dolphins have this set when they go to find treasure for the player
public const PREGNANT = 58;
public const LAYING_EGG = 59;
public const RIDER_CAN_PICK = 60; //???
public const TRANSITION_SITTING = 61;
public const EATING = 62;
public const LAYING_DOWN = 63;
public const SNEEZING = 64;
public const TRUSTING = 65;
public const ROLLING = 66;
public const SCARED = 67;
public const IN_SCAFFOLDING = 68;
public const OVER_SCAFFOLDING = 69;
public const FALL_THROUGH_SCAFFOLDING = 70;
public const BLOCKING = 71; //shield
public const DISABLE_BLOCKING = 72;
//73 is set when a player is attacked while using shield, unclear on purpose
//74 related to shield usage, needs further investigation
public const SLEEPING = 75;
//76 related to sleeping, unclear usage
public const TRADE_INTEREST = 77;
public const DOOR_BREAKER = 78; //...
public const BREAKING_OBSTRUCTION = 79;
public const DOOR_OPENER = 80; //...
public const ILLAGER_CAPTAIN = 81;
public const STUNNED = 82;
public const ROARING = 83;
public const DELAYED_ATTACKING = 84;
public const AVOIDING_MOBS = 85;
//86 used by RangedAttackGoal
//87 used by NearestAttackableTargetGoal
}

View File

@ -0,0 +1,143 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
final class EntityMetadataProperties{
private function __construct(){
//NOOP
}
/*
* Readers beware: this isn't a nice list. Some of the properties have different types for different entities, and
* are used for entirely different things.
*/
public const FLAGS = 0;
public const HEALTH = 1; //int (minecart/boat)
public const VARIANT = 2; //int
public const COLOR = 3, COLOUR = 3; //byte
public const NAMETAG = 4; //string
public const OWNER_EID = 5; //long
public const TARGET_EID = 6; //long
public const AIR = 7; //short
public const POTION_COLOR = 8; //int (ARGB!)
public const POTION_AMBIENT = 9; //byte
/* 10 (byte) */
public const HURT_TIME = 11; //int (minecart/boat)
public const HURT_DIRECTION = 12; //int (minecart/boat)
public const PADDLE_TIME_LEFT = 13; //float
public const PADDLE_TIME_RIGHT = 14; //float
public const EXPERIENCE_VALUE = 15; //int (xp orb)
public const MINECART_DISPLAY_BLOCK = 16; //int (id | (data << 16))
public const HORSE_FLAGS = 16; //int
/* 16 (byte) used by wither skull */
public const MINECART_DISPLAY_OFFSET = 17; //int
public const SHOOTER_ID = 17; //long (used by arrows)
public const MINECART_HAS_DISPLAY = 18; //byte (must be 1 for minecart to show block inside)
public const HORSE_TYPE = 19; //byte
/* 20 (unknown)
* 21 (unknown) */
public const CHARGE_AMOUNT = 22; //int8, used for ghasts and also crossbow charging
public const ENDERMAN_HELD_ITEM_ID = 23; //short
public const ENTITY_AGE = 24; //short
/* 25 (int) used by horse, (byte) used by witch */
public const PLAYER_FLAGS = 26; //byte
public const PLAYER_INDEX = 27; //int, used for marker colours and agent nametag colours
public const PLAYER_BED_POSITION = 28; //blockpos
public const FIREBALL_POWER_X = 29; //float
public const FIREBALL_POWER_Y = 30;
public const FIREBALL_POWER_Z = 31;
/* 32 (unknown)
* 33 (float) fishing bobber
* 34 (float) fishing bobber
* 35 (float) fishing bobber */
public const POTION_AUX_VALUE = 36; //short
public const LEAD_HOLDER_EID = 37; //long
public const SCALE = 38; //float
public const HAS_NPC_COMPONENT = 39; //byte (???)
public const SKIN_ID = 40; //string
public const NPC_SKIN_ID = 41; //string
public const URL_TAG = 42; //string
public const MAX_AIR = 43; //short
public const MARK_VARIANT = 44; //int
public const CONTAINER_TYPE = 45; //byte (ContainerComponent)
public const CONTAINER_BASE_SIZE = 46; //int (ContainerComponent)
public const CONTAINER_EXTRA_SLOTS_PER_STRENGTH = 47; //int (used for llamas, inventory size is baseSize + thisProp * strength)
public const BLOCK_TARGET = 48; //block coords (ender crystal)
public const WITHER_INVULNERABLE_TICKS = 49; //int
public const WITHER_TARGET_1 = 50; //long
public const WITHER_TARGET_2 = 51; //long
public const WITHER_TARGET_3 = 52; //long
/* 53 (short) */
public const BOUNDING_BOX_WIDTH = 54; //float
public const BOUNDING_BOX_HEIGHT = 55; //float
public const FUSE_LENGTH = 56; //int
public const RIDER_SEAT_POSITION = 57; //vector3f
public const RIDER_ROTATION_LOCKED = 58; //byte
public const RIDER_MAX_ROTATION = 59; //float
public const RIDER_MIN_ROTATION = 60; //float
public const AREA_EFFECT_CLOUD_RADIUS = 61; //float
public const AREA_EFFECT_CLOUD_WAITING = 62; //int
public const AREA_EFFECT_CLOUD_PARTICLE_ID = 63; //int
/* 64 (int) shulker-related */
public const SHULKER_ATTACH_FACE = 65; //byte
/* 66 (short) shulker-related */
public const SHULKER_ATTACH_POS = 67; //block coords
public const TRADING_PLAYER_EID = 68; //long
/* 70 (byte) command-block */
public const COMMAND_BLOCK_COMMAND = 71; //string
public const COMMAND_BLOCK_LAST_OUTPUT = 72; //string
public const COMMAND_BLOCK_TRACK_OUTPUT = 73; //byte
public const CONTROLLING_RIDER_SEAT_NUMBER = 74; //byte
public const STRENGTH = 75; //int
public const MAX_STRENGTH = 76; //int
/* 77 (int) */
public const LIMITED_LIFE = 78;
public const ARMOR_STAND_POSE_INDEX = 79; //int
public const ENDER_CRYSTAL_TIME_OFFSET = 80; //int
public const ALWAYS_SHOW_NAMETAG = 81; //byte: -1 = default, 0 = only when looked at, 1 = always
public const COLOR_2 = 82; //byte
/* 83 (unknown) */
public const SCORE_TAG = 84; //string
public const BALLOON_ATTACHED_ENTITY = 85; //int64, entity unique ID of owner
public const PUFFERFISH_SIZE = 86; //byte
public const BOAT_BUBBLE_TIME = 87; //int (time in bubble column)
public const PLAYER_AGENT_EID = 88; //long
/* 89 (float) related to panda sitting
* 90 (float) related to panda sitting */
public const EAT_COUNTER = 91; //int (used by pandas)
public const FLAGS2 = 92; //long (extended data flags)
/* 93 (float) related to panda lying down
* 94 (float) related to panda lying down */
public const AREA_EFFECT_CLOUD_DURATION = 95; //int
public const AREA_EFFECT_CLOUD_SPAWN_TIME = 96; //int
public const AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 97; //float, usually negative
public const AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 98; //float
public const AREA_EFFECT_CLOUD_PICKUP_COUNT = 99; //int
public const INTERACTIVE_TAG = 100; //string (button text)
public const TRADE_TIER = 101; //int
public const MAX_TRADE_TIER = 102; //int
public const TRADE_XP = 103; //int
}

View File

@ -0,0 +1,41 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
final class EntityMetadataTypes{
private function __construct(){
//NOOP
}
public const BYTE = 0;
public const SHORT = 1;
public const INT = 2;
public const FLOAT = 3;
public const STRING = 4;
public const SLOT = 5;
public const POS = 6;
public const LONG = 7;
public const VECTOR3F = 8;
}

View File

@ -0,0 +1,34 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
final class PlayerMetadataFlags{
private function __construct(){
//NOOP
}
public const SLEEP = 1;
public const DEAD = 2; //TODO: CHECK
}