Revert "Block: Get rid of state bitmasks"

This reverts commit b7b05e729e4fcfbe74786342882d011f004658fa.

Apparently this was premature, because we still need these things to deal with default state remapping.
This commit is contained in:
Dylan K. Taylor 2019-02-24 18:30:18 +00:00
parent 6cb263fcca
commit 0f7f5362b8
53 changed files with 251 additions and 14 deletions

View File

@ -50,7 +50,11 @@ class Anvil extends Transparent implements Fallable{
} }
public function readStateFromData(int $id, int $stateMeta) : void{ public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta);
}
public function getStateBitmask() : int{
return 0b11;
} }
public function getHardness() : float{ public function getHardness() : float{

View File

@ -95,6 +95,10 @@ abstract class BaseRail extends Flowable{
$this->connections = $connections; $this->connections = $connections;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.7; return 0.7;
} }

View File

@ -68,6 +68,10 @@ class Bed extends Transparent{
$this->head = ($stateMeta & self::BITFLAG_HEAD) !== 0; $this->head = ($stateMeta & self::BITFLAG_HEAD) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();
//read extra state information from the tile - this is an ugly hack //read extra state information from the tile - this is an ugly hack

View File

@ -43,6 +43,8 @@ use pocketmine\Player;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\tile\TileFactory; use pocketmine\tile\TileFactory;
use function array_merge; use function array_merge;
use function assert;
use function dechex;
use function get_class; use function get_class;
use const PHP_INT_MAX; use const PHP_INT_MAX;
@ -80,6 +82,9 @@ class Block extends Position implements BlockIds, Metadatable{
* @param string $name English name of the block type (TODO: implement translations) * @param string $name English name of the block type (TODO: implement translations)
*/ */
public function __construct(BlockIdentifier $idInfo, string $name){ public function __construct(BlockIdentifier $idInfo, string $name){
if(($idInfo->getVariant() & $this->getStateBitmask()) !== 0){
throw new \InvalidArgumentException("Variant 0x" . dechex($idInfo->getVariant()) . " collides with state bitmask 0x" . dechex($this->getStateBitmask()));
}
$this->idInfo = $idInfo; $this->idInfo = $idInfo;
$this->fallbackName = $name; $this->fallbackName = $name;
} }
@ -118,7 +123,9 @@ class Block extends Position implements BlockIds, Metadatable{
* @return int * @return int
*/ */
public function getDamage() : int{ public function getDamage() : int{
return $this->idInfo->getVariant() | $this->writeStateToMeta(); $stateMeta = $this->writeStateToMeta();
assert(($stateMeta & ~$this->getStateBitmask()) === 0);
return $this->idInfo->getVariant() | $stateMeta;
} }
protected function writeStateToMeta() : int{ protected function writeStateToMeta() : int{
@ -161,6 +168,15 @@ class Block extends Position implements BlockIds, Metadatable{
} }
} }
/**
* Returns a bitmask used to extract state bits from block metadata.
*
* @return int
*/
public function getStateBitmask() : int{
return 0;
}
/** /**
* Returns whether the given block has an equivalent type to this one. This compares base legacy ID and variant. * Returns whether the given block has an equivalent type to this one. This compares base legacy ID and variant.
* *

View File

@ -527,17 +527,20 @@ class BlockFactory{
* $override parameter. * $override parameter.
*/ */
public static function register(Block $block, bool $override = false) : void{ public static function register(Block $block, bool $override = false) : void{
foreach($block->getIdInfo()->getAllBlockIds() as $id){ $variant = $block->getIdInfo()->getVariant();
for($m = 0; $m < 16; ++$m){
$index = ($id << 4) | $m;
$v = clone $block; $stateMask = $block->getStateBitmask();
try{ if(($variant & $stateMask) !== 0){
$v->readStateFromData($id, $m); throw new \InvalidArgumentException("Block variant collides with state bitmask");
if($v->getDamage() !== $m){
throw new InvalidBlockStateException("Corrupted meta"); //don't register anything that isn't the same when we read it back again
} }
}catch(InvalidBlockStateException $e){ //invalid property combination
foreach($block->getIdInfo()->getAllBlockIds() as $id){
if(!$override and self::isRegistered($id, $variant)){
throw new \InvalidArgumentException("Block registration $id:$variant conflicts with an existing block");
}
for($m = $variant; $m <= ($variant | $stateMask); ++$m){
if(($m & ~$stateMask) !== $variant){
continue; continue;
} }
@ -545,10 +548,21 @@ class BlockFactory{
throw new \InvalidArgumentException("Block registration " . get_class($block) . " has states which conflict with other blocks"); throw new \InvalidArgumentException("Block registration " . get_class($block) . " has states which conflict with other blocks");
} }
$index = ($id << 4) | $m;
$v = clone $block;
try{
$v->readStateFromData($id, $m & $stateMask);
if($v->getDamage() !== $m){
throw new InvalidBlockStateException("Corrupted meta"); //don't register anything that isn't the same when we read it back again
}
}catch(InvalidBlockStateException $e){ //invalid property combination
continue;
}
self::fillStaticArrays($index, $v); self::fillStaticArrays($index, $v);
} }
$variant = $block->getIdInfo()->getVariant();
if(!self::isRegistered($id, $variant)){ if(!self::isRegistered($id, $variant)){
self::fillStaticArrays(($id << 4) | $variant, $block); //register default state mapped to variant, for blocks which don't use 0 as valid state self::fillStaticArrays(($id << 4) | $variant, $block); //register default state mapped to variant, for blocks which don't use 0 as valid state
} }

View File

@ -44,6 +44,10 @@ class BrewingStand extends Transparent{
$this->northwestSlot = ($stateMeta & 0x04) !== 0; $this->northwestSlot = ($stateMeta & 0x04) !== 0;
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }

View File

@ -47,6 +47,10 @@ abstract class Button extends Flowable{
$this->powered = ($stateMeta & 0x08) !== 0; $this->powered = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
//TODO: check valid target block //TODO: check valid target block
$this->facing = $face; $this->facing = $face;

View File

@ -47,6 +47,10 @@ class Cactus extends Transparent{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15);
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.4; return 0.4;
} }

View File

@ -46,6 +46,10 @@ class Cake extends Transparent implements FoodSource{
$this->bites = BlockDataValidator::readBoundedInt("bites", $stateMeta, 0, 6); $this->bites = BlockDataValidator::readBoundedInt("bites", $stateMeta, 0, 6);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }

View File

@ -44,6 +44,10 @@ class Chest extends Transparent{
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 2.5; return 2.5;
} }

View File

@ -51,6 +51,10 @@ class CocoaBlock extends Transparent{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta >> 2, 0, 2); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta >> 2, 0, 2);
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.2; return 0.2;
} }

View File

@ -44,6 +44,10 @@ abstract class Crops extends Flowable{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 7); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 7);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($blockReplace->getSide(Facing::DOWN)->getId() === Block::FARMLAND){ if($blockReplace->getSide(Facing::DOWN)->getId() === Block::FARMLAND){
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);

View File

@ -57,6 +57,10 @@ class DaylightSensor extends Transparent{
$this->inverted = $id === $this->idInfo->getSecondId(); $this->inverted = $id === $this->idInfo->getSecondId();
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function isInverted() : bool{ public function isInverted() : bool{
return $this->inverted; return $this->inverted;
} }

View File

@ -67,6 +67,10 @@ abstract class Door extends Transparent{
} }
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();

View File

@ -43,6 +43,10 @@ class DoublePlant extends Flowable{
$this->top = ($stateMeta & self::BITFLAG_TOP) !== 0; $this->top = ($stateMeta & self::BITFLAG_TOP) !== 0;
} }
public function getStateBitmask() : int{
return 0b1000;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$id = $blockReplace->getSide(Facing::DOWN)->getId(); $id = $blockReplace->getSide(Facing::DOWN)->getId();
if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){ if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){

View File

@ -47,6 +47,10 @@ class EndPortalFrame extends Solid{
$this->eye = ($stateMeta & 0x04) !== 0; $this->eye = ($stateMeta & 0x04) !== 0;
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getLightLevel() : int{ public function getLightLevel() : int{
return 1; return 1;
} }

View File

@ -50,6 +50,10 @@ class EndRod extends Flowable{
$this->facing = BlockDataValidator::readFacing($stateMeta); $this->facing = BlockDataValidator::readFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->facing = $face; $this->facing = $face;
if($blockClicked instanceof EndRod and $blockClicked->facing === $this->facing){ if($blockClicked instanceof EndRod and $blockClicked->facing === $this->facing){

View File

@ -42,6 +42,10 @@ class Farmland extends Transparent{
$this->wetness = BlockDataValidator::readBoundedInt("wetness", $stateMeta, 0, 7); $this->wetness = BlockDataValidator::readBoundedInt("wetness", $stateMeta, 0, 7);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.6; return 0.6;
} }

View File

@ -50,6 +50,10 @@ class FenceGate extends Transparent{
$this->inWall = ($stateMeta & 0x08) !== 0; $this->inWall = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 2; return 2;
} }

View File

@ -48,6 +48,10 @@ class Fire extends Flowable{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15);
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function hasEntityCollision() : bool{ public function hasEntityCollision() : bool{
return true; return true;
} }

View File

@ -43,6 +43,10 @@ class FlowerPot extends Flowable{
$this->occupied = $stateMeta !== 0; $this->occupied = $stateMeta !== 0;
} }
public function getStateBitmask() : int{
return 0b1111; //vanilla uses various values, we only care about 1 and 0 for PE
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8); return AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8);
} }

