mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Improve BlockFactory initialization performance
as expected, expanding data range unconditionally resulted in some performance issues ...
This commit is contained in:
parent
bedc9cf518
commit
0afb67be7d
@ -51,6 +51,8 @@ class Anvil extends Transparent implements Fallable{
|
||||
return $this->damage << 2;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->setDamage($r->readBoundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED));
|
||||
$this->setFacing($r->readHorizontalFacing());
|
||||
|
@ -55,6 +55,8 @@ class Bamboo extends Transparent{
|
||||
protected bool $ready = false;
|
||||
protected int $leafSize = self::NO_LEAVES;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->setLeafSize($r->readBoundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES));
|
||||
$this->setThick($r->readBool());
|
||||
|
@ -36,6 +36,8 @@ use pocketmine\world\BlockTransaction;
|
||||
final class BambooSapling extends Flowable{
|
||||
private bool $ready = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->setReady($r->readBool());
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class Barrel extends Opaque{
|
||||
|
||||
protected bool $open = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->setFacing($r->readFacing());
|
||||
$this->setOpen($r->readBool());
|
||||
|
@ -55,6 +55,9 @@ abstract class BaseBanner extends Transparent{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 0; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
//TODO: we currently purposely don't read or write colour (it's stored on the tile)
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ class Bed extends Transparent{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->occupied = $r->readBool();
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\block\utils\BlockDataWriter;
|
||||
class Bedrock extends Opaque{
|
||||
private bool $burnsForever = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->burnsForever = $r->readBool();
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ final class Bell extends Transparent{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->attachmentType = BlockDataReaderHelper::readBellAttachmentType($r);
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
|
@ -100,9 +100,16 @@ class Block{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 0; }
|
||||
|
||||
public function decodeStateData(int $data) : void{
|
||||
$reader = new BlockDataReader(self::INTERNAL_STATE_DATA_BITS, $data);
|
||||
$givenBits = $this->getRequiredStateDataBits();
|
||||
$reader = new BlockDataReader($givenBits, $data);
|
||||
$this->decodeState($reader);
|
||||
$readBits = $reader->getOffset();
|
||||
if($givenBits !== $readBits){
|
||||
throw new \LogicException("Exactly $givenBits bits of state data were provided, but only $readBits were read");
|
||||
}
|
||||
}
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
@ -113,8 +120,14 @@ class Block{
|
||||
* @internal
|
||||
*/
|
||||
public function computeStateData() : int{
|
||||
$writer = new BlockDataWriter(self::INTERNAL_STATE_DATA_BITS);
|
||||
$requiredBits = $this->getRequiredStateDataBits();
|
||||
$writer = new BlockDataWriter($requiredBits);
|
||||
$this->encodeState($writer);
|
||||
|
||||
$writtenBits = $writer->getOffset();
|
||||
if($requiredBits !== $writtenBits){
|
||||
throw new \LogicException("Exactly $requiredBits bits of state data were expected, but only $writtenBits were written");
|
||||
}
|
||||
return $writer->getValue();
|
||||
}
|
||||
|
||||
|
@ -864,7 +864,11 @@ class BlockFactory{
|
||||
|
||||
//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
|
||||
for($stateData = 0; $stateData < (1 << Block::INTERNAL_STATE_DATA_BITS); ++$stateData){
|
||||
$bits = $block->getRequiredStateDataBits();
|
||||
if($bits > Block::INTERNAL_STATE_DATA_BITS){
|
||||
throw new \InvalidArgumentException("Block state data cannot use more than " . Block::INTERNAL_STATE_DATA_BITS . " bits");
|
||||
}
|
||||
for($stateData = 0; $stateData < (1 << $bits); ++$stateData){
|
||||
$v = clone $block;
|
||||
try{
|
||||
$v->decodeStateData($stateData);
|
||||
|
@ -46,6 +46,8 @@ class BrewingStand extends Transparent{
|
||||
*/
|
||||
protected array $slots = [];
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->setSlots(BlockDataReaderHelper::readBrewingStandSlotKeySet($r));
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ abstract class Button extends Flowable{
|
||||
|
||||
protected bool $pressed = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
$this->pressed = $r->readBool();
|
||||
|
@ -42,6 +42,8 @@ class Cactus extends Transparent{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class Cake extends Transparent implements FoodSource{
|
||||
|
||||
protected int $bites = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->bites = $r->readBoundedInt(3, 0, self::MAX_BITES);
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ class CocoaBlock extends Transparent{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
|
@ -39,6 +39,8 @@ abstract class Crops extends Flowable{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(3, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ class DaylightSensor extends Transparent{
|
||||
|
||||
protected bool $inverted = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->signalStrength = $r->readBoundedInt(4, 0, 15);
|
||||
$this->inverted = $r->readBool();
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\block\utils\BlockDataWriter;
|
||||
class DetectorRail extends StraightOnlyRail{
|
||||
protected bool $activated = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->activated = $r->readBool();
|
||||
|
@ -39,6 +39,8 @@ class Dirt extends Opaque{
|
||||
return $this->coarse ? BlockLegacyMetadata::DIRT_FLAG_COARSE : 0;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->coarse = $r->readBool();
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ class Door extends Transparent{
|
||||
protected bool $hingeRight = false;
|
||||
protected bool $open = false;
|
||||
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->top = $r->readBool();
|
||||
|
@ -34,6 +34,8 @@ use pocketmine\world\BlockTransaction;
|
||||
class DoublePlant extends Flowable{
|
||||
protected bool $top = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->top = $r->readBool();
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ class EndPortalFrame extends Opaque{
|
||||
|
||||
protected bool $eye = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->eye = $r->readBool();
|
||||
|
@ -38,6 +38,8 @@ class Farmland extends Transparent{
|
||||
|
||||
protected int $wetness = 0; //"moisture" blockstate property in PC
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->wetness = $r->readBoundedInt(3, 0, self::MAX_WETNESS);
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class FenceGate extends Transparent{
|
||||
protected bool $open = false;
|
||||
protected bool $inWall = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->open = $r->readBool();
|
||||
|
@ -46,6 +46,8 @@ class Fire extends Flowable{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ final class FloorBanner extends BaseBanner{
|
||||
encodeState as encodeRotation;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->decodeRotation($r);
|
||||
|
@ -52,6 +52,8 @@ final class FloorCoralFan extends BaseCoral{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->axis = $r->readHorizontalAxis();
|
||||
|
@ -33,6 +33,8 @@ class FrostedIce extends Ice{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class Furnace extends Opaque{
|
||||
|
||||
protected bool $lit = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->lit = $r->readBool();
|
||||
|
@ -41,6 +41,8 @@ class Hopper extends Transparent{
|
||||
|
||||
private int $facing = Facing::DOWN;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::UP){
|
||||
|
@ -47,6 +47,8 @@ class ItemFrame extends Flowable{
|
||||
protected int $itemRotation = 0;
|
||||
protected float $itemDropChance = 1.0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
$this->hasMap = $r->readBool();
|
||||
|
@ -37,6 +37,8 @@ use pocketmine\world\BlockTransaction;
|
||||
class Lantern extends Transparent{
|
||||
protected bool $hanging = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->hanging = $r->readBool();
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ class Leaves extends Transparent{
|
||||
$this->treeType = $treeType;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->noDecay = $r->readBool();
|
||||
$this->checkDecay = $r->readBool();
|
||||
|
@ -47,6 +47,8 @@ class Lectern extends Transparent{
|
||||
|
||||
protected bool $producingSignal = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->producingSignal = $r->readBool();
|
||||
|
@ -47,6 +47,8 @@ class Lever extends Flowable{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = BlockDataReaderHelper::readLeverFacing($r);
|
||||
$this->activated = $r->readBool();
|
||||
|
@ -49,6 +49,8 @@ abstract class Liquid extends Transparent{
|
||||
protected int $decay = 0; //PC "level" property
|
||||
protected bool $still = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->decay = $r->readBoundedInt(3, 0, self::MAX_DECAY);
|
||||
$this->falling = $r->readBool();
|
||||
|
@ -35,6 +35,8 @@ class NetherPortal extends Transparent{
|
||||
|
||||
protected int $axis = Axis::X;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->axis = $r->readHorizontalAxis();
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ class NetherWartPlant extends Flowable{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ class Rail extends BaseRail{
|
||||
|
||||
private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$railShape = $r->readInt(4);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$railShape]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$railShape])){
|
||||
|
@ -39,6 +39,8 @@ class RedMushroomBlock extends Opaque{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->mushroomBlockType = BlockDataReaderHelper::readMushroomBlockType($r);
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ class RedstoneComparator extends Flowable{
|
||||
|
||||
protected bool $isSubtractMode = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->isSubtractMode = $r->readBool();
|
||||
|
@ -30,6 +30,8 @@ use pocketmine\block\utils\PoweredByRedstoneTrait;
|
||||
class RedstoneLamp extends Opaque{
|
||||
use PoweredByRedstoneTrait;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ use function mt_rand;
|
||||
class RedstoneOre extends Opaque{
|
||||
protected bool $lit = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->lit = $r->readBool();
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ class RedstoneRepeater extends Flowable{
|
||||
|
||||
protected int $delay = self::MIN_DELAY;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->delay = $r->readBoundedInt(2, self::MIN_DELAY - 1, self::MAX_DELAY - 1) + 1;
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\block\utils\BlockDataWriter;
|
||||
class RedstoneTorch extends Torch{
|
||||
protected bool $lit = true;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->lit = $r->readBool();
|
||||
|
@ -47,6 +47,8 @@ class Sapling extends Flowable{
|
||||
$this->treeType = $treeType;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->ready = $r->readBool();
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class SeaPickle extends Transparent{
|
||||
protected int $count = self::MIN_COUNT;
|
||||
protected bool $underwater = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->count = $r->readBoundedInt(2, self::MIN_COUNT - 1, self::MAX_COUNT - 1) + 1;
|
||||
$this->underwater = $r->readBool();
|
||||
|
@ -35,6 +35,8 @@ use pocketmine\world\BlockTransaction;
|
||||
class ShulkerBox extends Opaque{
|
||||
use AnyFacingTrait;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 0; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
//NOOP - we don't read or write facing here, because the tile persists it
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\block\utils\BlockDataWriter;
|
||||
abstract class SimplePressurePlate extends PressurePlate{
|
||||
protected bool $pressed = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->pressed = $r->readBool();
|
||||
}
|
||||
|
@ -51,6 +51,8 @@ class Skull extends Flowable{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::DOWN){
|
||||
|
@ -44,6 +44,8 @@ class Slab extends Transparent{
|
||||
$this->slabType = SlabType::BOTTOM();
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->slabType = BlockDataReaderHelper::readSlabType($r);
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ class SnowLayer extends Flowable implements Fallable{
|
||||
|
||||
protected int $layers = self::MIN_LAYERS;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->layers = $r->readBoundedInt(3, self::MIN_LAYERS - 1, self::MAX_LAYERS - 1) + 1;
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ class Sponge extends Opaque{
|
||||
return $this->wet ? BlockLegacyMetadata::SPONGE_FLAG_WET : 0;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->wet = $r->readBool();
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ class Stair extends Transparent{
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->upsideDown = $r->readBool();
|
||||
|
@ -37,6 +37,8 @@ class StraightOnlyRail extends BaseRail{
|
||||
|
||||
private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$railShape = $r->readInt(3);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$railShape])){
|
||||
|
@ -38,6 +38,8 @@ class Sugarcane extends Flowable{
|
||||
|
||||
protected int $age = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ class SweetBerryBush extends Flowable{
|
||||
|
||||
protected int $age = self::STAGE_SAPLING;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE);
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ class TNT extends Opaque{
|
||||
return $this->worksUnderwater ? BlockLegacyMetadata::TNT_FLAG_UNDERWATER : 0;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->unstable = $r->readBool();
|
||||
$this->worksUnderwater = $r->readBool();
|
||||
|
@ -38,6 +38,8 @@ class Torch extends Flowable{
|
||||
|
||||
protected int $facing = Facing::UP;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::DOWN){
|
||||
|
@ -41,6 +41,8 @@ class Trapdoor extends Transparent{
|
||||
protected bool $open = false;
|
||||
protected bool $top = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->top = $r->readBool();
|
||||
|
@ -32,6 +32,8 @@ class Tripwire extends Flowable{
|
||||
protected bool $connected = false;
|
||||
protected bool $disarmed = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->triggered = $r->readBool();
|
||||
$this->suspended = $r->readBool();
|
||||
|
@ -39,6 +39,8 @@ class TripwireHook extends Flowable{
|
||||
protected bool $connected = false;
|
||||
protected bool $powered = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->connected = $r->readBool();
|
||||
|
@ -40,6 +40,8 @@ class Vine extends Flowable{
|
||||
/** @var int[] */
|
||||
protected array $faces = [];
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$this->setFace($facing, $r->readBool());
|
||||
|
@ -43,6 +43,8 @@ class Wall extends Transparent{
|
||||
protected array $connections = [];
|
||||
protected bool $post = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 9; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->connections = $r->readWallConnections();
|
||||
$this->post = $r->readBool();
|
||||
|
@ -39,6 +39,8 @@ final class WallBanner extends BaseBanner{
|
||||
encodeState as encodeFacing;
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->decodeFacing($r);
|
||||
|
@ -43,6 +43,8 @@ final class WallCoralFan extends BaseCoral{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
|
@ -26,6 +26,8 @@ namespace pocketmine\block\utils;
|
||||
trait AnalogRedstoneSignalEmitterTrait{
|
||||
protected int $signalStrength = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->signalStrength = $r->readBoundedInt(4, 0, 15);
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ use pocketmine\math\Facing;
|
||||
trait AnyFacingTrait{
|
||||
protected int $facing = Facing::DOWN;
|
||||
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
}
|
||||
|
@ -118,4 +118,6 @@ final class BlockDataReader{
|
||||
|
||||
return $connections;
|
||||
}
|
||||
|
||||
public function getOffset() : int{ return $this->offset; }
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ trait ColoredTrait{
|
||||
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
/** @see Block::decodeState() */
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->color = BlockDataReaderHelper::readDyeColor($r);
|
||||
|
@ -27,6 +27,8 @@ trait CoralTypeTrait{
|
||||
protected CoralType $coralType;
|
||||
protected bool $dead = false;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->coralType = BlockDataReaderHelper::readCoralType($r);
|
||||
$this->dead = $r->readBool();
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\math\Facing;
|
||||
trait HorizontalFacingTrait{
|
||||
protected int $facing = Facing::NORTH;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ use pocketmine\world\BlockTransaction;
|
||||
trait PillarRotationTrait{
|
||||
protected int $axis = Axis::Y;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->axis = $r->readAxis();
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ namespace pocketmine\block\utils;
|
||||
trait RailPoweredByRedstoneTrait{
|
||||
use PoweredByRedstoneTrait;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->powered = $r->readBool();
|
||||
|
@ -29,6 +29,8 @@ trait SignLikeRotationTrait{
|
||||
/** @var int */
|
||||
private $rotation = 0;
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
$this->rotation = $r->readBoundedInt(4, 0, 15);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user