mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
A giant hack to cut down code needed for runtime block serialization by 50%
this also avoids repeated information and inconsistencies.
This commit is contained in:
parent
cf34f88a67
commit
6d4279671e
@ -41,6 +41,7 @@ use function dirname;
|
||||
use function file_put_contents;
|
||||
use function implode;
|
||||
use function ksort;
|
||||
use function lcfirst;
|
||||
use function log;
|
||||
use function ob_get_clean;
|
||||
use function ob_start;
|
||||
@ -58,9 +59,9 @@ function buildWriterFunc(string $virtualTypeName, string $nativeTypeName, array
|
||||
$bits = getBitsRequired($memberNames);
|
||||
$lines = [];
|
||||
|
||||
$functionName = "write$virtualTypeName";
|
||||
$functionName = lcfirst($virtualTypeName);
|
||||
$lines[] = "public function $functionName(\\$nativeTypeName \$value) : void{";
|
||||
$lines[] = "\t\$this->writeInt($bits, match(\$value){";
|
||||
$lines[] = "\t\$this->int($bits, match(\$value){";
|
||||
|
||||
foreach($memberNames as $key => $memberName){
|
||||
$lines[] = "\t\t$memberName => $key,";
|
||||
@ -83,9 +84,9 @@ function buildReaderFunc(string $virtualTypeName, string $nativeTypeName, array
|
||||
$bits = getBitsRequired($memberNames);
|
||||
$lines = [];
|
||||
|
||||
$functionName = "read$virtualTypeName";
|
||||
$lines[] = "public function $functionName() : \\$nativeTypeName{";
|
||||
$lines[] = "\treturn match(\$this->readInt($bits)){";
|
||||
$functionName = lcfirst($virtualTypeName);
|
||||
$lines[] = "public function $functionName(\\$nativeTypeName &\$value) : void{";
|
||||
$lines[] = "\t\$value = match(\$this->readInt($bits)){";
|
||||
|
||||
foreach($memberNames as $key => $memberName){
|
||||
$lines[] = "\t\t$key => $memberName,";
|
||||
@ -167,12 +168,12 @@ $enumsUsed = [
|
||||
|
||||
$readerFuncs = [
|
||||
"" => [
|
||||
"abstract public function readInt(int \$bits) : int;"
|
||||
"abstract protected function readInt(int \$bits) : int;"
|
||||
]
|
||||
];
|
||||
$writerFuncs = [
|
||||
"" => [
|
||||
"abstract public function writeInt(int \$bits, int \$value) : self;"
|
||||
"abstract public function int(int \$bits, int \$value) : void;"
|
||||
]
|
||||
];
|
||||
$functionName = "";
|
||||
|
@ -49,22 +49,14 @@ class Anvil extends Transparent implements Fallable{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->setDamage($r->readBoundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED));
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->getDamage());
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->damage);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->setFacing($r->readHorizontalFacing());
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->getFacing());
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
}
|
||||
|
||||
public function getDamage() : int{ return $this->damage; }
|
||||
|
@ -58,16 +58,10 @@ class Bamboo extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->setLeafSize($r->readBoundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES));
|
||||
$this->setThick($r->readBool());
|
||||
$this->setReady($r->readBool());
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES, $this->getLeafSize());
|
||||
$w->writeBool($this->isThick());
|
||||
$w->writeBool($this->isReady());
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES, $this->leafSize);
|
||||
$w->bool($this->thick);
|
||||
$w->bool($this->ready);
|
||||
}
|
||||
|
||||
public function isThick() : bool{ return $this->thick; }
|
||||
|
@ -39,12 +39,8 @@ final class BambooSapling extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->setReady($r->readBool());
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->isReady());
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->ready);
|
||||
}
|
||||
|
||||
public function isReady() : bool{ return $this->ready; }
|
||||
|
@ -41,14 +41,9 @@ class Barrel extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->setFacing($r->readFacing());
|
||||
$this->setOpen($r->readBool());
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->getFacing());
|
||||
$w->writeBool($this->isOpen());
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facing($this->facing);
|
||||
$w->bool($this->open);
|
||||
}
|
||||
|
||||
public function isOpen() : bool{
|
||||
|
@ -56,16 +56,10 @@ class Bed extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->occupied = $r->readBool();
|
||||
$this->head = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->occupied);
|
||||
$w->writeBool($this->head);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->occupied);
|
||||
$w->bool($this->head);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -31,12 +31,8 @@ class Bedrock extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->burnsForever = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->burnsForever);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->burnsForever);
|
||||
}
|
||||
|
||||
public function burnsForever() : bool{
|
||||
|
@ -49,14 +49,9 @@ final class Bell extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->attachmentType = $r->readBellAttachmentType();
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBellAttachmentType($this->attachmentType);
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bellAttachmentType($this->attachmentType);
|
||||
$w->horizontalFacing($this->facing);
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
|
@ -107,7 +107,7 @@ class Block{
|
||||
$givenBits = $typeBits;
|
||||
$reader = new RuntimeDataReader($givenBits, $data);
|
||||
|
||||
$this->decodeType($reader);
|
||||
$this->describeType($reader);
|
||||
$readBits = $reader->getOffset();
|
||||
if($typeBits !== $readBits){
|
||||
throw new \LogicException(get_class($this) . ": Exactly $typeBits bits of type data were provided, but $readBits were read");
|
||||
@ -124,21 +124,13 @@ class Block{
|
||||
$reader = new RuntimeDataReader($givenBits, $data);
|
||||
$this->decodeTypeData($reader->readInt($typeBits));
|
||||
|
||||
$this->decodeState($reader);
|
||||
$this->describeState($reader);
|
||||
$readBits = $reader->getOffset() - $typeBits;
|
||||
if($stateBits !== $readBits){
|
||||
throw new \LogicException(get_class($this) . ": Exactly $stateBits bits of state data were provided, but $readBits were read");
|
||||
}
|
||||
}
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -147,7 +139,7 @@ class Block{
|
||||
$requiredBits = $typeBits;
|
||||
$writer = new RuntimeDataWriter($requiredBits);
|
||||
|
||||
$this->encodeType($writer);
|
||||
$this->describeType($writer);
|
||||
$writtenBits = $writer->getOffset();
|
||||
if($typeBits !== $writtenBits){
|
||||
throw new \LogicException(get_class($this) . ": Exactly $typeBits bits of type data were expected, but $writtenBits were written");
|
||||
@ -164,9 +156,9 @@ class Block{
|
||||
$stateBits = $this->getRequiredStateDataBits();
|
||||
$requiredBits = $typeBits + $stateBits;
|
||||
$writer = new RuntimeDataWriter($requiredBits);
|
||||
$writer->writeInt($typeBits, $this->computeTypeData());
|
||||
$writer->int($typeBits, $this->computeTypeData());
|
||||
|
||||
$this->encodeState($writer);
|
||||
$this->describeState($writer);
|
||||
$writtenBits = $writer->getOffset() - $typeBits;
|
||||
if($stateBits !== $writtenBits){
|
||||
throw new \LogicException(get_class($this) . ": Exactly $stateBits bits of state data were expected, but $writtenBits were written");
|
||||
@ -175,11 +167,11 @@ class Block{
|
||||
return $writer->getValue();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,8 @@ class BrewingStand extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->setSlots($r->readBrewingStandSlots());
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBrewingStandSlots($this->getSlots());
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->brewingStandSlots($this->slots);
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
|
@ -41,14 +41,9 @@ abstract class Button extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
$this->pressed = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
$w->writeBool($this->pressed);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facing($this->facing);
|
||||
$w->bool($this->pressed);
|
||||
}
|
||||
|
||||
public function isPressed() : bool{ return $this->pressed; }
|
||||
|
@ -44,12 +44,8 @@ class Cactus extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -39,12 +39,8 @@ class Cake extends BaseCake{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->bites = $r->readBoundedInt(3, 0, self::MAX_BITES);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, 0, self::MAX_BITES, $this->bites);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, 0, self::MAX_BITES, $this->bites);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,10 +24,16 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColoredTrait;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
|
||||
class CakeWithDyedCandle extends CakeWithCandle{
|
||||
use ColoredTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->color = DyeColor::WHITE();
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getCandle() : Candle{
|
||||
return VanillaBlocks::DYED_CANDLE()->setColor($this->color);
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ use pocketmine\world\BlockTransaction;
|
||||
|
||||
class Candle extends Transparent{
|
||||
use CandleTrait {
|
||||
decodeState as decodeLitState;
|
||||
encodeState as encodeLitState;
|
||||
describeState as encodeLitState;
|
||||
getLightLevel as getBaseLightLevel;
|
||||
}
|
||||
|
||||
@ -51,14 +50,9 @@ class Candle extends Transparent{
|
||||
return 3;
|
||||
}
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->decodeLitState($r);
|
||||
$this->count = $r->readBoundedInt(2, self::MIN_COUNT, self::MAX_COUNT);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$this->encodeLitState($w);
|
||||
$w->writeBoundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
|
||||
$w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
|
||||
}
|
||||
|
||||
public function getCount() : int{ return $this->count; }
|
||||
|
@ -49,14 +49,9 @@ class CocoaBlock extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBoundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -23,8 +23,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\CopperOxidation;
|
||||
use pocketmine\block\utils\CopperTrait;
|
||||
|
||||
class CopperStairs extends Stair{
|
||||
use CopperTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->oxidation = CopperOxidation::NONE();
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,8 @@ abstract class Crops extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(3, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -44,14 +44,9 @@ class DaylightSensor extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->signalStrength = $r->readBoundedInt(4, 0, 15);
|
||||
$this->inverted = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, 15, $this->signalStrength);
|
||||
$w->writeBool($this->inverted);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, 15, $this->signalStrength);
|
||||
$w->bool($this->inverted);
|
||||
}
|
||||
|
||||
public function isInverted() : bool{
|
||||
|
@ -31,14 +31,9 @@ class DetectorRail extends StraightOnlyRail{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->activated = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
parent::encodeState($w);
|
||||
$w->writeBool($this->activated);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
parent::describeState($w);
|
||||
$w->bool($this->activated);
|
||||
}
|
||||
|
||||
public function isActivated() : bool{ return $this->activated; }
|
||||
|
@ -37,12 +37,8 @@ class Dirt extends Opaque{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->coarse = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->coarse);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->coarse);
|
||||
}
|
||||
|
||||
public function isCoarse() : bool{ return $this->coarse; }
|
||||
|
@ -44,18 +44,11 @@ class Door extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->top = $r->readBool();
|
||||
$this->hingeRight = $r->readBool();
|
||||
$this->open = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->top);
|
||||
$w->writeBool($this->hingeRight);
|
||||
$w->writeBool($this->open);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->top);
|
||||
$w->bool($this->hingeRight);
|
||||
$w->bool($this->open);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -36,12 +36,8 @@ class DoublePlant extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->top = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->top);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->top);
|
||||
}
|
||||
|
||||
public function isTop() : bool{ return $this->top; }
|
||||
|
@ -24,10 +24,16 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColoredTrait;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
|
||||
class DyedCandle extends Candle{
|
||||
use ColoredTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->color = DyeColor::WHITE();
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
protected function getCandleIfCompatibleType(Block $block) : ?Candle{
|
||||
$result = parent::getCandleIfCompatibleType($block);
|
||||
//different coloured candles can't be combined in the same block
|
||||
|
@ -38,14 +38,9 @@ class EndPortalFrame extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->eye = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->eye);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->eye);
|
||||
}
|
||||
|
||||
public function hasEye() : bool{ return $this->eye; }
|
||||
|
@ -40,12 +40,8 @@ class Farmland extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->wetness = $r->readBoundedInt(3, 0, self::MAX_WETNESS);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, 0, self::MAX_WETNESS, $this->wetness);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, 0, self::MAX_WETNESS, $this->wetness);
|
||||
}
|
||||
|
||||
public function getWetness() : int{ return $this->wetness; }
|
||||
|
@ -45,16 +45,10 @@ class FenceGate extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->open = $r->readBool();
|
||||
$this->inWall = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->open);
|
||||
$w->writeBool($this->inWall);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->open);
|
||||
$w->bool($this->inWall);
|
||||
}
|
||||
|
||||
public function isOpen() : bool{ return $this->open; }
|
||||
|
@ -42,12 +42,8 @@ class Fire extends BaseFire{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -40,12 +40,8 @@ final class FloorCoralFan extends BaseCoral{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->axis = $r->readHorizontalAxis();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalAxis($this->axis);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalAxis($this->axis);
|
||||
}
|
||||
|
||||
public function getAxis() : int{ return $this->axis; }
|
||||
|
@ -35,12 +35,8 @@ class FrostedIce extends Ice{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -41,14 +41,9 @@ class Furnace extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->lit = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->lit);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->lit);
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{
|
||||
|
@ -26,7 +26,6 @@ namespace pocketmine\block;
|
||||
use pocketmine\block\tile\Hopper as TileHopper;
|
||||
use pocketmine\block\utils\PoweredByRedstoneTrait;
|
||||
use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\item\Item;
|
||||
@ -43,18 +42,9 @@ class Hopper extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::UP){
|
||||
throw new InvalidSerializedRuntimeDataException("Hopper may not face upward");
|
||||
}
|
||||
$this->facing = $facing;
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facingExcept($this->facing, Facing::UP);
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
|
||||
public function getFacing() : int{ return $this->facing; }
|
||||
|
@ -51,24 +51,15 @@ class ItemFrame extends Flowable{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->glowing = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->glowing);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->glowing);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
$this->hasMap = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
$w->writeBool($this->hasMap);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facing($this->facing);
|
||||
$w->bool($this->hasMap);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -46,12 +46,8 @@ class Lantern extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->hanging = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->hanging);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->hanging);
|
||||
}
|
||||
|
||||
public function isHanging() : bool{ return $this->hanging; }
|
||||
|
@ -50,14 +50,9 @@ class Leaves extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->noDecay = $r->readBool();
|
||||
$this->checkDecay = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->noDecay);
|
||||
$w->writeBool($this->checkDecay);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->noDecay);
|
||||
$w->bool($this->checkDecay);
|
||||
}
|
||||
|
||||
public function isNoDecay() : bool{ return $this->noDecay; }
|
||||
|
@ -49,14 +49,9 @@ class Lectern extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->producingSignal = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->producingSignal);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->producingSignal);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -47,14 +47,9 @@ class Lever extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readLeverFacing();
|
||||
$this->activated = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeLeverFacing($this->facing);
|
||||
$w->writeBool($this->activated);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->leverFacing($this->facing);
|
||||
$w->bool($this->activated);
|
||||
}
|
||||
|
||||
public function getFacing() : LeverFacing{ return $this->facing; }
|
||||
|
@ -37,12 +37,8 @@ final class Light extends Flowable{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->level = $r->readBoundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL);
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL, $this->level);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL, $this->level);
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{ return $this->level; }
|
||||
|
@ -51,16 +51,10 @@ abstract class Liquid extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->decay = $r->readBoundedInt(3, 0, self::MAX_DECAY);
|
||||
$this->falling = $r->readBool();
|
||||
$this->still = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, 0, self::MAX_DECAY, $this->decay);
|
||||
$w->writeBool($this->falling);
|
||||
$w->writeBool($this->still);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, 0, self::MAX_DECAY, $this->decay);
|
||||
$w->bool($this->falling);
|
||||
$w->bool($this->still);
|
||||
}
|
||||
|
||||
public function isFalling() : bool{ return $this->falling; }
|
||||
|
@ -37,12 +37,8 @@ class NetherPortal extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->axis = $r->readHorizontalAxis();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalAxis($this->axis);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalAxis($this->axis);
|
||||
}
|
||||
|
||||
public function getAxis() : int{
|
||||
|
@ -40,12 +40,8 @@ class NetherWartPlant extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(2, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\RailConnectionInfo;
|
||||
use pocketmine\data\bedrock\block\BlockLegacyMetadata;
|
||||
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\math\Facing;
|
||||
@ -38,16 +37,8 @@ class Rail extends BaseRail{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$railShape = $r->readInt(4);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$railShape]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$railShape])){
|
||||
throw new InvalidSerializedRuntimeDataException("Invalid rail shape $railShape");
|
||||
}
|
||||
$this->railShape = $railShape;
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeInt(4, $this->railShape);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->railShape($this->railShape);
|
||||
}
|
||||
|
||||
protected function setShapeFromConnections(array $connections) : void{
|
||||
|
@ -39,12 +39,8 @@ class RedMushroomBlock extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->mushroomBlockType = $r->readMushroomBlockType();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeMushroomBlockType($this->mushroomBlockType);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->mushroomBlockType($this->mushroomBlockType);
|
||||
}
|
||||
|
||||
public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; }
|
||||
|
@ -47,17 +47,10 @@ class RedstoneComparator extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->isSubtractMode = $r->readBool();
|
||||
$this->powered = $r->readBool();
|
||||
//TODO: this doesn't call the decoder from AnalogRedstoneSignalEmitter
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->isSubtractMode);
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->isSubtractMode);
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -32,12 +32,8 @@ class RedstoneLamp extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{
|
||||
|
@ -36,12 +36,8 @@ class RedstoneOre extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->lit = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->lit);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->lit);
|
||||
}
|
||||
|
||||
public function isLit() : bool{
|
||||
|
@ -46,16 +46,10 @@ class RedstoneRepeater extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 5; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->delay = $r->readBoundedInt(2, self::MIN_DELAY, self::MAX_DELAY);
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBoundedInt(2, self::MIN_DELAY, self::MAX_DELAY, $this->delay);
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->boundedInt(2, self::MIN_DELAY, self::MAX_DELAY, $this->delay);
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
|
||||
public function getDelay() : int{ return $this->delay; }
|
||||
|
@ -31,14 +31,9 @@ class RedstoneTorch extends Torch{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->lit = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
parent::encodeState($w);
|
||||
$w->writeBool($this->lit);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
parent::describeState($w);
|
||||
$w->bool($this->lit);
|
||||
}
|
||||
|
||||
public function isLit() : bool{
|
||||
|
@ -49,12 +49,8 @@ class Sapling extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->ready = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->ready);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->ready);
|
||||
}
|
||||
|
||||
public function isReady() : bool{ return $this->ready; }
|
||||
|
@ -41,14 +41,9 @@ class SeaPickle extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->count = $r->readBoundedInt(2, self::MIN_COUNT, self::MAX_COUNT);
|
||||
$this->underwater = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
|
||||
$w->writeBool($this->underwater);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
|
||||
$w->bool($this->underwater);
|
||||
}
|
||||
|
||||
public function getCount() : int{ return $this->count; }
|
||||
|
@ -37,11 +37,7 @@ class ShulkerBox extends Opaque{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 0; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
//NOOP - we don't read or write facing here, because the tile persists it
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
//NOOP - we don't read or write facing here, because the tile persists it
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,8 @@ abstract class SimplePressurePlate extends PressurePlate{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->pressed = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->pressed);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->pressed);
|
||||
}
|
||||
|
||||
public function isPressed() : bool{ return $this->pressed; }
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\tile\Skull as TileSkull;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\item\Item;
|
||||
@ -53,26 +52,14 @@ class Skull extends Flowable{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->skullType = $r->readSkullType();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeSkullType($this->skullType);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->skullType($this->skullType);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::DOWN){
|
||||
throw new InvalidSerializedRuntimeDataException("Skull may not face down");
|
||||
}
|
||||
$this->facing = $facing;
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facingExcept($this->facing, Facing::DOWN);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -44,12 +44,8 @@ class Slab extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->slabType = $r->readSlabType();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeSlabType($this->slabType);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->slabType($this->slabType);
|
||||
}
|
||||
|
||||
public function isTransparent() : bool{
|
||||
|
@ -49,12 +49,8 @@ class SnowLayer extends Flowable implements Fallable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->layers = $r->readBoundedInt(3, self::MIN_LAYERS, self::MAX_LAYERS);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, self::MIN_LAYERS, self::MAX_LAYERS, $this->layers);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, self::MIN_LAYERS, self::MAX_LAYERS, $this->layers);
|
||||
}
|
||||
|
||||
public function getLayers() : int{ return $this->layers; }
|
||||
|
@ -31,12 +31,8 @@ class Sponge extends Opaque{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->wet = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->wet);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->wet);
|
||||
}
|
||||
|
||||
public function isWet() : bool{ return $this->wet; }
|
||||
|
@ -49,14 +49,9 @@ class Stair extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->upsideDown = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->upsideDown);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->upsideDown);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : Block{
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\RailConnectionInfo;
|
||||
use pocketmine\data\bedrock\block\BlockLegacyMetadata;
|
||||
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use function array_keys;
|
||||
@ -40,16 +39,8 @@ class StraightOnlyRail extends BaseRail{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$railShape = $r->readInt(3);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$railShape])){
|
||||
throw new InvalidSerializedRuntimeDataException("No rail shape matches meta $railShape");
|
||||
}
|
||||
$this->railShape = $railShape;
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeInt(3, $this->railShape);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->straightOnlyRailShape($this->railShape);
|
||||
}
|
||||
|
||||
protected function setShapeFromConnections(array $connections) : void{
|
||||
|
@ -40,12 +40,8 @@ class Sugarcane extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(4, 0, self::MAX_AGE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
|
||||
}
|
||||
|
||||
private function grow() : bool{
|
||||
|
@ -48,12 +48,8 @@ class SweetBerryBush extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->age = $r->readBoundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE, $this->age);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE, $this->age);
|
||||
}
|
||||
|
||||
public function getAge() : int{ return $this->age; }
|
||||
|
@ -47,22 +47,14 @@ class TNT extends Opaque{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->worksUnderwater = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->worksUnderwater);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->worksUnderwater);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->unstable = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->unstable);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->unstable);
|
||||
}
|
||||
|
||||
public function isUnstable() : bool{ return $this->unstable; }
|
||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\item\Item;
|
||||
@ -40,16 +39,8 @@ class Torch extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$facing = $r->readFacing();
|
||||
if($facing === Facing::DOWN){
|
||||
throw new InvalidSerializedRuntimeDataException("Torch cannot have a DOWN facing");
|
||||
}
|
||||
$this->facing = $facing;
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facingExcept($this->facing, Facing::DOWN);
|
||||
}
|
||||
|
||||
public function getFacing() : int{ return $this->facing; }
|
||||
|
@ -43,16 +43,10 @@ class Trapdoor extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->top = $r->readBool();
|
||||
$this->open = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->top);
|
||||
$w->writeBool($this->open);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->top);
|
||||
$w->bool($this->open);
|
||||
}
|
||||
|
||||
public function isOpen() : bool{ return $this->open; }
|
||||
|
@ -36,18 +36,11 @@ class Tripwire extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->triggered = $r->readBool();
|
||||
$this->suspended = $r->readBool();
|
||||
$this->connected = $r->readBool();
|
||||
$this->disarmed = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->triggered);
|
||||
$w->writeBool($this->suspended);
|
||||
$w->writeBool($this->connected);
|
||||
$w->writeBool($this->disarmed);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->triggered);
|
||||
$w->bool($this->suspended);
|
||||
$w->bool($this->connected);
|
||||
$w->bool($this->disarmed);
|
||||
}
|
||||
|
||||
public function isTriggered() : bool{ return $this->triggered; }
|
||||
|
@ -41,16 +41,10 @@ class TripwireHook extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
$this->connected = $r->readBool();
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
$w->writeBool($this->connected);
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
$w->bool($this->connected);
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
|
||||
public function isConnected() : bool{ return $this->connected; }
|
||||
|
@ -36,14 +36,10 @@ class UnknownBlock extends Transparent{
|
||||
$this->stateData = $stateData;
|
||||
}
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
//use type instead of state, so we don't lose any information like colour
|
||||
//this might be an improperly registered plugin block
|
||||
$this->stateData = $r->readInt(Block::INTERNAL_STATE_DATA_BITS);
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeInt(Block::INTERNAL_STATE_DATA_BITS, $this->stateData);
|
||||
$w->int(Block::INTERNAL_STATE_DATA_BITS, $this->stateData);
|
||||
}
|
||||
|
||||
public function canBePlaced() : bool{
|
||||
|
@ -42,12 +42,8 @@ class Vine extends Flowable{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->faces = $r->readHorizontalFacingFlags();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacingFlags($this->faces);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacingFlags($this->faces);
|
||||
}
|
||||
|
||||
/** @return int[] */
|
||||
|
@ -45,14 +45,9 @@ class Wall extends Transparent{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 9; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->connections = $r->readWallConnections();
|
||||
$this->post = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeWallConnections($this->connections);
|
||||
$w->writeBool($this->post);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->wallConnections($this->connections);
|
||||
$w->bool($this->post);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,12 +39,8 @@ final class WallCoralFan extends BaseCoral{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
}
|
||||
|
||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
|
@ -41,12 +41,8 @@ class Wood extends Opaque{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->stripped = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->stripped);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->stripped);
|
||||
}
|
||||
|
||||
public function isStripped() : bool{ return $this->stripped; }
|
||||
|
@ -31,12 +31,8 @@ trait AnalogRedstoneSignalEmitterTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->signalStrength = $r->readBoundedInt(4, 0, 15);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, 15, $this->signalStrength);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, 15, $this->signalStrength);
|
||||
}
|
||||
|
||||
public function getOutputSignalStrength() : int{ return $this->signalStrength; }
|
||||
|
@ -32,12 +32,8 @@ trait AnyFacingTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readFacing();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->facing($this->facing);
|
||||
}
|
||||
|
||||
public function getFacing() : int{ return $this->facing; }
|
||||
|
@ -42,12 +42,8 @@ trait CandleTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->lit = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBool($this->lit);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->bool($this->lit);
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{
|
||||
|
@ -33,14 +33,9 @@ trait ColoredTrait{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 4; }
|
||||
|
||||
/** @see Block::decodeType() */
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->color = $r->readDyeColor();
|
||||
}
|
||||
|
||||
/** @see Block::encodeType() */
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeDyeColor($this->color);
|
||||
/** @see Block::describeType() */
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->dyeColor($this->color);
|
||||
}
|
||||
|
||||
public function getColor() : DyeColor{ return $this->color; }
|
||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\block\BlockBreakInfo;
|
||||
use pocketmine\block\BlockIdentifier;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\item\Axe;
|
||||
@ -36,18 +38,18 @@ use pocketmine\world\sound\ItemUseOnBlockSound;
|
||||
|
||||
trait CopperTrait{
|
||||
private CopperOxidation $oxidation;
|
||||
private bool $waxed;
|
||||
private bool $waxed = false;
|
||||
|
||||
public function __construct(BlockIdentifier $identifier, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->oxidation = CopperOxidation::NONE();
|
||||
parent::__construct($identifier, $name, $breakInfo);
|
||||
}
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 3; }
|
||||
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->oxidation = $r->readCopperOxidation();
|
||||
$this->waxed = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeCopperOxidation($this->oxidation);
|
||||
$w->writeBool($this->waxed);
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->copperOxidation($this->oxidation);
|
||||
$w->bool($this->waxed);
|
||||
}
|
||||
|
||||
public function getOxidation() : CopperOxidation{ return $this->oxidation; }
|
||||
|
@ -33,16 +33,10 @@ trait CoralTypeTrait{
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 4; }
|
||||
|
||||
/** @see Block::decodeType() */
|
||||
protected function decodeType(RuntimeDataReader $r) : void{
|
||||
$this->coralType = $r->readCoralType();
|
||||
$this->dead = $r->readBool();
|
||||
}
|
||||
|
||||
/** @see Block::encodeType() */
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeCoralType($this->coralType);
|
||||
$w->writeBool($this->dead);
|
||||
/** @see Block::describeType() */
|
||||
protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->coralType($this->coralType);
|
||||
$w->bool($this->dead);
|
||||
}
|
||||
|
||||
public function getCoralType() : CoralType{ return $this->coralType; }
|
||||
|
@ -33,12 +33,8 @@ trait HorizontalFacingTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->facing = $r->readHorizontalFacing();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeHorizontalFacing($this->facing);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->horizontalFacing($this->facing);
|
||||
}
|
||||
|
||||
public function getFacing() : int{ return $this->facing; }
|
||||
|
@ -38,12 +38,8 @@ trait PillarRotationTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 2; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->axis = $r->readAxis();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeAxis($this->axis);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->axis($this->axis);
|
||||
}
|
||||
|
||||
/** @see Axis */
|
||||
|
@ -31,13 +31,8 @@ trait RailPoweredByRedstoneTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
parent::decodeState($r);
|
||||
$this->powered = $r->readBool();
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
parent::encodeState($w);
|
||||
$w->writeBool($this->powered);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
parent::describeState($w);
|
||||
$w->bool($this->powered);
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,8 @@ trait SignLikeRotationTrait{
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeState(RuntimeDataReader $r) : void{
|
||||
$this->rotation = $r->readBoundedInt(4, 0, 15);
|
||||
}
|
||||
|
||||
protected function encodeState(RuntimeDataWriter $w) : void{
|
||||
$w->writeBoundedInt(4, 0, 15, $this->rotation);
|
||||
protected function describeState(RuntimeDataReader|RuntimeDataWriter $w) : void{
|
||||
$w->boundedInt(4, 0, 15, $this->rotation);
|
||||
}
|
||||
|
||||
public function getRotation() : int{ return $this->rotation; }
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\data\runtime;
|
||||
|
||||
use pocketmine\block\utils\BrewingStandSlot;
|
||||
use pocketmine\block\utils\RailConnectionInfo;
|
||||
use pocketmine\block\utils\WallConnectionType;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\Facing;
|
||||
@ -50,20 +51,28 @@ final class RuntimeDataReader{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function readBoundedInt(int $bits, int $min, int $max) : int{
|
||||
public function int(int $bits, int &$value) : void{
|
||||
$value = $this->readInt($bits);
|
||||
}
|
||||
|
||||
public function boundedInt(int $bits, int $min, int $max, int &$value) : void{
|
||||
$result = $this->readInt($bits) + $min;
|
||||
if($result < $min || $result > $max){
|
||||
throw new InvalidSerializedRuntimeDataException("Value is outside the range $min - $max");
|
||||
}
|
||||
return $result;
|
||||
$value = $result;
|
||||
}
|
||||
|
||||
public function readBool() : bool{
|
||||
protected function readBool() : bool{
|
||||
return $this->readInt(1) === 1;
|
||||
}
|
||||
|
||||
public function readHorizontalFacing() : int{
|
||||
return match($this->readInt(2)){
|
||||
public function bool(bool &$value) : void{
|
||||
$value = $this->readBool();
|
||||
}
|
||||
|
||||
public function horizontalFacing(int &$facing) : void{
|
||||
$facing = match($this->readInt(2)){
|
||||
0 => Facing::NORTH,
|
||||
1 => Facing::EAST,
|
||||
2 => Facing::SOUTH,
|
||||
@ -73,9 +82,9 @@ final class RuntimeDataReader{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
* @param int[] $faces
|
||||
*/
|
||||
public function readHorizontalFacingFlags() : array{
|
||||
public function horizontalFacingFlags(array &$faces) : void{
|
||||
$result = [];
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
if($this->readBool()){
|
||||
@ -83,11 +92,11 @@ final class RuntimeDataReader{
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
$faces = $result;
|
||||
}
|
||||
|
||||
public function readFacing() : int{
|
||||
return match($this->readInt(3)){
|
||||
public function facing(int &$facing) : void{
|
||||
$facing = match($this->readInt(3)){
|
||||
0 => Facing::DOWN,
|
||||
1 => Facing::UP,
|
||||
2 => Facing::NORTH,
|
||||
@ -98,8 +107,18 @@ final class RuntimeDataReader{
|
||||
};
|
||||
}
|
||||
|
||||
public function readAxis() : int{
|
||||
return match($this->readInt(2)){
|
||||
public function facingExcept(int &$facing, int $except) : void{
|
||||
$result = 0;
|
||||
$this->facing($result);
|
||||
if($result === $except){
|
||||
throw new InvalidSerializedRuntimeDataException("Illegal facing value");
|
||||
}
|
||||
|
||||
$facing = $result;
|
||||
}
|
||||
|
||||
public function axis(int &$axis) : void{
|
||||
$axis = match($this->readInt(2)){
|
||||
0 => Axis::X,
|
||||
1 => Axis::Z,
|
||||
2 => Axis::Y,
|
||||
@ -107,8 +126,8 @@ final class RuntimeDataReader{
|
||||
};
|
||||
}
|
||||
|
||||
public function readHorizontalAxis() : int{
|
||||
return match($this->readInt(1)){
|
||||
public function horizontalAxis(int &$axis) : void{
|
||||
$axis = match($this->readInt(1)){
|
||||
0 => Axis::X,
|
||||
1 => Axis::Z,
|
||||
default => throw new AssumptionFailedError("Unreachable")
|
||||
@ -116,16 +135,17 @@ final class RuntimeDataReader{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WallConnectionType[]
|
||||
* @phpstan-return array<Facing::NORTH|Facing::EAST|Facing::SOUTH|Facing::WEST, WallConnectionType>
|
||||
* @param WallConnectionType[] $connections
|
||||
* @phpstan-param array<Facing::NORTH|Facing::EAST|Facing::SOUTH|Facing::WEST, WallConnectionType> $connections
|
||||
*/
|
||||
public function readWallConnections() : array{
|
||||
$connections = [];
|
||||
public function wallConnections(array &$connections) : void{
|
||||
$result = [];
|
||||
//TODO: we can pack this into 7 bits instead of 8
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$type = $this->readBoundedInt(2, 0, 2);
|
||||
$type = 0;
|
||||
$this->boundedInt(2, 0, 2, $type);
|
||||
if($type !== 0){
|
||||
$connections[$facing] = match($type){
|
||||
$result[$facing] = match($type){
|
||||
1 => WallConnectionType::SHORT(),
|
||||
2 => WallConnectionType::TALL(),
|
||||
default => throw new AssumptionFailedError("Unreachable")
|
||||
@ -133,14 +153,14 @@ final class RuntimeDataReader{
|
||||
}
|
||||
}
|
||||
|
||||
return $connections;
|
||||
$connections = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BrewingStandSlot[]
|
||||
* @phpstan-return array<int, BrewingStandSlot>
|
||||
* @param BrewingStandSlot[] $slots
|
||||
* @phpstan-param array<int, BrewingStandSlot> $slots
|
||||
*/
|
||||
public function readBrewingStandSlots() : array{
|
||||
public function brewingStandSlots(array &$slots) : void{
|
||||
$result = [];
|
||||
foreach([
|
||||
BrewingStandSlot::EAST(),
|
||||
@ -152,7 +172,25 @@ final class RuntimeDataReader{
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
$slots = $result;
|
||||
}
|
||||
|
||||
public function railShape(int &$railShape) : void{
|
||||
$result = $this->readInt(4);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$result]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$result])){
|
||||
throw new InvalidSerializedRuntimeDataException("Invalid rail shape $result");
|
||||
}
|
||||
|
||||
$railShape = $result;
|
||||
}
|
||||
|
||||
public function straightOnlyRailShape(int &$railShape) : void{
|
||||
$result = $this->readInt(3);
|
||||
if(!isset(RailConnectionInfo::CONNECTIONS[$result])){
|
||||
throw new InvalidSerializedRuntimeDataException("No rail shape matches meta $result");
|
||||
}
|
||||
|
||||
$railShape = $result;
|
||||
}
|
||||
|
||||
public function getOffset() : int{ return $this->offset; }
|
||||
|
@ -40,8 +40,7 @@ final class RuntimeDataWriter{
|
||||
private int $maxBits
|
||||
){}
|
||||
|
||||
/** @return $this */
|
||||
public function writeInt(int $bits, int $value) : self{
|
||||
public function int(int $bits, int $value) : void{
|
||||
if($this->offset + $bits > $this->maxBits){
|
||||
throw new \InvalidArgumentException("Bit buffer cannot be larger than $this->maxBits bits (already have $this->offset bits)");
|
||||
}
|
||||
@ -51,27 +50,21 @@ final class RuntimeDataWriter{
|
||||
|
||||
$this->value |= ($value << $this->offset);
|
||||
$this->offset += $bits;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return $this */
|
||||
public function writeBoundedInt(int $bits, int $min, int $max, int $value) : self{
|
||||
public function boundedInt(int $bits, int $min, int $max, int $value) : void{
|
||||
if($value < $min || $value > $max){
|
||||
throw new \InvalidArgumentException("Value $value is outside the range $min - $max");
|
||||
}
|
||||
$this->writeInt($bits, $value - $min);
|
||||
return $this;
|
||||
$this->int($bits, $value - $min);
|
||||
}
|
||||
|
||||
/** @return $this */
|
||||
public function writeBool(bool $value) : self{
|
||||
return $this->writeInt(1, $value ? 1 : 0);
|
||||
public function bool(bool $value) : void{
|
||||
$this->int(1, $value ? 1 : 0);
|
||||
}
|
||||
|
||||
/** @return $this */
|
||||
public function writeHorizontalFacing(int $facing) : self{
|
||||
return $this->writeInt(2, match($facing){
|
||||
public function horizontalFacing(int $facing) : void{
|
||||
$this->int(2, match($facing){
|
||||
Facing::NORTH => 0,
|
||||
Facing::EAST => 1,
|
||||
Facing::SOUTH => 2,
|
||||
@ -82,20 +75,16 @@ final class RuntimeDataWriter{
|
||||
|
||||
/**
|
||||
* @param int[] $faces
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function writeHorizontalFacingFlags(array $faces) : self{
|
||||
public function horizontalFacingFlags(array $faces) : void{
|
||||
$uniqueFaces = array_flip($faces);
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$this->writeBool(isset($uniqueFaces[$facing]));
|
||||
$this->bool(isset($uniqueFaces[$facing]));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function writeFacing(int $facing) : self{
|
||||
return $this->writeInt(3, match($facing){
|
||||
public function facing(int $facing) : void{
|
||||
$this->int(3, match($facing){
|
||||
0 => Facing::DOWN,
|
||||
1 => Facing::UP,
|
||||
2 => Facing::NORTH,
|
||||
@ -106,8 +95,12 @@ final class RuntimeDataWriter{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeAxis(int $axis) : self{
|
||||
return $this->writeInt(2, match($axis){
|
||||
public function facingExcept(int $facing, int $except) : void{
|
||||
$this->facing($facing);
|
||||
}
|
||||
|
||||
public function axis(int $axis) : void{
|
||||
$this->int(2, match($axis){
|
||||
Axis::X => 0,
|
||||
Axis::Z => 1,
|
||||
Axis::Y => 2,
|
||||
@ -115,8 +108,8 @@ final class RuntimeDataWriter{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeHorizontalAxis(int $axis) : self{
|
||||
return $this->writeInt(1, match($axis){
|
||||
public function horizontalAxis(int $axis) : void{
|
||||
$this->int(1, match($axis){
|
||||
Axis::X => 0,
|
||||
Axis::Z => 1,
|
||||
default => throw new \InvalidArgumentException("Invalid horizontal axis $axis")
|
||||
@ -127,36 +120,38 @@ final class RuntimeDataWriter{
|
||||
* @param WallConnectionType[] $connections
|
||||
* @phpstan-param array<Facing::NORTH|Facing::EAST|Facing::SOUTH|Facing::WEST, WallConnectionType> $connections
|
||||
*/
|
||||
public function writeWallConnections(array $connections) : self{
|
||||
public function wallConnections(array $connections) : void{
|
||||
//TODO: we can pack this into 7 bits instead of 8
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$this->writeBoundedInt(2, 0, 2, match($connections[$facing] ?? null){
|
||||
$this->boundedInt(2, 0, 2, match($connections[$facing] ?? null){
|
||||
null => 0,
|
||||
WallConnectionType::SHORT() => 1,
|
||||
WallConnectionType::TALL() => 2,
|
||||
default => throw new AssumptionFailedError("Unreachable")
|
||||
});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BrewingStandSlot[] $slots
|
||||
* @phpstan-param array<int, BrewingStandSlot> $slots
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function writeBrewingStandSlots(array $slots) : self{
|
||||
public function brewingStandSlots(array $slots) : void{
|
||||
foreach([
|
||||
BrewingStandSlot::EAST(),
|
||||
BrewingStandSlot::NORTHWEST(),
|
||||
BrewingStandSlot::SOUTHWEST(),
|
||||
] as $member){
|
||||
$this->writeBool(isset($slots[$member->id()]));
|
||||
$this->bool(isset($slots[$member->id()]));
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
public function railShape(int $railShape) : void{
|
||||
$this->int(4, $railShape);
|
||||
}
|
||||
|
||||
public function straightOnlyRailShape(int $railShape) : void{
|
||||
$this->int(3, $railShape);
|
||||
}
|
||||
|
||||
public function getValue() : int{ return $this->value; }
|
||||
|
@ -29,10 +29,10 @@ namespace pocketmine\data\runtime;
|
||||
*/
|
||||
trait RuntimeEnumDeserializerTrait{
|
||||
|
||||
abstract public function readInt(int $bits) : int;
|
||||
abstract protected function readInt(int $bits) : int;
|
||||
|
||||
public function readBellAttachmentType() : \pocketmine\block\utils\BellAttachmentType{
|
||||
return match($this->readInt(2)){
|
||||
public function bellAttachmentType(\pocketmine\block\utils\BellAttachmentType &$value) : void{
|
||||
$value = match($this->readInt(2)){
|
||||
0 => \pocketmine\block\utils\BellAttachmentType::CEILING(),
|
||||
1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(),
|
||||
2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(),
|
||||
@ -41,8 +41,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readCopperOxidation() : \pocketmine\block\utils\CopperOxidation{
|
||||
return match($this->readInt(2)){
|
||||
public function copperOxidation(\pocketmine\block\utils\CopperOxidation &$value) : void{
|
||||
$value = match($this->readInt(2)){
|
||||
0 => \pocketmine\block\utils\CopperOxidation::EXPOSED(),
|
||||
1 => \pocketmine\block\utils\CopperOxidation::NONE(),
|
||||
2 => \pocketmine\block\utils\CopperOxidation::OXIDIZED(),
|
||||
@ -51,8 +51,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readCoralType() : \pocketmine\block\utils\CoralType{
|
||||
return match($this->readInt(3)){
|
||||
public function coralType(\pocketmine\block\utils\CoralType &$value) : void{
|
||||
$value = match($this->readInt(3)){
|
||||
0 => \pocketmine\block\utils\CoralType::BRAIN(),
|
||||
1 => \pocketmine\block\utils\CoralType::BUBBLE(),
|
||||
2 => \pocketmine\block\utils\CoralType::FIRE(),
|
||||
@ -62,8 +62,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readDyeColor() : \pocketmine\block\utils\DyeColor{
|
||||
return match($this->readInt(4)){
|
||||
public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{
|
||||
$value = match($this->readInt(4)){
|
||||
0 => \pocketmine\block\utils\DyeColor::BLACK(),
|
||||
1 => \pocketmine\block\utils\DyeColor::BLUE(),
|
||||
2 => \pocketmine\block\utils\DyeColor::BROWN(),
|
||||
@ -84,8 +84,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readLeverFacing() : \pocketmine\block\utils\LeverFacing{
|
||||
return match($this->readInt(3)){
|
||||
public function leverFacing(\pocketmine\block\utils\LeverFacing &$value) : void{
|
||||
$value = match($this->readInt(3)){
|
||||
0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(),
|
||||
1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(),
|
||||
2 => \pocketmine\block\utils\LeverFacing::EAST(),
|
||||
@ -98,8 +98,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readMushroomBlockType() : \pocketmine\block\utils\MushroomBlockType{
|
||||
return match($this->readInt(4)){
|
||||
public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType &$value) : void{
|
||||
$value = match($this->readInt(4)){
|
||||
0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(),
|
||||
1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(),
|
||||
2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(),
|
||||
@ -115,8 +115,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readPotionType() : \pocketmine\item\PotionType{
|
||||
return match($this->readInt(6)){
|
||||
public function potionType(\pocketmine\item\PotionType &$value) : void{
|
||||
$value = match($this->readInt(6)){
|
||||
0 => \pocketmine\item\PotionType::AWKWARD(),
|
||||
1 => \pocketmine\item\PotionType::FIRE_RESISTANCE(),
|
||||
2 => \pocketmine\item\PotionType::HARMING(),
|
||||
@ -163,8 +163,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readSkullType() : \pocketmine\block\utils\SkullType{
|
||||
return match($this->readInt(3)){
|
||||
public function skullType(\pocketmine\block\utils\SkullType &$value) : void{
|
||||
$value = match($this->readInt(3)){
|
||||
0 => \pocketmine\block\utils\SkullType::CREEPER(),
|
||||
1 => \pocketmine\block\utils\SkullType::DRAGON(),
|
||||
2 => \pocketmine\block\utils\SkullType::PLAYER(),
|
||||
@ -175,8 +175,8 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function readSlabType() : \pocketmine\block\utils\SlabType{
|
||||
return match($this->readInt(2)){
|
||||
public function slabType(\pocketmine\block\utils\SlabType &$value) : void{
|
||||
$value = match($this->readInt(2)){
|
||||
0 => \pocketmine\block\utils\SlabType::BOTTOM(),
|
||||
1 => \pocketmine\block\utils\SlabType::DOUBLE(),
|
||||
2 => \pocketmine\block\utils\SlabType::TOP(),
|
||||
|
@ -29,10 +29,10 @@ namespace pocketmine\data\runtime;
|
||||
*/
|
||||
trait RuntimeEnumSerializerTrait{
|
||||
|
||||
abstract public function writeInt(int $bits, int $value) : self;
|
||||
abstract public function int(int $bits, int $value) : void;
|
||||
|
||||
public function writeBellAttachmentType(\pocketmine\block\utils\BellAttachmentType $value) : void{
|
||||
$this->writeInt(2, match($value){
|
||||
public function bellAttachmentType(\pocketmine\block\utils\BellAttachmentType $value) : void{
|
||||
$this->int(2, match($value){
|
||||
\pocketmine\block\utils\BellAttachmentType::CEILING() => 0,
|
||||
\pocketmine\block\utils\BellAttachmentType::FLOOR() => 1,
|
||||
\pocketmine\block\utils\BellAttachmentType::ONE_WALL() => 2,
|
||||
@ -41,8 +41,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeCopperOxidation(\pocketmine\block\utils\CopperOxidation $value) : void{
|
||||
$this->writeInt(2, match($value){
|
||||
public function copperOxidation(\pocketmine\block\utils\CopperOxidation $value) : void{
|
||||
$this->int(2, match($value){
|
||||
\pocketmine\block\utils\CopperOxidation::EXPOSED() => 0,
|
||||
\pocketmine\block\utils\CopperOxidation::NONE() => 1,
|
||||
\pocketmine\block\utils\CopperOxidation::OXIDIZED() => 2,
|
||||
@ -51,8 +51,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeCoralType(\pocketmine\block\utils\CoralType $value) : void{
|
||||
$this->writeInt(3, match($value){
|
||||
public function coralType(\pocketmine\block\utils\CoralType $value) : void{
|
||||
$this->int(3, match($value){
|
||||
\pocketmine\block\utils\CoralType::BRAIN() => 0,
|
||||
\pocketmine\block\utils\CoralType::BUBBLE() => 1,
|
||||
\pocketmine\block\utils\CoralType::FIRE() => 2,
|
||||
@ -62,8 +62,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeDyeColor(\pocketmine\block\utils\DyeColor $value) : void{
|
||||
$this->writeInt(4, match($value){
|
||||
public function dyeColor(\pocketmine\block\utils\DyeColor $value) : void{
|
||||
$this->int(4, match($value){
|
||||
\pocketmine\block\utils\DyeColor::BLACK() => 0,
|
||||
\pocketmine\block\utils\DyeColor::BLUE() => 1,
|
||||
\pocketmine\block\utils\DyeColor::BROWN() => 2,
|
||||
@ -84,8 +84,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeLeverFacing(\pocketmine\block\utils\LeverFacing $value) : void{
|
||||
$this->writeInt(3, match($value){
|
||||
public function leverFacing(\pocketmine\block\utils\LeverFacing $value) : void{
|
||||
$this->int(3, match($value){
|
||||
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0,
|
||||
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1,
|
||||
\pocketmine\block\utils\LeverFacing::EAST() => 2,
|
||||
@ -98,8 +98,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeMushroomBlockType(\pocketmine\block\utils\MushroomBlockType $value) : void{
|
||||
$this->writeInt(4, match($value){
|
||||
public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType $value) : void{
|
||||
$this->int(4, match($value){
|
||||
\pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0,
|
||||
\pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1,
|
||||
\pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE() => 2,
|
||||
@ -115,8 +115,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writePotionType(\pocketmine\item\PotionType $value) : void{
|
||||
$this->writeInt(6, match($value){
|
||||
public function potionType(\pocketmine\item\PotionType $value) : void{
|
||||
$this->int(6, match($value){
|
||||
\pocketmine\item\PotionType::AWKWARD() => 0,
|
||||
\pocketmine\item\PotionType::FIRE_RESISTANCE() => 1,
|
||||
\pocketmine\item\PotionType::HARMING() => 2,
|
||||
@ -163,8 +163,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeSkullType(\pocketmine\block\utils\SkullType $value) : void{
|
||||
$this->writeInt(3, match($value){
|
||||
public function skullType(\pocketmine\block\utils\SkullType $value) : void{
|
||||
$this->int(3, match($value){
|
||||
\pocketmine\block\utils\SkullType::CREEPER() => 0,
|
||||
\pocketmine\block\utils\SkullType::DRAGON() => 1,
|
||||
\pocketmine\block\utils\SkullType::PLAYER() => 2,
|
||||
@ -175,8 +175,8 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function writeSlabType(\pocketmine\block\utils\SlabType $value) : void{
|
||||
$this->writeInt(2, match($value){
|
||||
public function slabType(\pocketmine\block\utils\SlabType $value) : void{
|
||||
$this->int(2, match($value){
|
||||
\pocketmine\block\utils\SlabType::BOTTOM() => 0,
|
||||
\pocketmine\block\utils\SlabType::DOUBLE() => 1,
|
||||
\pocketmine\block\utils\SlabType::TOP() => 2,
|
||||
|
@ -64,7 +64,7 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeDyeColor($this->color);
|
||||
$w->dyeColor($this->color);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ use pocketmine\math\Facing;
|
||||
|
||||
final class CoralFan extends Item{
|
||||
use CoralTypeTrait {
|
||||
encodeType as encodeCoralType;
|
||||
describeType as encodeCoralType;
|
||||
}
|
||||
|
||||
public function __construct(ItemIdentifier $identifier){
|
||||
|
@ -35,7 +35,7 @@ class Dye extends Item{
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeDyeColor($this->color);
|
||||
$w->dyeColor($this->color);
|
||||
}
|
||||
|
||||
public function getColor() : DyeColor{
|
||||
|
@ -45,7 +45,7 @@ final class ItemBlock extends Item{
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writeInt(Block::INTERNAL_STATE_DATA_BITS, $this->blockTypeData);
|
||||
$w->int(Block::INTERNAL_STATE_DATA_BITS, $this->blockTypeData);
|
||||
}
|
||||
|
||||
public function getBlock(?int $clickedFace = null) : Block{
|
||||
|
@ -37,7 +37,7 @@ class Potion extends Item implements ConsumableItem{
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writePotionType($this->potionType);
|
||||
$w->potionType($this->potionType);
|
||||
}
|
||||
|
||||
public function getType() : PotionType{ return $this->potionType; }
|
||||
|
@ -39,7 +39,7 @@ class SplashPotion extends ProjectileItem{
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->writePotionType($this->potionType);
|
||||
$w->potionType($this->potionType);
|
||||
}
|
||||
|
||||
public function getType() : PotionType{ return $this->potionType; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user