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.
This commit is contained in:
Dylan K. Taylor 2023-02-16 16:45:19 +00:00
parent c2f6d8139a
commit 55a48e0c84
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
83 changed files with 242 additions and 172 deletions

View File

@ -105,6 +105,22 @@ function buildInterfaceFunc(string $nativeTypeName, string $functionName) : stri
return "public function $functionName(\\$nativeTypeName &\$value) : void;";
}
/**
* @param string[] $memberNames
* @phpstan-param list<string> $memberNames
*
* @return string[]
* @phpstan-return list<string>
*/
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";

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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<string, int>
*/
private static array $typeDataBits = [];
/**
* @var int[]
* @phpstan-var array<string, int>
*/
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

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -0,0 +1,99 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\runtime;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\math\Facing;
use function count;
final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{
use RuntimeEnumSizeCalculatorTrait;
private int $bits = 0;
protected function addBits(int $bits) : void{
$this->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);
}
}

View File

@ -0,0 +1,86 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\runtime;
/**
* This class is auto-generated. Do not edit it manually.
* @see build/generate-runtime-enum-serializers.php
*/
trait RuntimeEnumSizeCalculatorTrait{
abstract protected function addBits(int $bits) : void;
public function bellAttachmentType(\pocketmine\block\utils\BellAttachmentType &$value) : void{
$this->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);
}
}