View File

@ -53,6 +53,10 @@ class Furnace extends Solid{
$this->lit = $id === $this->idInfo->getSecondId(); $this->lit = $id === $this->idInfo->getSecondId();
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 3.5; return 3.5;
} }

View File

@ -44,6 +44,10 @@ class GlazedTerracotta extends Solid{
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getHardness() : float{ public function getHardness() : float{
return 1.4; return 1.4;
} }

View File

@ -77,6 +77,10 @@ class ItemFrame extends Flowable{
} }
} }
public function getStateBitmask() : int{
return 0b111;
}
/** /**
* @return int * @return int
*/ */

View File

@ -44,6 +44,10 @@ class Ladder extends Transparent{
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function hasEntityCollision() : bool{ public function hasEntityCollision() : bool{
return true; return true;
} }

View File

@ -56,6 +56,10 @@ class Leaves extends Transparent{
$this->checkDecay = ($stateMeta & 0x08) !== 0; $this->checkDecay = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1100;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.2; return 0.2;
} }

View File

@ -69,6 +69,10 @@ class Lever extends Flowable{
$this->powered = ($stateMeta & 0x08) !== 0; $this->powered = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }

View File

@ -77,6 +77,10 @@ abstract class Liquid extends Transparent{
$this->still = $id === $this->idInfo->getSecondId(); $this->still = $id === $this->idInfo->getSecondId();
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function hasEntityCollision() : bool{ public function hasEntityCollision() : bool{
return true; return true;
} }

View File

@ -44,6 +44,10 @@ class NetherReactor extends Solid{
$this->state = BlockDataValidator::readBoundedInt("state", $stateMeta, 0, 2); $this->state = BlockDataValidator::readBoundedInt("state", $stateMeta, 0, 2);
} }
public function getStateBitmask() : int{
return 0b11;
}
public function getToolType() : int{ public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE; return BlockToolType::TYPE_PICKAXE;
} }

View File

@ -45,6 +45,10 @@ class NetherWartPlant extends Flowable{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 3); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 3);
} }
public function getStateBitmask() : int{
return 0b11;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === Block::SOUL_SAND){ if($down->getId() === Block::SOUL_SAND){

View File

@ -43,6 +43,10 @@ class Pumpkin extends Solid{
return Bearing::fromFacing($this->facing); return Bearing::fromFacing($this->facing);
} }
public function getStateBitmask() : int{
return 0b11;
}
public function getHardness() : float{ public function getHardness() : float{
return 1; return 1;
} }

View File

@ -45,6 +45,10 @@ class RedMushroomBlock extends Solid{
$this->rotationData = $stateMeta; $this->rotationData = $stateMeta;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.2; return 0.2;
} }

View File

@ -60,6 +60,10 @@ class RedstoneRepeater extends Flowable{
return Bearing::fromFacing($this->facing) | (($this->delay - 1) << 2); return Bearing::fromFacing($this->facing) | (($this->delay - 1) << 2);
} }
public function getStateBitmask() : int{
return 0b1111;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()->trim(Facing::UP, 7 / 8); return AxisAlignedBB::one()->trim(Facing::UP, 7 / 8);
} }

View File

@ -38,6 +38,10 @@ class RedstoneWire extends Flowable{
return $this->power; return $this->power;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();
//TODO: check connections to nearby redstone components //TODO: check connections to nearby redstone components

View File

@ -53,6 +53,10 @@ class Sapling extends Flowable{
$this->ready = ($stateMeta & 0x08) !== 0; $this->ready = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1000;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN); $down = $this->getSide(Facing::DOWN);
if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){

View File

@ -43,6 +43,10 @@ class SignPost extends Transparent{
$this->rotation = $stateMeta; $this->rotation = $stateMeta;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 1; return 1;
} }

