diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 310bbe17a..c66b980b4 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1147,7 +1147,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sleeping = clone $pos; $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]); - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, true); $this->setSpawn($pos); @@ -1188,7 +1188,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sleeping = null; $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]); - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false); $this->level->sleepTicks = 0; @@ -2166,7 +2166,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->craftingType = 0; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); //TODO: check if this should be true + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); //TODO: check if this should be true switch($packet->event){ case EntityEventPacket::USE_ITEM: //Eating @@ -2218,7 +2218,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->inventory->equipItem($packet->hotbarSlot, $packet->inventorySlot); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } @@ -2387,7 +2387,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->craftingType = 0; if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){ }elseif($this->isCreative()){ @@ -2482,7 +2482,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, true); + $this->setGenericFlag(self::DATA_FLAG_ACTION, true); $this->startAction = $this->server->getTick(); } @@ -2532,7 +2532,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); break; case PlayerActionPacket::ACTION_RELEASE_ITEM: - if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ + if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){ if($this->inventory->getItemInHand()->getId() === Item::BOW){ $bow = $this->inventory->getItemInHand(); if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ @@ -2728,7 +2728,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->startAction = -1; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } @@ -2774,7 +2774,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } diff --git a/src/pocketmine/entity/Animal.php b/src/pocketmine/entity/Animal.php index d8c502a41..9cd4e86f7 100644 --- a/src/pocketmine/entity/Animal.php +++ b/src/pocketmine/entity/Animal.php @@ -27,6 +27,6 @@ namespace pocketmine\entity; abstract class Animal extends Creature implements Ageable{ public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } } \ No newline at end of file diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index d79963a76..2580c1c87 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -46,11 +46,11 @@ class Arrow extends Projectile{ } public function isCritical() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CRITICAL); + return $this->getGenericFlag(self::DATA_FLAG_CRITICAL); } public function setCritical(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CRITICAL, $value); + $this->setGenericFlag(self::DATA_FLAG_CRITICAL, $value); } public function getResultDamage() : int{ diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 36675effc..1241c5b34 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -422,7 +422,7 @@ class Effect{ switch($this->id){ case Effect::INVISIBILITY: - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); + $entity->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, true); $entity->setNameTagVisible(false); break; case Effect::SPEED: @@ -487,7 +487,7 @@ class Effect{ switch($this->id){ case Effect::INVISIBILITY: - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); + $entity->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, false); $entity->setNameTagVisible(true); break; case Effect::SPEED: diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9220e4ad2..1648539ce 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -453,14 +453,14 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function isNameTagVisible() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG); + return $this->getGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG); } /** * @return bool */ public function isNameTagAlwaysVisible() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG); + return $this->getGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG); } @@ -475,14 +475,14 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setNameTagVisible(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); + $this->setGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); } /** * @param bool $value */ public function setNameTagAlwaysVisible(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); + $this->setGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); } /** @@ -521,31 +521,31 @@ abstract class Entity extends Location implements Metadatable{ public function isSneaking() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING); + return $this->getGenericFlag(self::DATA_FLAG_SNEAKING); } public function setSneaking(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, $value); + $this->setGenericFlag(self::DATA_FLAG_SNEAKING, $value); } public function isSprinting() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING); + return $this->getGenericFlag(self::DATA_FLAG_SPRINTING); } public function setSprinting(bool $value = true){ if($value !== $this->isSprinting()){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, $value); + $this->setGenericFlag(self::DATA_FLAG_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->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE); + return $this->getGenericFlag(self::DATA_FLAG_IMMOBILE); } public function setImmobile(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value); + $this->setGenericFlag(self::DATA_FLAG_IMMOBILE, $value); } /** @@ -553,7 +553,7 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function canClimb() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB); + return $this->getGenericFlag(self::DATA_FLAG_CAN_CLIMB); } /** @@ -561,7 +561,7 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setCanClimb(bool $value){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB, $value); + $this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value); } /** @@ -570,7 +570,7 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function canClimbWalls() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING); + return $this->getGenericFlag(self::DATA_FLAG_WALLCLIMBING); } /** @@ -579,7 +579,7 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setCanClimbWalls(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING, $value); + $this->setGenericFlag(self::DATA_FLAG_WALLCLIMBING, $value); } /** @@ -1266,12 +1266,12 @@ abstract class Entity extends Location implements Metadatable{ $this->fireTicks = $ticks; } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, true); + $this->setGenericFlag(self::DATA_FLAG_ONFIRE, true); } public function extinguish(){ $this->fireTicks = 0; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, false); + $this->setGenericFlag(self::DATA_FLAG_ONFIRE, false); } public function isFireProof() : bool{ @@ -1930,6 +1930,26 @@ abstract class Entity extends Location implements Metadatable{ return (((int) $this->getDataProperty($propertyId)) & (1 << $flagId)) > 0; } + /** + * Wrapper around {@link Entity#getDataFlag} for generic data flag reading. + * + * @param int $flagId + * @return bool + */ + public function getGenericFlag(int $flagId) : bool{ + return $this->getDataFlag(self::DATA_FLAGS, $flagId); + } + + /** + * Wrapper around {@link Entity#setDataFlag} for generic data flag setting. + * + * @param int $flagId + * @param bool $value + */ + public function setGenericFlag(int $flagId, bool $value = true){ + $this->setDataFlag(self::DATA_FLAGS, $flagId, $value, self::DATA_TYPE_LONG); + } + public function __destruct(){ $this->close(); } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index b4b87d5f8..db36c093c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -283,7 +283,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ protected function initEntity(){ - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false); $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false); $this->inventory = new PlayerInventory($this); @@ -542,4 +542,24 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ parent::close(); } } + + /** + * Wrapper around {@link Entity#getDataFlag} for player-specific data flag reading. + * + * @param int $flagId + * @return bool + */ + public function getPlayerFlag(int $flagId){ + return $this->getDataFlag(self::DATA_PLAYER_FLAGS, $flagId); + } + + /** + * Wrapper around {@link Entity#setDataFlag} for player-specific data flag setting. + * + * @param int $flagId + * @param bool $value + */ + public function setPlayerFlag(int $flagId, bool $value = true){ + $this->setDataFlag(self::DATA_PLAYER_FLAGS, $flagId, $value, self::DATA_TYPE_BYTE); + } } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 6447f463e..11b9b4cb7 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -418,7 +418,7 @@ abstract class Living extends Entity implements Damageable{ public function entityBaseTick(int $tickDiff = 1) : bool{ Timings::$timerLivingEntityBaseTick->startTiming(); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BREATHING, !$this->isInsideOfWater()); + $this->setGenericFlag(self::DATA_FLAG_BREATHING, !$this->isInsideOfWater()); $hasUpdate = parent::entityBaseTick($tickDiff); diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 4cc7e233d..b88f62234 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -63,7 +63,7 @@ class PrimedTNT extends Entity implements Explosive{ $this->fuse = 80; } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IGNITED, true); + $this->setGenericFlag(self::DATA_FLAG_IGNITED, true); $this->setDataProperty(self::DATA_FUSE_LENGTH, self::DATA_TYPE_INT, $this->fuse); $this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_SOUND_IGNITE); diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index 910922195..3bd32d0c0 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -84,6 +84,6 @@ class Villager extends Creature implements NPC, Ageable{ } public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } } diff --git a/src/pocketmine/entity/WaterAnimal.php b/src/pocketmine/entity/WaterAnimal.php index 6f4e3f4a8..eb1452c5a 100644 --- a/src/pocketmine/entity/WaterAnimal.php +++ b/src/pocketmine/entity/WaterAnimal.php @@ -26,6 +26,6 @@ namespace pocketmine\entity; abstract class WaterAnimal extends Creature implements Ageable{ public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } }