From 015c668885a0f63cb041569441d6040c40f2694b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 16 May 2023 14:07:06 +0100 Subject: [PATCH] Change confusing 'type data' and 'state data' terminology for blocks and items For blocks, we now use 'block-item state' and 'block-only state', which should be much clearer for people implementing custom stuff. 'block-item state', as the name suggests, sticks to the item when the block is acquired as an item. 'block-only state' applies only to the block and is discarded when the block is acquired as an item. 'type data' for items was also renamed, since 'type' is too ambiguous to be anything but super confusing. --- src/block/Anvil.php | 4 +- src/block/Bamboo.php | 2 +- src/block/BambooSapling.php | 2 +- src/block/Barrel.php | 2 +- src/block/Bed.php | 2 +- src/block/Bedrock.php | 2 +- src/block/Bell.php | 2 +- src/block/Block.php | 115 +++++++++--------- src/block/BrewingStand.php | 2 +- src/block/Button.php | 2 +- src/block/Cactus.php | 2 +- src/block/Cake.php | 2 +- src/block/Candle.php | 4 +- src/block/CaveVines.php | 2 +- src/block/ChorusFlower.php | 2 +- src/block/CocoaBlock.php | 2 +- src/block/Crops.php | 2 +- src/block/DaylightSensor.php | 2 +- src/block/DetectorRail.php | 4 +- src/block/Dirt.php | 2 +- src/block/Door.php | 2 +- src/block/DoublePlant.php | 2 +- src/block/EndPortalFrame.php | 2 +- src/block/Farmland.php | 2 +- src/block/FenceGate.php | 2 +- src/block/FillableCauldron.php | 2 +- src/block/Fire.php | 2 +- src/block/FloorCoralFan.php | 2 +- src/block/Froglight.php | 2 +- src/block/FrostedIce.php | 2 +- src/block/Furnace.php | 2 +- src/block/Hopper.php | 2 +- src/block/ItemFrame.php | 2 +- src/block/Lantern.php | 2 +- src/block/Leaves.php | 2 +- src/block/Lectern.php | 2 +- src/block/Lever.php | 2 +- src/block/Light.php | 2 +- src/block/Liquid.php | 2 +- src/block/NetherPortal.php | 2 +- src/block/NetherVines.php | 2 +- src/block/NetherWartPlant.php | 2 +- src/block/Rail.php | 2 +- src/block/RedMushroomBlock.php | 2 +- src/block/RedstoneComparator.php | 2 +- src/block/RedstoneLamp.php | 2 +- src/block/RedstoneOre.php | 2 +- src/block/RedstoneRepeater.php | 2 +- src/block/RedstoneTorch.php | 4 +- src/block/Sapling.php | 2 +- src/block/SeaPickle.php | 2 +- src/block/ShulkerBox.php | 2 +- src/block/SimplePressurePlate.php | 2 +- src/block/Skull.php | 4 +- src/block/Slab.php | 2 +- src/block/SnowLayer.php | 2 +- src/block/Sponge.php | 2 +- src/block/Stair.php | 2 +- src/block/StraightOnlyRail.php | 2 +- src/block/Sugarcane.php | 2 +- src/block/SweetBerryBush.php | 2 +- src/block/TNT.php | 4 +- src/block/Torch.php | 2 +- src/block/Trapdoor.php | 2 +- src/block/Tripwire.php | 2 +- src/block/TripwireHook.php | 2 +- src/block/UnknownBlock.php | 2 +- src/block/Vine.php | 2 +- src/block/Wall.php | 2 +- src/block/WallCoralFan.php | 2 +- src/block/Wood.php | 2 +- .../AnalogRedstoneSignalEmitterTrait.php | 2 +- src/block/utils/AnyFacingTrait.php | 2 +- src/block/utils/CandleTrait.php | 2 +- src/block/utils/ColoredTrait.php | 4 +- src/block/utils/CopperTrait.php | 2 +- src/block/utils/CoralTypeTrait.php | 4 +- src/block/utils/HorizontalFacingTrait.php | 2 +- src/block/utils/PillarRotationTrait.php | 2 +- .../utils/RailPoweredByRedstoneTrait.php | 4 +- src/block/utils/SignLikeRotationTrait.php | 2 +- src/crafting/CraftingManager.php | 8 +- src/crafting/FurnaceRecipeManager.php | 2 +- src/item/Banner.php | 2 +- src/item/CoralFan.php | 4 +- src/item/Dye.php | 2 +- src/item/Item.php | 14 ++- src/item/ItemBlock.php | 4 +- src/item/Medicine.php | 2 +- src/item/Potion.php | 2 +- src/item/SplashPotion.php | 2 +- src/item/StringToItemParser.php | 4 +- src/item/SuspiciousStew.php | 2 +- src/network/mcpe/convert/TypeConverter.php | 2 +- src/player/Player.php | 6 +- 95 files changed, 178 insertions(+), 171 deletions(-) diff --git a/src/block/Anvil.php b/src/block/Anvil.php index ee8b25e38..de8b6d33c 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -51,11 +51,11 @@ class Anvil extends Transparent implements Fallable{ private int $damage = self::UNDAMAGED; - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->damage); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index dae857206..980f4382d 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -55,7 +55,7 @@ class Bamboo extends Transparent{ protected bool $ready = false; protected int $leafSize = self::NO_LEAVES; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES, $this->leafSize); $w->bool($this->thick); $w->bool($this->ready); diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index cfa81519b..6be42546a 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction; final class BambooSapling extends Flowable{ private bool $ready = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->ready); } diff --git a/src/block/Barrel.php b/src/block/Barrel.php index 68eda5331..1dce2376b 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -38,7 +38,7 @@ class Barrel extends Opaque{ protected bool $open = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->open); } diff --git a/src/block/Bed.php b/src/block/Bed.php index 678c8a542..13b466026 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -53,7 +53,7 @@ class Bed extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->occupied); $w->bool($this->head); diff --git a/src/block/Bedrock.php b/src/block/Bedrock.php index 4bca83305..e56898691 100644 --- a/src/block/Bedrock.php +++ b/src/block/Bedrock.php @@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class Bedrock extends Opaque{ private bool $burnsForever = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->burnsForever); } diff --git a/src/block/Bell.php b/src/block/Bell.php index f20a031c2..753d6453d 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -48,7 +48,7 @@ final class Bell extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bellAttachmentType($this->attachmentType); $w->horizontalFacing($this->facing); } diff --git a/src/block/Block.php b/src/block/Block.php index bb2224723..bc76bf952 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -66,9 +66,9 @@ class Block{ /** @var AxisAlignedBB[]|null */ protected ?array $collisionBoxes = null; - private int $requiredTypeDataBits; - private int $requiredStateDataBits; - private int $defaultStateData; + private int $requiredBlockItemStateDataBits; + private int $requiredBlockOnlyStateDataBits; + private int $defaultBlockOnlyStateData; /** * @param string $name English name of the block type (TODO: implement translations) @@ -80,14 +80,14 @@ class Block{ $this->position = new Position(0, 0, 0, null); $calculator = new RuntimeDataSizeCalculator(); - $this->describeType($calculator); - $this->requiredTypeDataBits = $calculator->getBitsUsed(); + $this->describeBlockItemState($calculator); + $this->requiredBlockItemStateDataBits = $calculator->getBitsUsed(); $calculator = new RuntimeDataSizeCalculator(); - $this->describeState($calculator); - $this->requiredStateDataBits = $calculator->getBitsUsed(); + $this->describeBlockOnlyState($calculator); + $this->requiredBlockOnlyStateDataBits = $calculator->getBitsUsed(); - $this->defaultStateData = $this->computeStateData(); + $this->defaultBlockOnlyStateData = $this->encodeBlockOnlyState(); } public function __clone(){ @@ -111,10 +111,10 @@ class Block{ /** * Returns a type ID that identifies this type of block. This allows comparing basic block types, e.g. wool, stone, - * glass, etc. + * glass, etc. Type ID will not change for a given block type. * - * This does **NOT** include information like facing, open/closed, powered/unpowered, colour, etc. This means that, - * for example, red wool and green wool have the same type ID. + * Information such as colour, powered, open/closed, etc. is **not** included in this ID. + * If you want to get a state ID that includes this information, use {@link Block::getStateId()} instead. * * @see BlockTypeIds */ @@ -129,21 +129,22 @@ class Block{ * blocks in chunks at runtime. * * This usually encodes all properties of the block, such as facing, open/closed, powered/unpowered, colour, etc. - * However, some blocks (such as signs and chests) may store additional properties in an associated "tile" if they + * State ID may change depending on the properties of the block (e.g. a torch facing east will have a different + * state ID to one facing west). + * + * Some blocks (such as signs and chests) may store additional properties in an associated "tile" if they * have too many possible values to be encoded into the state ID. These extra properties are **NOT** included in * this function's result. * - * This ID can be used to later obtain a copy of this block using {@link RuntimeBlockStateRegistry::fromStateId()}. + * This ID can be used to later obtain a copy of the block with the same state properties by using + * {@link RuntimeBlockStateRegistry::fromStateId()}. */ public function getStateId() : int{ - return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->computeTypeAndStateData(); + return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->encodeFullState(); } /** - * Returns whether the given block has an equivalent type to this one. This compares the type IDs. - * - * Type properties (e.g. colour, skull type, etc.) are not compared. This means that different colours of wool, - * concrete, etc. will all be considered as having the same type. + * Returns whether the given block has the same type ID as this one. */ public function hasSameTypeId(Block $other) : bool{ return $this->getTypeId() === $other->getTypeId(); @@ -151,6 +152,8 @@ class Block{ /** * Returns whether the given block has the same type and properties as this block. + * + * Note: Tile data (e.g. sign text, chest contents) are not compared here. */ public function isSameState(Block $other) : bool{ return $this->getStateId() === $other->getStateId(); @@ -177,69 +180,69 @@ class Block{ /** * Returns the block as an item. - * State information such as facing, powered/unpowered, open/closed, etc., is discarded. - * Type information such as colour, wood type, etc. is preserved. + * Block-only state such as facing, powered/unpowered, open/closed, etc., is discarded. + * Block-item state such as colour, wood type, etc. is preserved. */ public function asItem() : Item{ $normalized = clone $this; - $normalized->decodeStateData($this->defaultStateData); + $normalized->decodeBlockOnlyState($this->defaultBlockOnlyStateData); return new ItemBlock($normalized); } - private function decodeTypeData(int $data) : void{ - $reader = new RuntimeDataReader($this->requiredTypeDataBits, $data); + private function decodeBlockItemState(int $data) : void{ + $reader = new RuntimeDataReader($this->requiredBlockItemStateDataBits, $data); - $this->describeType($reader); + $this->describeBlockItemState($reader); $readBits = $reader->getOffset(); - if($this->requiredTypeDataBits !== $readBits){ - throw new \LogicException(get_class($this) . ": Exactly $this->requiredTypeDataBits bits of type data were provided, but $readBits were read"); + if($this->requiredBlockItemStateDataBits !== $readBits){ + throw new \LogicException(get_class($this) . ": Exactly $this->requiredBlockItemStateDataBits bits of block-item state data were provided, but $readBits were read"); } } - private function decodeStateData(int $data) : void{ - $reader = new RuntimeDataReader($this->requiredStateDataBits, $data); + private function decodeBlockOnlyState(int $data) : void{ + $reader = new RuntimeDataReader($this->requiredBlockOnlyStateDataBits, $data); - $this->describeState($reader); + $this->describeBlockOnlyState($reader); $readBits = $reader->getOffset(); - if($this->requiredStateDataBits !== $readBits){ - throw new \LogicException(get_class($this) . ": Exactly $this->requiredStateDataBits bits of state data were provided, but $readBits were read"); + if($this->requiredBlockOnlyStateDataBits !== $readBits){ + throw new \LogicException(get_class($this) . ": Exactly $this->requiredBlockOnlyStateDataBits bits of block-only state data were provided, but $readBits were read"); } } - private function decodeTypeAndStateData(int $data) : void{ - $reader = new RuntimeDataReader($this->requiredTypeDataBits + $this->requiredStateDataBits, $data); - $this->decodeTypeData($reader->readInt($this->requiredTypeDataBits)); - $this->decodeStateData($reader->readInt($this->requiredStateDataBits)); + private function decodeFullState(int $data) : void{ + $reader = new RuntimeDataReader($this->requiredBlockItemStateDataBits + $this->requiredBlockOnlyStateDataBits, $data); + $this->decodeBlockItemState($reader->readInt($this->requiredBlockItemStateDataBits)); + $this->decodeBlockOnlyState($reader->readInt($this->requiredBlockOnlyStateDataBits)); } - private function computeTypeData() : int{ - $writer = new RuntimeDataWriter($this->requiredTypeDataBits); + private function encodeBlockItemState() : int{ + $writer = new RuntimeDataWriter($this->requiredBlockItemStateDataBits); - $this->describeType($writer); + $this->describeBlockItemState($writer); $writtenBits = $writer->getOffset(); - if($this->requiredTypeDataBits !== $writtenBits){ - throw new \LogicException(get_class($this) . ": Exactly $this->requiredTypeDataBits bits of type data were expected, but $writtenBits were written"); + if($this->requiredBlockItemStateDataBits !== $writtenBits){ + throw new \LogicException(get_class($this) . ": Exactly $this->requiredBlockItemStateDataBits bits of block-item state data were expected, but $writtenBits were written"); } return $writer->getValue(); } - private function computeStateData() : int{ - $writer = new RuntimeDataWriter($this->requiredStateDataBits); + private function encodeBlockOnlyState() : int{ + $writer = new RuntimeDataWriter($this->requiredBlockOnlyStateDataBits); - $this->describeState($writer); + $this->describeBlockOnlyState($writer); $writtenBits = $writer->getOffset(); - if($this->requiredStateDataBits !== $writtenBits){ - throw new \LogicException(get_class($this) . ": Exactly $this->requiredStateDataBits bits of state data were expected, but $writtenBits were written"); + if($this->requiredBlockOnlyStateDataBits !== $writtenBits){ + throw new \LogicException(get_class($this) . ": Exactly $this->requiredBlockOnlyStateDataBits bits of block-only state data were expected, but $writtenBits were written"); } return $writer->getValue(); } - private function computeTypeAndStateData() : int{ - $writer = new RuntimeDataWriter($this->requiredTypeDataBits + $this->requiredStateDataBits); - $writer->writeInt($this->requiredTypeDataBits, $this->computeTypeData()); - $writer->writeInt($this->requiredStateDataBits, $this->computeStateData()); + private function encodeFullState() : int{ + $writer = new RuntimeDataWriter($this->requiredBlockItemStateDataBits + $this->requiredBlockOnlyStateDataBits); + $writer->writeInt($this->requiredBlockItemStateDataBits, $this->encodeBlockItemState()); + $writer->writeInt($this->requiredBlockOnlyStateDataBits, $this->encodeBlockOnlyState()); return $writer->getValue(); } @@ -252,7 +255,7 @@ class Block{ * The method implementation must NOT use conditional logic to determine which properties are written. It must * always write the same properties in the same order, regardless of the current state of the block. */ - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ //NOOP } @@ -264,7 +267,7 @@ class Block{ * The method implementation must NOT use conditional logic to determine which properties are written. It must * always write the same properties in the same order, regardless of the current state of the block. */ - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ //NOOP } @@ -278,16 +281,16 @@ class Block{ public function generateStatePermutations() : \Generator{ //TODO: this bruteforce approach to discovering all valid states is very inefficient for larger state data sizes //at some point we'll need to find a better way to do this - $bits = $this->requiredTypeDataBits + $this->requiredStateDataBits; + $bits = $this->requiredBlockItemStateDataBits + $this->requiredBlockOnlyStateDataBits; if($bits > Block::INTERNAL_STATE_DATA_BITS){ throw new \LogicException("Block state data cannot use more than " . Block::INTERNAL_STATE_DATA_BITS . " bits"); } for($stateData = 0; $stateData < (1 << $bits); ++$stateData){ $v = clone $this; try{ - $v->decodeTypeAndStateData($stateData); - if($v->computeTypeAndStateData() !== $stateData){ - throw new \LogicException(static::class . "::decodeStateData() accepts invalid state data (returned " . $v->computeTypeAndStateData() . " for input $stateData)"); + $v->decodeFullState($stateData); + if($v->encodeFullState() !== $stateData){ + throw new \LogicException(static::class . "::decodeStateData() accepts invalid state data (returned " . $v->encodeFullState() . " for input $stateData)"); } }catch(InvalidSerializedRuntimeDataException){ //invalid property combination, leave it continue; @@ -732,7 +735,7 @@ class Block{ * @return string */ public function __toString(){ - return "Block[" . $this->getName() . "] (" . $this->getTypeId() . ":" . $this->computeTypeAndStateData() . ")"; + return "Block[" . $this->getName() . "] (" . $this->getTypeId() . ":" . $this->encodeFullState() . ")"; } /** diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index 479d20739..497d282d7 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -43,7 +43,7 @@ class BrewingStand extends Transparent{ */ protected array $slots = []; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->brewingStandSlots($this->slots); } diff --git a/src/block/Button.php b/src/block/Button.php index aa6ca8fa0..85d1d3e09 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -38,7 +38,7 @@ abstract class Button extends Flowable{ protected bool $pressed = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->pressed); } diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 3563eded7..8fff294f6 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -41,7 +41,7 @@ class Cactus extends Transparent{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/Cake.php b/src/block/Cake.php index 93e51be21..3e26e59b0 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -36,7 +36,7 @@ class Cake extends BaseCake{ protected int $bites = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, 0, self::MAX_BITES, $this->bites); } diff --git a/src/block/Candle.php b/src/block/Candle.php index d95815222..5936a0812 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -37,7 +37,7 @@ use pocketmine\world\BlockTransaction; class Candle extends Transparent{ use CandleTrait { - describeState as encodeLitState; + describeBlockOnlyState as encodeLitState; getLightLevel as getBaseLightLevel; } @@ -46,7 +46,7 @@ class Candle extends Transparent{ private int $count = self::MIN_COUNT; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $this->encodeLitState($w); $w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count); } diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 43109192b..55f73fb65 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -44,7 +44,7 @@ class CaveVines extends Flowable{ protected bool $berries = false; protected bool $head = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(5, 0, self::MAX_AGE, $this->age); $w->bool($this->berries); $w->bool($this->head); diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 2aa65d1f6..5c5077f22 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -49,7 +49,7 @@ final class ChorusFlower extends Flowable{ private int $age = self::MIN_AGE; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, self::MIN_AGE, self::MAX_AGE, $this->age); } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 9aa4157b7..aafce3169 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -46,7 +46,7 @@ class CocoaBlock extends Transparent{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->boundedInt(2, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/Crops.php b/src/block/Crops.php index 1ed62985d..8949e663b 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -38,7 +38,7 @@ abstract class Crops extends Flowable{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index 2a55500c6..e1f78aef5 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -41,7 +41,7 @@ class DaylightSensor extends Transparent{ protected bool $inverted = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, 15, $this->signalStrength); $w->bool($this->inverted); } diff --git a/src/block/DetectorRail.php b/src/block/DetectorRail.php index 8af12276b..3bd791d10 100644 --- a/src/block/DetectorRail.php +++ b/src/block/DetectorRail.php @@ -28,8 +28,8 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class DetectorRail extends StraightOnlyRail{ protected bool $activated = false; - protected function describeState(RuntimeDataDescriber $w) : void{ - parent::describeState($w); + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ + parent::describeBlockOnlyState($w); $w->bool($this->activated); } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 33f3800d7..539454b41 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -45,7 +45,7 @@ class Dirt extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->dirtType($this->dirtType); } diff --git a/src/block/Door.php b/src/block/Door.php index d3a2abfb6..06da8e68b 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -41,7 +41,7 @@ class Door extends Transparent{ protected bool $hingeRight = false; protected bool $open = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->top); $w->bool($this->hingeRight); diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index cb341adad..aab6d5b04 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -33,7 +33,7 @@ use pocketmine\world\BlockTransaction; class DoublePlant extends Flowable{ protected bool $top = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->top); } diff --git a/src/block/EndPortalFrame.php b/src/block/EndPortalFrame.php index 5a6537d4d..08c903f11 100644 --- a/src/block/EndPortalFrame.php +++ b/src/block/EndPortalFrame.php @@ -35,7 +35,7 @@ class EndPortalFrame extends Opaque{ protected bool $eye = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->eye); } diff --git a/src/block/Farmland.php b/src/block/Farmland.php index 3d293fa7e..6fcdcd8bc 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -37,7 +37,7 @@ class Farmland extends Transparent{ protected int $wetness = 0; //"moisture" blockstate property in PC - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, 0, self::MAX_WETNESS, $this->wetness); } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 7ad96d842..c22edabc4 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -42,7 +42,7 @@ class FenceGate extends Transparent{ protected bool $open = false; protected bool $inWall = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->open); $w->bool($this->inWall); diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index b6d9b995e..84705ea9d 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -37,7 +37,7 @@ abstract class FillableCauldron extends Transparent{ private int $fillLevel = self::MIN_FILL_LEVEL; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, self::MIN_FILL_LEVEL, self::MAX_FILL_LEVEL, $this->fillLevel); } diff --git a/src/block/Fire.php b/src/block/Fire.php index 6f4332261..9e485fa61 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -39,7 +39,7 @@ class Fire extends BaseFire{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 173c87a08..efa560467 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -37,7 +37,7 @@ use function rad2deg; final class FloorCoralFan extends BaseCoral{ private int $axis = Axis::X; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } diff --git a/src/block/Froglight.php b/src/block/Froglight.php index dcd14c900..f33fc8261 100644 --- a/src/block/Froglight.php +++ b/src/block/Froglight.php @@ -35,7 +35,7 @@ final class Froglight extends SimplePillar{ parent::__construct($idInfo, $name, $typeInfo); } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->froglightType($this->froglightType); } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 5953ce8ae..ba8c7b536 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -32,7 +32,7 @@ class FrostedIce extends Ice{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/Furnace.php b/src/block/Furnace.php index f830a3835..d943f8cc6 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -46,7 +46,7 @@ class Furnace extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->lit); } diff --git a/src/block/Hopper.php b/src/block/Hopper.php index 778e5c2a1..ea000503c 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -39,7 +39,7 @@ class Hopper extends Transparent{ private int $facing = Facing::DOWN; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::UP); $w->bool($this->powered); } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 94754910f..f14720fe4 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -50,7 +50,7 @@ class ItemFrame extends Flowable{ protected int $itemRotation = 0; protected float $itemDropChance = 1.0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->hasMap); } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index a5d8031dd..bc50c3cb6 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -43,7 +43,7 @@ class Lantern extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->hanging); } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index b83de2dde..62a30a3e8 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -47,7 +47,7 @@ class Leaves extends Transparent{ $this->leavesType = $leavesType; } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->noDecay); $w->bool($this->checkDecay); } diff --git a/src/block/Lectern.php b/src/block/Lectern.php index ae1df8549..a80426acf 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -46,7 +46,7 @@ class Lectern extends Transparent{ protected bool $producingSignal = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->producingSignal); } diff --git a/src/block/Lever.php b/src/block/Lever.php index 284a646d9..5d86ac7d2 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -44,7 +44,7 @@ class Lever extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->leverFacing($this->facing); $w->bool($this->activated); } diff --git a/src/block/Light.php b/src/block/Light.php index 963c00385..239e1c048 100644 --- a/src/block/Light.php +++ b/src/block/Light.php @@ -34,7 +34,7 @@ final class Light extends Flowable{ private int $level = self::MAX_LIGHT_LEVEL; - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL, $this->level); } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index ba04510a0..98f1d5627 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -48,7 +48,7 @@ abstract class Liquid extends Transparent{ protected int $decay = 0; //PC "level" property protected bool $still = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, 0, self::MAX_DECAY, $this->decay); $w->bool($this->falling); $w->bool($this->still); diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index 0c507a166..a2524914a 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -34,7 +34,7 @@ class NetherPortal extends Transparent{ protected int $axis = Axis::X; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index 34ab406c6..adf611785 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -52,7 +52,7 @@ class NetherVines extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(5, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 787b1f5f8..76de2a470 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -37,7 +37,7 @@ class NetherWartPlant extends Flowable{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/Rail.php b/src/block/Rail.php index 12b47e6ea..f516902f0 100644 --- a/src/block/Rail.php +++ b/src/block/Rail.php @@ -34,7 +34,7 @@ class Rail extends BaseRail{ private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->railShape($this->railShape); } diff --git a/src/block/RedMushroomBlock.php b/src/block/RedMushroomBlock.php index 07afbfc21..ecac38e18 100644 --- a/src/block/RedMushroomBlock.php +++ b/src/block/RedMushroomBlock.php @@ -36,7 +36,7 @@ class RedMushroomBlock extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ //these blocks always drop as all-cap, but may exist in other forms in the inventory (particularly creative), //so this information needs to be kept in the type info $w->mushroomBlockType($this->mushroomBlockType); diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index 0f8fee840..2158f1a84 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -44,7 +44,7 @@ class RedstoneComparator extends Flowable{ protected bool $isSubtractMode = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->isSubtractMode); $w->bool($this->powered); diff --git a/src/block/RedstoneLamp.php b/src/block/RedstoneLamp.php index 1d0ff7345..58098c395 100644 --- a/src/block/RedstoneLamp.php +++ b/src/block/RedstoneLamp.php @@ -29,7 +29,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class RedstoneLamp extends Opaque{ use PoweredByRedstoneTrait; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->powered); } diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 13cf84205..74708c2bd 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -33,7 +33,7 @@ use function mt_rand; class RedstoneOre extends Opaque{ protected bool $lit = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->lit); } diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index d1ad17eeb..d4f145238 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -43,7 +43,7 @@ class RedstoneRepeater extends Flowable{ protected int $delay = self::MIN_DELAY; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->boundedInt(2, self::MIN_DELAY, self::MAX_DELAY, $this->delay); $w->bool($this->powered); diff --git a/src/block/RedstoneTorch.php b/src/block/RedstoneTorch.php index f85c6c07a..b30c011d4 100644 --- a/src/block/RedstoneTorch.php +++ b/src/block/RedstoneTorch.php @@ -28,8 +28,8 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class RedstoneTorch extends Torch{ protected bool $lit = true; - protected function describeState(RuntimeDataDescriber $w) : void{ - parent::describeState($w); + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ + parent::describeBlockOnlyState($w); $w->bool($this->lit); } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 73ebfeb1f..b1f255f0d 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -46,7 +46,7 @@ class Sapling extends Flowable{ $this->saplingType = $saplingType; } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->ready); } diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index c2955cbaa..4e667038e 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -38,7 +38,7 @@ class SeaPickle extends Transparent{ protected int $count = self::MIN_COUNT; protected bool $underwater = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count); $w->bool($this->underwater); } diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index e979b09e5..b2f53e0a7 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -34,7 +34,7 @@ use pocketmine\world\BlockTransaction; class ShulkerBox extends Opaque{ use AnyFacingTrait; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ //NOOP - we don't read or write facing here, because the tile persists it } diff --git a/src/block/SimplePressurePlate.php b/src/block/SimplePressurePlate.php index f4ad37ea4..e4278410d 100644 --- a/src/block/SimplePressurePlate.php +++ b/src/block/SimplePressurePlate.php @@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; abstract class SimplePressurePlate extends PressurePlate{ protected bool $pressed = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->pressed); } diff --git a/src/block/Skull.php b/src/block/Skull.php index 926c5cc80..6566da733 100644 --- a/src/block/Skull.php +++ b/src/block/Skull.php @@ -49,11 +49,11 @@ class Skull extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->skullType($this->skullType); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::DOWN); } diff --git a/src/block/Slab.php b/src/block/Slab.php index 265dce695..cbf5dce18 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -41,7 +41,7 @@ class Slab extends Transparent{ parent::__construct($idInfo, $name . " Slab", $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->slabType($this->slabType); } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index ec08620c0..f2425455c 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -46,7 +46,7 @@ class SnowLayer extends Flowable implements Fallable{ protected int $layers = self::MIN_LAYERS; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, self::MIN_LAYERS, self::MAX_LAYERS, $this->layers); } diff --git a/src/block/Sponge.php b/src/block/Sponge.php index 5b283d18b..915c98ee1 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class Sponge extends Opaque{ protected bool $wet = false; - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->bool($this->wet); } diff --git a/src/block/Stair.php b/src/block/Stair.php index 971dbc43a..a20746721 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -46,7 +46,7 @@ class Stair extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->upsideDown); } diff --git a/src/block/StraightOnlyRail.php b/src/block/StraightOnlyRail.php index fe3d19b25..054983dbc 100644 --- a/src/block/StraightOnlyRail.php +++ b/src/block/StraightOnlyRail.php @@ -36,7 +36,7 @@ class StraightOnlyRail extends BaseRail{ private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->straightOnlyRailShape($this->railShape); } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index b71a8e9ea..4cc5989a7 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -38,7 +38,7 @@ class Sugarcane extends Flowable{ protected int $age = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, self::MAX_AGE, $this->age); } diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index 13e710f40..b75a343ec 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -45,7 +45,7 @@ class SweetBerryBush extends Flowable{ protected int $age = self::STAGE_SAPLING; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE, $this->age); } diff --git a/src/block/TNT.php b/src/block/TNT.php index d50028f92..a0256bb67 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -45,11 +45,11 @@ class TNT extends Opaque{ protected bool $unstable = false; //TODO: Usage unclear, seems to be a weird hack in vanilla protected bool $worksUnderwater = false; - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->bool($this->worksUnderwater); } - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->unstable); } diff --git a/src/block/Torch.php b/src/block/Torch.php index b7bc5136f..163c0d115 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -36,7 +36,7 @@ class Torch extends Flowable{ protected int $facing = Facing::UP; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::DOWN); } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 79e3f0e8f..d12a922df 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -40,7 +40,7 @@ class Trapdoor extends Transparent{ protected bool $open = false; protected bool $top = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->top); $w->bool($this->open); diff --git a/src/block/Tripwire.php b/src/block/Tripwire.php index b8b3e732d..2ddad2784 100644 --- a/src/block/Tripwire.php +++ b/src/block/Tripwire.php @@ -33,7 +33,7 @@ class Tripwire extends Flowable{ protected bool $connected = false; protected bool $disarmed = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->triggered); $w->bool($this->suspended); $w->bool($this->connected); diff --git a/src/block/TripwireHook.php b/src/block/TripwireHook.php index 2ad6057b8..325819825 100644 --- a/src/block/TripwireHook.php +++ b/src/block/TripwireHook.php @@ -38,7 +38,7 @@ class TripwireHook extends Flowable{ protected bool $connected = false; protected bool $powered = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->connected); $w->bool($this->powered); diff --git a/src/block/UnknownBlock.php b/src/block/UnknownBlock.php index 4523fd7ec..a8cbd2d40 100644 --- a/src/block/UnknownBlock.php +++ b/src/block/UnknownBlock.php @@ -38,7 +38,7 @@ class UnknownBlock extends Transparent{ $this->stateData = $stateData; } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ //use type instead of state, so we don't lose any information like colour //this might be an improperly registered plugin block $w->int(Block::INTERNAL_STATE_DATA_BITS, $this->stateData); diff --git a/src/block/Vine.php b/src/block/Vine.php index 53d4b1efe..cc516bbca 100644 --- a/src/block/Vine.php +++ b/src/block/Vine.php @@ -39,7 +39,7 @@ class Vine extends Flowable{ /** @var int[] */ protected array $faces = []; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacingFlags($this->faces); } diff --git a/src/block/Wall.php b/src/block/Wall.php index 8b128c525..30584c92b 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -42,7 +42,7 @@ class Wall extends Transparent{ protected array $connections = []; protected bool $post = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->wallConnections($this->connections); $w->bool($this->post); } diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index c7e350c47..432dd5ddb 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction; final class WallCoralFan extends BaseCoral{ use HorizontalFacingTrait; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/Wood.php b/src/block/Wood.php index 3fbae40da..127533b98 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -38,7 +38,7 @@ class Wood extends Opaque{ private bool $stripped = false; - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->bool($this->stripped); } diff --git a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php index 783517dcd..fe61f652c 100644 --- a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php +++ b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php @@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; trait AnalogRedstoneSignalEmitterTrait{ protected int $signalStrength = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, 15, $this->signalStrength); } diff --git a/src/block/utils/AnyFacingTrait.php b/src/block/utils/AnyFacingTrait.php index 78fdd9bf9..4805b7b7c 100644 --- a/src/block/utils/AnyFacingTrait.php +++ b/src/block/utils/AnyFacingTrait.php @@ -29,7 +29,7 @@ use pocketmine\math\Facing; trait AnyFacingTrait{ protected int $facing = Facing::DOWN; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); } diff --git a/src/block/utils/CandleTrait.php b/src/block/utils/CandleTrait.php index 60dd61849..99e164a84 100644 --- a/src/block/utils/CandleTrait.php +++ b/src/block/utils/CandleTrait.php @@ -39,7 +39,7 @@ use pocketmine\world\sound\FlintSteelSound; trait CandleTrait{ private bool $lit = false; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bool($this->lit); } diff --git a/src/block/utils/ColoredTrait.php b/src/block/utils/ColoredTrait.php index b9a14bee1..dab86fb66 100644 --- a/src/block/utils/ColoredTrait.php +++ b/src/block/utils/ColoredTrait.php @@ -30,8 +30,8 @@ trait ColoredTrait{ /** @var DyeColor */ private $color; - /** @see Block::describeType() */ - public function describeType(RuntimeDataDescriber $w) : void{ + /** @see Block::describeBlockItemState() */ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->dyeColor($this->color); } diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index 11c0178f9..5fede94dd 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -44,7 +44,7 @@ trait CopperTrait{ parent::__construct($identifier, $name, $typeInfo); } - public function describeType(RuntimeDataDescriber $w) : void{ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->copperOxidation($this->oxidation); $w->bool($this->waxed); } diff --git a/src/block/utils/CoralTypeTrait.php b/src/block/utils/CoralTypeTrait.php index 4607831c8..5dcd539d4 100644 --- a/src/block/utils/CoralTypeTrait.php +++ b/src/block/utils/CoralTypeTrait.php @@ -30,8 +30,8 @@ trait CoralTypeTrait{ protected CoralType $coralType; protected bool $dead = false; - /** @see Block::describeType() */ - public function describeType(RuntimeDataDescriber $w) : void{ + /** @see Block::describeBlockItemState() */ + public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->coralType($this->coralType); $w->bool($this->dead); } diff --git a/src/block/utils/HorizontalFacingTrait.php b/src/block/utils/HorizontalFacingTrait.php index b1558b154..a5bd6dcf4 100644 --- a/src/block/utils/HorizontalFacingTrait.php +++ b/src/block/utils/HorizontalFacingTrait.php @@ -30,7 +30,7 @@ use pocketmine\math\Facing; trait HorizontalFacingTrait{ protected int $facing = Facing::NORTH; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 0fc206a20..3f0117dec 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -35,7 +35,7 @@ use pocketmine\world\BlockTransaction; trait PillarRotationTrait{ protected int $axis = Axis::Y; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->axis($this->axis); } diff --git a/src/block/utils/RailPoweredByRedstoneTrait.php b/src/block/utils/RailPoweredByRedstoneTrait.php index a95fea253..05384f611 100644 --- a/src/block/utils/RailPoweredByRedstoneTrait.php +++ b/src/block/utils/RailPoweredByRedstoneTrait.php @@ -28,8 +28,8 @@ use pocketmine\data\runtime\RuntimeDataDescriber; trait RailPoweredByRedstoneTrait{ use PoweredByRedstoneTrait; - protected function describeState(RuntimeDataDescriber $w) : void{ - parent::describeState($w); + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ + parent::describeBlockOnlyState($w); $w->bool($this->powered); } } diff --git a/src/block/utils/SignLikeRotationTrait.php b/src/block/utils/SignLikeRotationTrait.php index 2fed25910..233c75095 100644 --- a/src/block/utils/SignLikeRotationTrait.php +++ b/src/block/utils/SignLikeRotationTrait.php @@ -30,7 +30,7 @@ trait SignLikeRotationTrait{ /** @var int */ private $rotation = 0; - protected function describeState(RuntimeDataDescriber $w) : void{ + protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, 15, $this->rotation); } diff --git a/src/crafting/CraftingManager.php b/src/crafting/CraftingManager.php index 1b1428b05..4ae32e769 100644 --- a/src/crafting/CraftingManager.php +++ b/src/crafting/CraftingManager.php @@ -103,7 +103,7 @@ class CraftingManager{ */ public static function sort(Item $i1, Item $i2) : int{ //Use spaceship operator to compare each property, then try the next one if they are equivalent. - ($retval = $i1->getTypeId() <=> $i2->getTypeId()) === 0 && ($retval = $i1->computeTypeData() <=> $i2->computeTypeData()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()) === 0; + ($retval = $i1->getTypeId() <=> $i2->getTypeId()) === 0 && ($retval = $i1->computeStateData() <=> $i2->computeStateData()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()) === 0; return $retval; } @@ -142,7 +142,7 @@ class CraftingManager{ foreach($outputs as $o){ //count is not written because the outputs might be from multiple repetitions of a single recipe //this reduces the accuracy of the hash, but it won't matter in most cases. - $result->putVarInt(morton2d_encode($o->getTypeId(), $o->computeTypeData())); + $result->putVarInt(morton2d_encode($o->getTypeId(), $o->computeStateData())); $result->put((new LittleEndianNbtSerializer())->write(new TreeRoot($o->getNamedTag()))); } @@ -283,8 +283,8 @@ class CraftingManager{ } public function matchBrewingRecipe(Item $input, Item $ingredient) : ?BrewingRecipe{ - $inputHash = morton2d_encode($input->getTypeId(), $input->computeTypeData()); - $ingredientHash = morton2d_encode($ingredient->getTypeId(), $ingredient->computeTypeData()); + $inputHash = morton2d_encode($input->getTypeId(), $input->computeStateData()); + $ingredientHash = morton2d_encode($ingredient->getTypeId(), $ingredient->computeStateData()); $cached = $this->brewingRecipeCache[$inputHash][$ingredientHash] ?? null; if($cached !== null){ return $cached; diff --git a/src/crafting/FurnaceRecipeManager.php b/src/crafting/FurnaceRecipeManager.php index 74e2817b6..951c55681 100644 --- a/src/crafting/FurnaceRecipeManager.php +++ b/src/crafting/FurnaceRecipeManager.php @@ -66,7 +66,7 @@ final class FurnaceRecipeManager{ } public function match(Item $input) : ?FurnaceRecipe{ - $index = morton2d_encode($input->getTypeId(), $input->computeTypeData()); + $index = morton2d_encode($input->getTypeId(), $input->computeStateData()); $simpleRecipe = $this->lookupCache[$index] ?? null; if($simpleRecipe !== null){ return $simpleRecipe; diff --git a/src/item/Banner.php b/src/item/Banner.php index 5de6bd909..250f2099e 100644 --- a/src/item/Banner.php +++ b/src/item/Banner.php @@ -63,7 +63,7 @@ class Banner extends ItemBlockWallOrFloor{ return $this; } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->dyeColor($this->color); } diff --git a/src/item/CoralFan.php b/src/item/CoralFan.php index 7ea31d53d..294eb6d6e 100644 --- a/src/item/CoralFan.php +++ b/src/item/CoralFan.php @@ -33,7 +33,7 @@ use pocketmine\math\Facing; final class CoralFan extends Item{ use CoralTypeTrait { - describeType as encodeCoralType; + describeBlockItemState as encodeCoralType; } public function __construct(ItemIdentifier $identifier){ @@ -41,7 +41,7 @@ final class CoralFan extends Item{ parent::__construct($identifier, VanillaBlocks::CORAL_FAN()->getName()); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ //this is aliased to ensure a compile error in case the functions in Item or Block start to differ in future //right now we can directly reuse encodeType from CoralTypeTrait, but that might silently stop working if Item //were to be altered. CoralTypeTrait was originally intended for blocks, so it's better not to assume anything. diff --git a/src/item/Dye.php b/src/item/Dye.php index 969c66eee..f71b44e3a 100644 --- a/src/item/Dye.php +++ b/src/item/Dye.php @@ -34,7 +34,7 @@ class Dye extends Item{ parent::__construct($identifier, $name); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->dyeColor($this->color); } diff --git a/src/item/Item.php b/src/item/Item.php index c052331a3..6fe45fccc 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -469,13 +469,17 @@ class Item implements \JsonSerializable{ return $this->identifier->getTypeId(); } - final public function computeTypeData() : int{ + final public function computeStateData() : int{ $writer = new RuntimeDataWriter(16); //TODO: max bits should be a constant instead of being hardcoded all over the place - $this->describeType($writer); + $this->describeState($writer); return $writer->getValue(); } - protected function describeType(RuntimeDataDescriber $w) : void{ + /** + * Describes state properties of the item, such as colour, skull type, etc. + * This allows associating basic extra data with the item at runtime in a more efficient format than NBT. + */ + protected function describeState(RuntimeDataDescriber $w) : void{ //NOOP } @@ -627,7 +631,7 @@ class Item implements \JsonSerializable{ */ final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{ return $this->getTypeId() === $item->getTypeId() && - $this->computeTypeData() === $item->computeTypeData() && + $this->computeStateData() === $item->computeStateData() && (!$checkCompound || $this->getNamedTag()->equals($item->getNamedTag())); } @@ -646,7 +650,7 @@ class Item implements \JsonSerializable{ } final public function __toString() : string{ - return "Item " . $this->name . " (" . $this->getTypeId() . ":" . $this->computeTypeData() . ")x" . $this->count . ($this->hasNamedTag() ? " tags:0x" . base64_encode((new LittleEndianNbtSerializer())->write(new TreeRoot($this->getNamedTag()))) : ""); + return "Item " . $this->name . " (" . $this->getTypeId() . ":" . $this->computeStateData() . ")x" . $this->count . ($this->hasNamedTag() ? " tags:0x" . base64_encode((new LittleEndianNbtSerializer())->write(new TreeRoot($this->getNamedTag()))) : ""); } /** diff --git a/src/item/ItemBlock.php b/src/item/ItemBlock.php index 16c4badf3..fbbe2efeb 100644 --- a/src/item/ItemBlock.php +++ b/src/item/ItemBlock.php @@ -39,8 +39,8 @@ final class ItemBlock extends Item{ parent::__construct(ItemIdentifier::fromBlock($block), $block->getName()); } - protected function describeType(RuntimeDataDescriber $w) : void{ - $this->block->describeType($w); + protected function describeState(RuntimeDataDescriber $w) : void{ + $this->block->describeBlockItemState($w); } public function getBlock(?int $clickedFace = null) : Block{ diff --git a/src/item/Medicine.php b/src/item/Medicine.php index 099af6d3c..a15ac0353 100644 --- a/src/item/Medicine.php +++ b/src/item/Medicine.php @@ -36,7 +36,7 @@ class Medicine extends Item implements ConsumableItem{ parent::__construct($identifier, $name); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->medicineType($this->medicineType); } diff --git a/src/item/Potion.php b/src/item/Potion.php index 7fcbeaa04..0ef339866 100644 --- a/src/item/Potion.php +++ b/src/item/Potion.php @@ -36,7 +36,7 @@ class Potion extends Item implements ConsumableItem{ parent::__construct($identifier, $name); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->potionType($this->potionType); } diff --git a/src/item/SplashPotion.php b/src/item/SplashPotion.php index a99d7541d..c54562f2b 100644 --- a/src/item/SplashPotion.php +++ b/src/item/SplashPotion.php @@ -38,7 +38,7 @@ class SplashPotion extends ProjectileItem{ parent::__construct($identifier, $name); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->potionType($this->potionType); } diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 72bc4d6a9..c2905a40b 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -1540,7 +1540,7 @@ final class StringToItemParser extends StringToTParser{ public function register(string $alias, \Closure $callback) : void{ parent::register($alias, $callback); $item = $callback($alias); - $this->reverseMap[$item->getTypeId()][$item->computeTypeData()][$alias] = true; + $this->reverseMap[$item->getTypeId()][$item->computeStateData()][$alias] = true; } /** @phpstan-param \Closure(string $input) : Block $callback */ @@ -1559,7 +1559,7 @@ final class StringToItemParser extends StringToTParser{ * @phpstan-return list */ public function lookupAliases(Item $item) : array{ - $aliases = $this->reverseMap[$item->getTypeId()][$item->computeTypeData()] ?? []; + $aliases = $this->reverseMap[$item->getTypeId()][$item->computeStateData()] ?? []; return array_keys($aliases); } diff --git a/src/item/SuspiciousStew.php b/src/item/SuspiciousStew.php index 1ecb94d7b..a2adc0b61 100644 --- a/src/item/SuspiciousStew.php +++ b/src/item/SuspiciousStew.php @@ -34,7 +34,7 @@ class SuspiciousStew extends Food{ parent::__construct($identifier, $name); } - protected function describeType(RuntimeDataDescriber $w) : void{ + protected function describeState(RuntimeDataDescriber $w) : void{ $w->suspiciousStewType($this->suspiciousStewType); } diff --git a/src/network/mcpe/convert/TypeConverter.php b/src/network/mcpe/convert/TypeConverter.php index b6c7909b6..6c31f015a 100644 --- a/src/network/mcpe/convert/TypeConverter.php +++ b/src/network/mcpe/convert/TypeConverter.php @@ -222,7 +222,7 @@ class TypeConverter{ if($nbt === null){ $nbt = new CompoundTag(); } - $nbt->setLong(self::PM_ID_TAG, morton2d_encode($itemStack->getTypeId(), $itemStack->computeTypeData())); + $nbt->setLong(self::PM_ID_TAG, morton2d_encode($itemStack->getTypeId(), $itemStack->computeStateData())); }else{ [$id, $meta, $blockRuntimeId] = $idMeta; } diff --git a/src/player/Player.php b/src/player/Player.php index a858a4f21..561116cf2 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -687,7 +687,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ */ public function getItemCooldownExpiry(Item $item) : int{ $this->checkItemCooldowns(); - return $this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())] ?? 0; + return $this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeStateData())] ?? 0; } /** @@ -695,7 +695,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ */ public function hasItemCooldown(Item $item) : bool{ $this->checkItemCooldowns(); - return isset($this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())]); + return isset($this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeStateData())]); } /** @@ -704,7 +704,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ public function resetItemCooldown(Item $item, ?int $ticks = null) : void{ $ticks = $ticks ?? $item->getCooldownTicks(); if($ticks > 0){ - $this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())] = $this->server->getTick() + $ticks; + $this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeStateData())] = $this->server->getTick() + $ticks; } }