diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8ac2816c2..942329b30 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -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); diff --git a/src/pocketmine/entity/Animal.php b/src/pocketmine/entity/Animal.php index 5474c39ca..d651057e8 100644 --- a/src/pocketmine/entity/Animal.php +++ b/src/pocketmine/entity/Animal.php @@ -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); } } diff --git a/src/pocketmine/entity/DataPropertyManager.php b/src/pocketmine/entity/DataPropertyManager.php index c8646132f..96014e798 100644 --- a/src/pocketmine/entity/DataPropertyManager.php +++ b/src/pocketmine/entity/DataPropertyManager.php @@ -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); } /** diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9eb1d7c15..8cb9d5ab4 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -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); } /** diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 443a1ffe4..f497ac6a3 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -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); } } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 2b07024d9..197dc6840 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -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); } /** diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index 52b0d1bdd..836c817f5 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -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); } } diff --git a/src/pocketmine/entity/WaterAnimal.php b/src/pocketmine/entity/WaterAnimal.php index 4bcc7d3b9..56c846465 100644 --- a/src/pocketmine/entity/WaterAnimal.php +++ b/src/pocketmine/entity/WaterAnimal.php @@ -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{ diff --git a/src/pocketmine/entity/object/ExperienceOrb.php b/src/pocketmine/entity/object/ExperienceOrb.php index 1cb3ad5f9..c0141bae2 100644 --- a/src/pocketmine/entity/object/ExperienceOrb.php +++ b/src/pocketmine/entity/object/ExperienceOrb.php @@ -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{ diff --git a/src/pocketmine/entity/object/FallingBlock.php b/src/pocketmine/entity/object/FallingBlock.php index 4016ceed7..c22e84908 100644 --- a/src/pocketmine/entity/object/FallingBlock.php +++ b/src/pocketmine/entity/object/FallingBlock.php @@ -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{ diff --git a/src/pocketmine/entity/object/PrimedTNT.php b/src/pocketmine/entity/object/PrimedTNT.php index ec2b2da97..92fc9870b 100644 --- a/src/pocketmine/entity/object/PrimedTNT.php +++ b/src/pocketmine/entity/object/PrimedTNT.php @@ -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()){ diff --git a/src/pocketmine/entity/projectile/Arrow.php b/src/pocketmine/entity/projectile/Arrow.php index dda7b9217..e20c679a6 100644 --- a/src/pocketmine/entity/projectile/Arrow.php +++ b/src/pocketmine/entity/projectile/Arrow.php @@ -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{ diff --git a/src/pocketmine/entity/projectile/SplashPotion.php b/src/pocketmine/entity/projectile/SplashPotion.php index 0fb687d6a..5c74c7569 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -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); } /** diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index e800a1c74..1eef46fd8 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -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; diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index b0d75682a..cbc0d75ee 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe; #include 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: diff --git a/src/pocketmine/network/mcpe/protocol/types/EntityMetadataFlags.php b/src/pocketmine/network/mcpe/protocol/types/EntityMetadataFlags.php new file mode 100644 index 000000000..566cf5ae1 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/EntityMetadataFlags.php @@ -0,0 +1,120 @@ +