View File

@ -35,4 +35,8 @@ abstract class SimplePressurePlate extends PressurePlate{
public function readStateFromData(int $id, int $stateMeta) : void{ public function readStateFromData(int $id, int $stateMeta) : void{
$this->powered = $stateMeta !== 0; $this->powered = $stateMeta !== 0;
} }
public function getStateBitmask() : int{
return 0b1;
}
} }

View File

@ -50,6 +50,10 @@ class Skull extends Flowable{
$this->facing = $stateMeta === 1 ? Facing::UP : BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = $stateMeta === 1 ? Facing::UP : BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();
$tile = $this->level->getTile($this); $tile = $this->level->getTile($this);

View File

@ -61,6 +61,10 @@ abstract class Slab extends Transparent{
} }
} }
public function getStateBitmask() : int{
return 0b1000;
}
public function isTransparent() : bool{ public function isTransparent() : bool{
return $this->slabType !== SlabType::DOUBLE(); return $this->slabType !== SlabType::DOUBLE();
} }

View File

@ -50,6 +50,10 @@ class SnowLayer extends Flowable implements Fallable{
$this->layers = BlockDataValidator::readBoundedInt("layers", $stateMeta + 1, 1, 8); $this->layers = BlockDataValidator::readBoundedInt("layers", $stateMeta + 1, 1, 8);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function canBeReplaced() : bool{ public function canBeReplaced() : bool{
return $this->layers < 8; return $this->layers < 8;
} }

View File

@ -37,6 +37,10 @@ class Sponge extends Solid{
$this->wet = $stateMeta !== 0; $this->wet = $stateMeta !== 0;
} }
public function getStateBitmask() : int{
return 0b1;
}
public function getHardness() : float{ public function getHardness() : float{
return 0.6; return 0.6;
} }

View File

@ -53,6 +53,10 @@ abstract class Stair extends Transparent{
$this->upsideDown = ($stateMeta & 0x04) !== 0; $this->upsideDown = ($stateMeta & 0x04) !== 0;
} }
public function getStateBitmask() : int{
return 0b111;
}
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();

View File

