From 55a48e0c8403fa24250ffc05e86158107b8750d5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 16 Feb 2023 16:45:19 +0000 Subject: [PATCH] Block: specifying required type/state data bits is no longer required RuntimeDataSizeCalculator allows calculating the number of required bits from describeType directly, which considerably reduces boilerplate code. --- build/generate-runtime-enum-serializers.php | 27 +++++ 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 | 32 +++++- 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/ChorusFlower.php | 2 - src/block/CocoaBlock.php | 2 - src/block/Crops.php | 2 - src/block/DaylightSensor.php | 2 - src/block/DetectorRail.php | 2 - 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 | 4 - 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 | 4 - 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 | 2 - 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 | 2 - src/block/utils/CopperTrait.php | 2 - src/block/utils/CoralTypeTrait.php | 2 - src/block/utils/HorizontalFacingTrait.php | 2 - src/block/utils/PillarRotationTrait.php | 2 - .../utils/RailPoweredByRedstoneTrait.php | 2 - src/block/utils/SignLikeRotationTrait.php | 2 - .../runtime/RuntimeDataSizeCalculator.php | 99 +++++++++++++++++++ .../RuntimeEnumSizeCalculatorTrait.php | 86 ++++++++++++++++ 83 files changed, 242 insertions(+), 172 deletions(-) create mode 100644 src/data/runtime/RuntimeDataSizeCalculator.php create mode 100644 src/data/runtime/RuntimeEnumSizeCalculatorTrait.php diff --git a/build/generate-runtime-enum-serializers.php b/build/generate-runtime-enum-serializers.php index d4b723814..db1d384ca 100644 --- a/build/generate-runtime-enum-serializers.php +++ b/build/generate-runtime-enum-serializers.php @@ -105,6 +105,22 @@ function buildInterfaceFunc(string $nativeTypeName, string $functionName) : stri return "public function $functionName(\\$nativeTypeName &\$value) : void;"; } +/** + * @param string[] $memberNames + * @phpstan-param list $memberNames + * + * @return string[] + * @phpstan-return list + */ +function buildSizeCalculationFunc(string $nativeTypeName, string $functionName, array $memberNames) : array{ + $lines = []; + $lines[] = "public function $functionName(\\$nativeTypeName &\$value) : void{"; + $lines[] = "\t\$this->addBits(" . getBitsRequired($memberNames) . ");"; + $lines[] = "}"; + + return $lines; +} + /** * @param mixed[] $members */ @@ -151,6 +167,11 @@ $writerFuncs = [ ] ]; $interfaceFuncs = []; +$sizeCalculationFuncs = [ + "" => [ + "abstract protected function addBits(int \$bits) : void;" + ] +]; foreach($enumsUsed as $enumMembers){ if(count($enumMembers) === 0){ @@ -178,6 +199,11 @@ foreach($enumsUsed as $enumMembers){ $nativeTypeName, $functionName )]; + $sizeCalculationFuncs[$functionName] = buildSizeCalculationFunc( + $nativeTypeName, + $functionName, + $stringifiedMembers + ); } /** @@ -232,5 +258,6 @@ HEADER; printFunctions($writerFuncs, "RuntimeEnumSerializerTrait", "trait"); printFunctions($readerFuncs, "RuntimeEnumDeserializerTrait", "trait"); printFunctions($interfaceFuncs, "RuntimeEnumDescriber", "interface"); +printFunctions($sizeCalculationFuncs, "RuntimeEnumSizeCalculatorTrait", "trait"); echo "Done. Don't forget to run CS fixup after generating code.\n"; diff --git a/src/block/Anvil.php b/src/block/Anvil.php index 76dc2cede..17814e2c9 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -51,14 +51,10 @@ class Anvil extends Transparent implements Fallable{ private int $damage = self::UNDAMAGED; - public function getRequiredTypeDataBits() : int{ return 2; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->damage); } - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index b576e771f..a6a08859b 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -55,8 +55,6 @@ class Bamboo extends Transparent{ protected bool $ready = false; protected int $leafSize = self::NO_LEAVES; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->boundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES, $this->leafSize); $w->bool($this->thick); diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index d5342f6b4..cfa81519b 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -36,8 +36,6 @@ use pocketmine\world\BlockTransaction; final class BambooSapling extends Flowable{ private bool $ready = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->ready); } diff --git a/src/block/Barrel.php b/src/block/Barrel.php index ee732b72c..68eda5331 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -38,8 +38,6 @@ class Barrel extends Opaque{ protected bool $open = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->open); diff --git a/src/block/Bed.php b/src/block/Bed.php index 6da2f5aa9..678c8a542 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -53,8 +53,6 @@ class Bed extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->occupied); diff --git a/src/block/Bedrock.php b/src/block/Bedrock.php index 5095d3a64..4bca83305 100644 --- a/src/block/Bedrock.php +++ b/src/block/Bedrock.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class Bedrock extends Opaque{ private bool $burnsForever = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->burnsForever); } diff --git a/src/block/Bell.php b/src/block/Bell.php index 20942f1df..f20a031c2 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -48,8 +48,6 @@ final class Bell extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bellAttachmentType($this->attachmentType); $w->horizontalFacing($this->facing); diff --git a/src/block/Block.php b/src/block/Block.php index 2dce0a49a..6863f47bc 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -31,6 +31,7 @@ use pocketmine\block\tile\Tile; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataSizeCalculator; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\entity\projectile\Projectile; @@ -64,6 +65,17 @@ class Block{ /** @var AxisAlignedBB[]|null */ protected ?array $collisionBoxes = null; + /** + * @var int[] + * @phpstan-var array + */ + private static array $typeDataBits = []; + /** + * @var int[] + * @phpstan-var array + */ + private static array $stateDataBits = []; + /** * @param string $name English name of the block type (TODO: implement translations) */ @@ -114,9 +126,25 @@ class Block{ return new ItemBlock($this); } - public function getRequiredTypeDataBits() : int{ return 0; } + final public function getRequiredTypeDataBits() : int{ + $class = get_class($this); + if(isset(self::$typeDataBits[$class])){ + return self::$typeDataBits[$class]; + } + $calculator = new RuntimeDataSizeCalculator(); + $this->describeType($calculator); + return self::$typeDataBits[$class] = $calculator->getBitsUsed(); + } - public function getRequiredStateDataBits() : int{ return 0; } + final public function getRequiredStateDataBits() : int{ + $class = get_class($this); + if(isset(self::$stateDataBits[$class])){ + return self::$stateDataBits[$class]; + } + $calculator = new RuntimeDataSizeCalculator(); + $this->describeState($calculator); + return self::$stateDataBits[$class] = $calculator->getBitsUsed(); + } /** * @internal diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index 033d93df0..479d20739 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -43,8 +43,6 @@ class BrewingStand extends Transparent{ */ protected array $slots = []; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->brewingStandSlots($this->slots); } diff --git a/src/block/Button.php b/src/block/Button.php index 6274b7e69..aa6ca8fa0 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -38,8 +38,6 @@ abstract class Button extends Flowable{ protected bool $pressed = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->pressed); diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 8828219d8..18dd726e7 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -41,8 +41,6 @@ class Cactus extends Transparent{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 8870968c2..93e51be21 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -36,8 +36,6 @@ class Cake extends BaseCake{ protected int $bites = 0; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 b382c0fe5..4870277cc 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -46,10 +46,6 @@ class Candle extends Transparent{ private int $count = self::MIN_COUNT; - public function getRequiredStateDataBits() : int{ - return 3; - } - protected function describeState(RuntimeDataDescriber $w) : void{ $this->encodeLitState($w); $w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count); diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 8b20b0e3d..2aa65d1f6 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -49,8 +49,6 @@ final class ChorusFlower extends Flowable{ private int $age = self::MIN_AGE; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 02c4390b9..fe4f1736b 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -46,8 +46,6 @@ class CocoaBlock extends Transparent{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 aabab87bb..c1c13bee9 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -38,8 +38,6 @@ abstract class Crops extends Flowable{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 27ec3764e..2a55500c6 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -41,8 +41,6 @@ class DaylightSensor extends Transparent{ protected bool $inverted = false; - public function getRequiredStateDataBits() : int{ return 5; } - protected function describeState(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 032f30870..8af12276b 100644 --- a/src/block/DetectorRail.php +++ b/src/block/DetectorRail.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class DetectorRail extends StraightOnlyRail{ protected bool $activated = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ parent::describeState($w); $w->bool($this->activated); diff --git a/src/block/Dirt.php b/src/block/Dirt.php index ead1e0c83..900879433 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -45,8 +45,6 @@ class Dirt extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredTypeDataBits() : int{ return 2; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->dirtType($this->dirtType); } diff --git a/src/block/Door.php b/src/block/Door.php index b0eba797c..98a8f5309 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -41,8 +41,6 @@ class Door extends Transparent{ protected bool $hingeRight = false; protected bool $open = false; - public function getRequiredStateDataBits() : int{ return 5; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->top); diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index 00c967271..be231c1ea 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -33,8 +33,6 @@ use pocketmine\world\BlockTransaction; class DoublePlant extends Flowable{ protected bool $top = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->top); } diff --git a/src/block/EndPortalFrame.php b/src/block/EndPortalFrame.php index f4e08393f..5a6537d4d 100644 --- a/src/block/EndPortalFrame.php +++ b/src/block/EndPortalFrame.php @@ -35,8 +35,6 @@ class EndPortalFrame extends Opaque{ protected bool $eye = false; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->eye); diff --git a/src/block/Farmland.php b/src/block/Farmland.php index cdc3b464e..7ce08c2d9 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -37,8 +37,6 @@ class Farmland extends Transparent{ protected int $wetness = 0; //"moisture" blockstate property in PC - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 75ffccbea..7ad96d842 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -42,8 +42,6 @@ class FenceGate extends Transparent{ protected bool $open = false; protected bool $inWall = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->open); diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index 048b3f312..b6d9b995e 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -37,10 +37,6 @@ abstract class FillableCauldron extends Transparent{ private int $fillLevel = self::MIN_FILL_LEVEL; - public function getRequiredStateDataBits() : int{ - return 3; - } - protected function describeState(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 8184caf6d..6f4332261 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -39,8 +39,6 @@ class Fire extends BaseFire{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 11bfb9e0f..173c87a08 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -37,8 +37,6 @@ use function rad2deg; final class FloorCoralFan extends BaseCoral{ private int $axis = Axis::X; - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } diff --git a/src/block/Froglight.php b/src/block/Froglight.php index e93ec2eb8..13b68e21e 100644 --- a/src/block/Froglight.php +++ b/src/block/Froglight.php @@ -35,8 +35,6 @@ final class Froglight extends SimplePillar{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredTypeDataBits() : int{ return 2; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->froglightType($this->froglightType); } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index c1eacb019..5953ce8ae 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -32,8 +32,6 @@ class FrostedIce extends Ice{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(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 8cb174985..f830a3835 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -46,8 +46,6 @@ class Furnace extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->lit); diff --git a/src/block/Hopper.php b/src/block/Hopper.php index 7764a4ee7..778e5c2a1 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -39,8 +39,6 @@ class Hopper extends Transparent{ private int $facing = Facing::DOWN; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 a3c313ca2..94754910f 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -50,8 +50,6 @@ class ItemFrame extends Flowable{ protected int $itemRotation = 0; protected float $itemDropChance = 1.0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); $w->bool($this->hasMap); diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 47aa4496f..a5d8031dd 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -43,8 +43,6 @@ class Lantern extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->hanging); } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 94d6cbcca..b83de2dde 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -47,8 +47,6 @@ class Leaves extends Transparent{ $this->leavesType = $leavesType; } - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->noDecay); $w->bool($this->checkDecay); diff --git a/src/block/Lectern.php b/src/block/Lectern.php index 7a144dbb8..ae1df8549 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -46,8 +46,6 @@ class Lectern extends Transparent{ protected bool $producingSignal = false; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->producingSignal); diff --git a/src/block/Lever.php b/src/block/Lever.php index a39937687..284a646d9 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -44,8 +44,6 @@ class Lever extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->leverFacing($this->facing); $w->bool($this->activated); diff --git a/src/block/Light.php b/src/block/Light.php index bdd232b6c..5ee7281c9 100644 --- a/src/block/Light.php +++ b/src/block/Light.php @@ -34,8 +34,6 @@ final class Light extends Flowable{ private int $level = self::MAX_LIGHT_LEVEL; - public function getRequiredTypeDataBits() : int{ return 4; } - protected function describeType(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 4f76d4699..476a8f8c7 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -48,8 +48,6 @@ abstract class Liquid extends Transparent{ protected int $decay = 0; //PC "level" property protected bool $still = false; - public function getRequiredStateDataBits() : int{ return 5; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->boundedInt(3, 0, self::MAX_DECAY, $this->decay); $w->bool($this->falling); diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index 873040fd3..0c507a166 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -34,8 +34,6 @@ class NetherPortal extends Transparent{ protected int $axis = Axis::X; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index c2c497112..4a924b2be 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -52,10 +52,6 @@ class NetherVines extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ - return 5; - } - public function describeState(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 2d3316b2c..787b1f5f8 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -37,8 +37,6 @@ class NetherWartPlant extends Flowable{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(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 2d37f6e95..12b47e6ea 100644 --- a/src/block/Rail.php +++ b/src/block/Rail.php @@ -34,8 +34,6 @@ class Rail extends BaseRail{ private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->railShape($this->railShape); } diff --git a/src/block/RedMushroomBlock.php b/src/block/RedMushroomBlock.php index 42763ba95..17fced412 100644 --- a/src/block/RedMushroomBlock.php +++ b/src/block/RedMushroomBlock.php @@ -36,8 +36,6 @@ class RedMushroomBlock extends Opaque{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->mushroomBlockType($this->mushroomBlockType); } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index e105701d1..0f8fee840 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -44,8 +44,6 @@ class RedstoneComparator extends Flowable{ protected bool $isSubtractMode = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->isSubtractMode); diff --git a/src/block/RedstoneLamp.php b/src/block/RedstoneLamp.php index 5557076b3..1d0ff7345 100644 --- a/src/block/RedstoneLamp.php +++ b/src/block/RedstoneLamp.php @@ -29,8 +29,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class RedstoneLamp extends Opaque{ use PoweredByRedstoneTrait; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->powered); } diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 34d463731..13cf84205 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -33,8 +33,6 @@ use function mt_rand; class RedstoneOre extends Opaque{ protected bool $lit = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->lit); } diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index 212bc9f4e..d1ad17eeb 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -43,8 +43,6 @@ class RedstoneRepeater extends Flowable{ protected int $delay = self::MIN_DELAY; - public function getRequiredStateDataBits() : int{ return 5; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->boundedInt(2, self::MIN_DELAY, self::MAX_DELAY, $this->delay); diff --git a/src/block/RedstoneTorch.php b/src/block/RedstoneTorch.php index b36bc9185..f85c6c07a 100644 --- a/src/block/RedstoneTorch.php +++ b/src/block/RedstoneTorch.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class RedstoneTorch extends Torch{ protected bool $lit = true; - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ parent::describeState($w); $w->bool($this->lit); diff --git a/src/block/Sapling.php b/src/block/Sapling.php index ea04ba624..838a32ce8 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -46,8 +46,6 @@ class Sapling extends Flowable{ $this->treeType = $treeType; } - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->ready); } diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 770ae6b45..c2955cbaa 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -38,8 +38,6 @@ class SeaPickle extends Transparent{ protected int $count = self::MIN_COUNT; protected bool $underwater = false; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 292506deb..e979b09e5 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -34,8 +34,6 @@ use pocketmine\world\BlockTransaction; class ShulkerBox extends Opaque{ use AnyFacingTrait; - public function getRequiredStateDataBits() : int{ return 0; } - protected function describeState(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 f93e244a5..f4ad37ea4 100644 --- a/src/block/SimplePressurePlate.php +++ b/src/block/SimplePressurePlate.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; abstract class SimplePressurePlate extends PressurePlate{ protected bool $pressed = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->pressed); } diff --git a/src/block/Skull.php b/src/block/Skull.php index 36a587aa9..10403ab6b 100644 --- a/src/block/Skull.php +++ b/src/block/Skull.php @@ -49,14 +49,10 @@ class Skull extends Flowable{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredTypeDataBits() : int{ return 3; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->skullType($this->skullType); } - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::DOWN); } diff --git a/src/block/Slab.php b/src/block/Slab.php index 3290648eb..4e25d15a4 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -41,8 +41,6 @@ class Slab extends Transparent{ $this->slabType = SlabType::BOTTOM(); } - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->slabType($this->slabType); } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 4f3950e74..ec08620c0 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -46,8 +46,6 @@ class SnowLayer extends Flowable implements Fallable{ protected int $layers = self::MIN_LAYERS; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 d8784febd..b4e523ffa 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class Sponge extends Opaque{ protected bool $wet = false; - public function getRequiredTypeDataBits() : int{ return 1; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->bool($this->wet); } diff --git a/src/block/Stair.php b/src/block/Stair.php index afbbf7918..971dbc43a 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -46,8 +46,6 @@ class Stair extends Transparent{ parent::__construct($idInfo, $name, $typeInfo); } - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->upsideDown); diff --git a/src/block/StraightOnlyRail.php b/src/block/StraightOnlyRail.php index bb9482fe9..fe3d19b25 100644 --- a/src/block/StraightOnlyRail.php +++ b/src/block/StraightOnlyRail.php @@ -36,8 +36,6 @@ class StraightOnlyRail extends BaseRail{ private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->straightOnlyRailShape($this->railShape); } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index a23c6d74d..cc41c0fb0 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -38,8 +38,6 @@ class Sugarcane extends Flowable{ protected int $age = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 a93306da9..c9e9232e7 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -45,8 +45,6 @@ class SweetBerryBush extends Flowable{ protected int $age = self::STAGE_SAPLING; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(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 1206d0e30..7012f7145 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -45,14 +45,10 @@ 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 getRequiredTypeDataBits() : int{ return 1; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->bool($this->worksUnderwater); } - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->unstable); } diff --git a/src/block/Torch.php b/src/block/Torch.php index 5b496c9ad..b7bc5136f 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -36,8 +36,6 @@ class Torch extends Flowable{ protected int $facing = Facing::UP; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::DOWN); } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 83bf4693e..79e3f0e8f 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -40,8 +40,6 @@ class Trapdoor extends Transparent{ protected bool $open = false; protected bool $top = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->top); diff --git a/src/block/Tripwire.php b/src/block/Tripwire.php index c785e6d12..b8b3e732d 100644 --- a/src/block/Tripwire.php +++ b/src/block/Tripwire.php @@ -33,8 +33,6 @@ class Tripwire extends Flowable{ protected bool $connected = false; protected bool $disarmed = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->triggered); $w->bool($this->suspended); diff --git a/src/block/TripwireHook.php b/src/block/TripwireHook.php index 9180f971f..2ad6057b8 100644 --- a/src/block/TripwireHook.php +++ b/src/block/TripwireHook.php @@ -38,8 +38,6 @@ class TripwireHook extends Flowable{ protected bool $connected = false; protected bool $powered = false; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->connected); diff --git a/src/block/UnknownBlock.php b/src/block/UnknownBlock.php index f3faeb689..7c48b236f 100644 --- a/src/block/UnknownBlock.php +++ b/src/block/UnknownBlock.php @@ -38,8 +38,6 @@ class UnknownBlock extends Transparent{ $this->stateData = $stateData; } - public function getRequiredTypeDataBits() : int{ return Block::INTERNAL_STATE_DATA_BITS; } - protected function describeType(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 diff --git a/src/block/Vine.php b/src/block/Vine.php index 65c6d59ae..53d4b1efe 100644 --- a/src/block/Vine.php +++ b/src/block/Vine.php @@ -39,8 +39,6 @@ class Vine extends Flowable{ /** @var int[] */ protected array $faces = []; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacingFlags($this->faces); } diff --git a/src/block/Wall.php b/src/block/Wall.php index 84b45150c..8b128c525 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -42,8 +42,6 @@ class Wall extends Transparent{ protected array $connections = []; protected bool $post = false; - public function getRequiredStateDataBits() : int{ return 9; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->wallConnections($this->connections); $w->bool($this->post); diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index f50438c6e..c7e350c47 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -36,8 +36,6 @@ use pocketmine\world\BlockTransaction; final class WallCoralFan extends BaseCoral{ use HorizontalFacingTrait; - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/Wood.php b/src/block/Wood.php index 5ffd1c775..9a0c36e1d 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -38,8 +38,6 @@ class Wood extends Opaque{ private bool $stripped = false; - public function getRequiredTypeDataBits() : int{ return 1; } - protected function describeType(RuntimeDataDescriber $w) : void{ $w->bool($this->stripped); } diff --git a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php index 5247e7576..783517dcd 100644 --- a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php +++ b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; trait AnalogRedstoneSignalEmitterTrait{ protected int $signalStrength = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(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 0788c1aca..78fdd9bf9 100644 --- a/src/block/utils/AnyFacingTrait.php +++ b/src/block/utils/AnyFacingTrait.php @@ -29,8 +29,6 @@ use pocketmine\math\Facing; trait AnyFacingTrait{ protected int $facing = Facing::DOWN; - public function getRequiredStateDataBits() : int{ return 3; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->facing($this->facing); } diff --git a/src/block/utils/CandleTrait.php b/src/block/utils/CandleTrait.php index 1391382e4..60dd61849 100644 --- a/src/block/utils/CandleTrait.php +++ b/src/block/utils/CandleTrait.php @@ -39,8 +39,6 @@ use pocketmine\world\sound\FlintSteelSound; trait CandleTrait{ private bool $lit = false; - public function getRequiredStateDataBits() : int{ return 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->bool($this->lit); } diff --git a/src/block/utils/ColoredTrait.php b/src/block/utils/ColoredTrait.php index ce7113159..42abe64b9 100644 --- a/src/block/utils/ColoredTrait.php +++ b/src/block/utils/ColoredTrait.php @@ -30,8 +30,6 @@ trait ColoredTrait{ /** @var DyeColor */ private $color; - public function getRequiredTypeDataBits() : int{ return 4; } - /** @see Block::describeType() */ protected function describeType(RuntimeDataDescriber $w) : void{ $w->dyeColor($this->color); diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index 0842d1351..ed230c6ba 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -44,8 +44,6 @@ trait CopperTrait{ parent::__construct($identifier, $name, $typeInfo); } - public function getRequiredTypeDataBits() : int{ return 3; } - protected function describeType(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 3e362394a..d2c96c8f4 100644 --- a/src/block/utils/CoralTypeTrait.php +++ b/src/block/utils/CoralTypeTrait.php @@ -30,8 +30,6 @@ trait CoralTypeTrait{ protected CoralType $coralType; protected bool $dead = false; - public function getRequiredTypeDataBits() : int{ return 4; } - /** @see Block::describeType() */ protected function describeType(RuntimeDataDescriber $w) : void{ $w->coralType($this->coralType); diff --git a/src/block/utils/HorizontalFacingTrait.php b/src/block/utils/HorizontalFacingTrait.php index 283cba078..b1558b154 100644 --- a/src/block/utils/HorizontalFacingTrait.php +++ b/src/block/utils/HorizontalFacingTrait.php @@ -30,8 +30,6 @@ use pocketmine\math\Facing; trait HorizontalFacingTrait{ protected int $facing = Facing::NORTH; - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 9b898ca15..0fc206a20 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -35,8 +35,6 @@ use pocketmine\world\BlockTransaction; trait PillarRotationTrait{ protected int $axis = Axis::Y; - public function getRequiredStateDataBits() : int{ return 2; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->axis($this->axis); } diff --git a/src/block/utils/RailPoweredByRedstoneTrait.php b/src/block/utils/RailPoweredByRedstoneTrait.php index 19801ee10..a95fea253 100644 --- a/src/block/utils/RailPoweredByRedstoneTrait.php +++ b/src/block/utils/RailPoweredByRedstoneTrait.php @@ -28,8 +28,6 @@ use pocketmine\data\runtime\RuntimeDataDescriber; trait RailPoweredByRedstoneTrait{ use PoweredByRedstoneTrait; - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function describeState(RuntimeDataDescriber $w) : void{ parent::describeState($w); $w->bool($this->powered); diff --git a/src/block/utils/SignLikeRotationTrait.php b/src/block/utils/SignLikeRotationTrait.php index 9fb03b8a4..2fed25910 100644 --- a/src/block/utils/SignLikeRotationTrait.php +++ b/src/block/utils/SignLikeRotationTrait.php @@ -30,8 +30,6 @@ trait SignLikeRotationTrait{ /** @var int */ private $rotation = 0; - public function getRequiredStateDataBits() : int{ return 4; } - protected function describeState(RuntimeDataDescriber $w) : void{ $w->boundedInt(4, 0, 15, $this->rotation); } diff --git a/src/data/runtime/RuntimeDataSizeCalculator.php b/src/data/runtime/RuntimeDataSizeCalculator.php new file mode 100644 index 000000000..5678ffd81 --- /dev/null +++ b/src/data/runtime/RuntimeDataSizeCalculator.php @@ -0,0 +1,99 @@ +bits += $bits; + } + + public function getBitsUsed() : int{ + return $this->bits; + } + + public function int(int $bits, int &$value) : void{ + $this->addBits($bits); + } + + public function boundedInt(int $bits, int $min, int $max, int &$value) : void{ + $this->addBits($bits); + } + + public function bool(bool &$value) : void{ + $this->addBits(1); + } + + public function horizontalFacing(int &$facing) : void{ + $this->addBits(2); + } + + /** + * @inheritDoc + */ + public function horizontalFacingFlags(array &$faces) : void{ + $this->addBits(count(Facing::HORIZONTAL)); + // TODO: Implement horizontalFacingFlags() method. + } + + public function facing(int &$facing) : void{ + $this->addBits(3); + } + + public function facingExcept(int &$facing, int $except) : void{ + $this->facing($facing); + } + + public function axis(int &$axis) : void{ + $this->addBits(2); + } + + public function horizontalAxis(int &$axis) : void{ + $this->addBits(1); + } + + public function wallConnections(array &$connections) : void{ + //TODO: this can be reduced to 7 if we pack the trinary values + $this->addBits(8); + } + + public function brewingStandSlots(array &$slots) : void{ + $this->addBits(count(BrewingStandSlot::getAll())); + } + + public function railShape(int &$railShape) : void{ + $this->addBits(4); + } + + public function straightOnlyRailShape(int &$railShape) : void{ + $this->addBits(3); + } +} diff --git a/src/data/runtime/RuntimeEnumSizeCalculatorTrait.php b/src/data/runtime/RuntimeEnumSizeCalculatorTrait.php new file mode 100644 index 000000000..25defa2c0 --- /dev/null +++ b/src/data/runtime/RuntimeEnumSizeCalculatorTrait.php @@ -0,0 +1,86 @@ +addBits(2); + } + + public function copperOxidation(\pocketmine\block\utils\CopperOxidation &$value) : void{ + $this->addBits(2); + } + + public function coralType(\pocketmine\block\utils\CoralType &$value) : void{ + $this->addBits(3); + } + + public function dirtType(\pocketmine\block\utils\DirtType &$value) : void{ + $this->addBits(2); + } + + public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{ + $this->addBits(4); + } + + public function froglightType(\pocketmine\block\utils\FroglightType &$value) : void{ + $this->addBits(2); + } + + public function leverFacing(\pocketmine\block\utils\LeverFacing &$value) : void{ + $this->addBits(3); + } + + public function medicineType(\pocketmine\item\MedicineType &$value) : void{ + $this->addBits(2); + } + + public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType &$value) : void{ + $this->addBits(4); + } + + public function potionType(\pocketmine\item\PotionType &$value) : void{ + $this->addBits(6); + } + + public function skullType(\pocketmine\block\utils\SkullType &$value) : void{ + $this->addBits(3); + } + + public function slabType(\pocketmine\block\utils\SlabType &$value) : void{ + $this->addBits(2); + } + + public function suspiciousStewType(\pocketmine\item\SuspiciousStewType &$value) : void{ + $this->addBits(4); + } + +}