@ -46,6 +46,10 @@ class StandingBanner extends Transparent{
$this->rotation = $stateMeta; $this->rotation = $stateMeta;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 1; return 1;
} }

View File

@ -44,6 +44,10 @@ class Sugarcane extends Flowable{
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15);
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof Fertilizer){ if($item instanceof Fertilizer){
if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){

View File

@ -39,10 +39,13 @@ class Torch extends Flowable{
} }
public function readStateFromData(int $id, int $stateMeta) : void{ public function readStateFromData(int $id, int $stateMeta) : void{
$stateMeta &= 0x07;
$this->facing = $stateMeta === 5 ? Facing::UP : BlockDataValidator::readHorizontalFacing(6 - $stateMeta); $this->facing = $stateMeta === 5 ? Facing::UP : BlockDataValidator::readHorizontalFacing(6 - $stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function getLightLevel() : int{ public function getLightLevel() : int{
return 14; return 14;
} }

View File

@ -54,6 +54,10 @@ class Trapdoor extends Transparent{
$this->open = ($stateMeta & self::MASK_OPENED) !== 0; $this->open = ($stateMeta & self::MASK_OPENED) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function getHardness() : float{ public function getHardness() : float{
return 3; return 3;
} }

View File

@ -45,6 +45,10 @@ class Tripwire extends Flowable{
$this->disarmed = ($stateMeta & 0x08) !== 0; $this->disarmed = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function isAffectedBySilkTouch() : bool{ public function isAffectedBySilkTouch() : bool{
return false; return false;
} }

View File

@ -49,6 +49,10 @@ class TripwireHook extends Flowable{
$this->powered = ($stateMeta & 0x08) !== 0; $this->powered = ($stateMeta & 0x08) !== 0;
} }
public function getStateBitmask() : int{
return 0b1111;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(Facing::axis($face) !== Facing::AXIS_Y){ if(Facing::axis($face) !== Facing::AXIS_Y){
//TODO: check face is valid //TODO: check face is valid

View File

@ -57,6 +57,10 @@ class Vine extends Flowable{
$this->setFaceFromMeta($stateMeta, self::FLAG_EAST, Facing::EAST); $this->setFaceFromMeta($stateMeta, self::FLAG_EAST, Facing::EAST);
} }
public function getStateBitmask() : int{
return 0b1111;
}
private function setFaceFromMeta(int $meta, int $flag, int $face) : void{ private function setFaceFromMeta(int $meta, int $flag, int $face) : void{
if(($meta & $flag) !== 0){ if(($meta & $flag) !== 0){
$this->faces[$face] = true; $this->faces[$face] = true;

View File

@ -39,6 +39,10 @@ class WallBanner extends StandingBanner{
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){ if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);

View File

@ -39,6 +39,10 @@ class WallSign extends SignPost{
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
} }
public function getStateBitmask() : int{
return 0b111;
}
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){ if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);

View File

@ -37,4 +37,8 @@ abstract class WeightedPressurePlate extends PressurePlate{
public function readStateFromData(int $id, int $stateMeta) : void{ public function readStateFromData(int $id, int $stateMeta) : void{
$this->power = BlockDataValidator::readBoundedInt("power", $stateMeta, 0, 15); $this->power = BlockDataValidator::readBoundedInt("power", $stateMeta, 0, 15);
} }
public function getStateBitmask() : int{
return 0b1111;
}
} }

View File

@ -52,6 +52,14 @@ trait PillarRotationTrait{
$this->readAxisFromMeta($stateMeta); $this->readAxisFromMeta($stateMeta);
} }
/**
* @see Block::getStateBitmask()
* @return int
*/
public function getStateBitmask() : int{
return 0b1100;
}
protected function readAxisFromMeta(int $meta) : void{ protected function readAxisFromMeta(int $meta) : void{
static $map = [ static $map = [
0 => Facing::AXIS_Y, 0 => Facing::AXIS_Y,