diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 9c7bc8a5c..f5a017a24 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -49,8 +49,8 @@ class Anvil extends Transparent implements Fallable{ return Bearing::fromFacing($this->facing); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/BaseRail.php b/src/pocketmine/block/BaseRail.php index 7dc0e48f7..ba9913d45 100644 --- a/src/pocketmine/block/BaseRail.php +++ b/src/pocketmine/block/BaseRail.php @@ -87,10 +87,10 @@ abstract class BaseRail extends Flowable{ return $this->getMetaForState($this->connections); } - public function readStateFromMeta(int $meta) : void{ - $connections = $this->getConnectionsFromMeta($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $connections = $this->getConnectionsFromMeta($stateMeta); if($connections === null){ - throw new InvalidBlockStateException("Invalid rail type meta $meta"); + throw new InvalidBlockStateException("Invalid rail type meta $stateMeta"); } $this->connections = $connections; } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 6123b35cf..25fe96582 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -61,10 +61,10 @@ class Bed extends Transparent{ ($this->head ? self::BITFLAG_HEAD : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); - $this->occupied = ($meta & self::BITFLAG_OCCUPIED) !== 0; - $this->head = ($meta & self::BITFLAG_HEAD) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); + $this->occupied = ($stateMeta & self::BITFLAG_OCCUPIED) !== 0; + $this->head = ($stateMeta & self::BITFLAG_HEAD) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index f0f40b94e..53d85a925 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -133,10 +133,12 @@ class Block extends Position implements BlockIds, Metadatable{ } /** - * @param int $meta + * @param int $id + * @param int $stateMeta + * * @throws InvalidBlockStateException */ - public function readStateFromMeta(int $meta) : void{ + public function readStateFromData(int $id, int $stateMeta) : void{ //NOOP } @@ -176,7 +178,10 @@ class Block extends Position implements BlockIds, Metadatable{ } /** - * Returns whether the given block has an equivalent type to this one. + * Returns whether the given block has an equivalent type to this one. This compares base legacy ID and variant. + * + * Note: This ignores additional IDs used to represent additional states. This means that, for example, a lit + * furnace and unlit furnace are considered the same type. * * @param Block $other * diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index f271e2ef0..1b5977a90 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -27,7 +27,6 @@ use pocketmine\block\BlockIdentifier as BID; use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\PillarRotationTrait; -use pocketmine\block\utils\SlabType; use pocketmine\block\utils\TreeType; use pocketmine\item\ItemIds; use pocketmine\level\Position; @@ -107,8 +106,7 @@ class BlockFactory{ self::register(new CocoaBlock(new BID(Block::COCOA), "Cocoa Block")); self::register(new CraftingTable(new BID(Block::CRAFTING_TABLE), "Crafting Table")); self::register(new Dandelion(new BID(Block::DANDELION), "Dandelion")); - self::register($daylightSensor = new DaylightSensor(new BlockIdentifierFlattened(Block::DAYLIGHT_DETECTOR, Block::DAYLIGHT_DETECTOR_INVERTED), "Daylight Sensor")); - self::register((clone $daylightSensor)->setInverted()); //flattening hack + self::register(new DaylightSensor(new BlockIdentifierFlattened(Block::DAYLIGHT_DETECTOR, Block::DAYLIGHT_DETECTOR_INVERTED), "Daylight Sensor")); self::register(new DeadBush(new BID(Block::DEADBUSH), "Dead Bush")); self::register(new DetectorRail(new BID(Block::DETECTOR_RAIL), "Detector Rail")); self::register(new Diamond(new BID(Block::DIAMOND_BLOCK), "Diamond Block")); @@ -148,8 +146,7 @@ class BlockFactory{ self::register(new Flower(new BID(Block::RED_FLOWER, Flower::TYPE_RED_TULIP), "Red Tulip")); self::register(new Flower(new BID(Block::RED_FLOWER, Flower::TYPE_WHITE_TULIP), "White Tulip")); self::register(new FlowerPot(new BID(Block::FLOWER_POT_BLOCK, 0, ItemIds::FLOWER_POT, \pocketmine\tile\FlowerPot::class), "Flower Pot")); - self::register($furnace = new Furnace(new BlockIdentifierFlattened(Block::FURNACE, Block::LIT_FURNACE, 0, null, \pocketmine\tile\Furnace::class), "Furnace")); - self::register((clone $furnace)->setLit()); //flattening hack + self::register(new Furnace(new BlockIdentifierFlattened(Block::FURNACE, Block::LIT_FURNACE, 0, null, \pocketmine\tile\Furnace::class), "Furnace")); self::register(new Glass(new BID(Block::GLASS), "Glass")); self::register(new GlassPane(new BID(Block::GLASS_PANE), "Glass Pane")); self::register(new GlazedTerracotta(new BID(Block::BLACK_GLAZED_TERRACOTTA), "Black Glazed Terracotta")); @@ -192,8 +189,7 @@ class BlockFactory{ self::register(new Ladder(new BID(Block::LADDER), "Ladder")); self::register(new Lapis(new BID(Block::LAPIS_BLOCK), "Lapis Lazuli Block")); self::register(new LapisOre(new BID(Block::LAPIS_ORE), "Lapis Lazuli Ore")); - self::register($lava = new Lava(new BlockIdentifierFlattened(Block::FLOWING_LAVA, Block::STILL_LAVA), "Lava")); - self::register((clone $lava)->setStill()); //flattening hack + self::register(new Lava(new BlockIdentifierFlattened(Block::FLOWING_LAVA, Block::STILL_LAVA), "Lava")); self::register(new Lever(new BID(Block::LEVER), "Lever")); self::register(new LitPumpkin(new BID(Block::JACK_O_LANTERN), "Jack o'Lantern")); self::register(new Magma(new BID(Block::MAGMA), "Magma Block")); @@ -239,14 +235,10 @@ class BlockFactory{ self::register(new RedMushroom(new BID(Block::RED_MUSHROOM), "Red Mushroom")); self::register(new RedMushroomBlock(new BID(Block::RED_MUSHROOM_BLOCK), "Red Mushroom Block")); self::register(new Redstone(new BID(Block::REDSTONE_BLOCK), "Redstone Block")); - self::register($redstoneLamp = new RedstoneLamp(new BlockIdentifierFlattened(Block::REDSTONE_LAMP, Block::LIT_REDSTONE_LAMP), "Redstone Lamp")); - self::register((clone $redstoneLamp)->setLit()); //flattening hack - self::register($redstoneOre = new RedstoneOre(new BlockIdentifierFlattened(Block::REDSTONE_ORE, Block::LIT_REDSTONE_ORE), "Redstone Ore")); - self::register((clone $redstoneOre)->setLit()); //flattening hack - self::register($repeater = new RedstoneRepeater(new BlockIdentifierFlattened(Block::UNPOWERED_REPEATER, Block::POWERED_REPEATER, 0, ItemIds::REPEATER), "Redstne Repeater")); - self::register((clone $repeater)->setPowered()); - self::register($redstoneTorch = new RedstoneTorch(new BlockIdentifierFlattened(Block::REDSTONE_TORCH, Block::UNLIT_REDSTONE_TORCH), "Redstone Torch")); - self::register((clone $redstoneTorch)->setLit(false)); //flattening hack + self::register(new RedstoneLamp(new BlockIdentifierFlattened(Block::REDSTONE_LAMP, Block::LIT_REDSTONE_LAMP), "Redstone Lamp")); + self::register(new RedstoneOre(new BlockIdentifierFlattened(Block::REDSTONE_ORE, Block::LIT_REDSTONE_ORE), "Redstone Ore")); + self::register(new RedstoneRepeater(new BlockIdentifierFlattened(Block::UNPOWERED_REPEATER, Block::POWERED_REPEATER, 0, ItemIds::REPEATER), "Redstne Repeater")); + self::register(new RedstoneTorch(new BlockIdentifierFlattened(Block::REDSTONE_TORCH, Block::UNLIT_REDSTONE_TORCH), "Redstone Torch")); self::register(new RedstoneWire(new BID(Block::REDSTONE_WIRE, 0, ItemIds::REDSTONE), "Redstone")); self::register(new Reserved6(new BID(Block::RESERVED6), "reserved6")); self::register(new Sand(new BID(Block::SAND), "Sand")); @@ -275,6 +267,22 @@ class BlockFactory{ self::register(new StoneBricks(new BID(Block::STONEBRICK, StoneBricks::NORMAL), "Stone Bricks")); self::register(new StoneButton(new BID(Block::STONE_BUTTON), "Stone Button")); self::register(new StonePressurePlate(new BID(Block::STONE_PRESSURE_PLATE), "Stone Pressure Plate")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 0), "Stone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 1), "Sandstone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 2), "Fake Wooden")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 3), "Cobblestone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 4), "Brick")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 5), "Stone Brick")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 6), "Quartz")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 7), "Nether Brick")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 0), "Red Sandstone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 1), "Purpur")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 2), "Prismarine")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 3), "Dark Prismarine")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 4), "Prismarine Bricks")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 5), "Mossy Cobblestone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 6), "Smooth Sandstone")); + self::register(new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 7), "Red Nether Brick")); self::register(new Stonecutter(new BID(Block::STONECUTTER), "Stonecutter")); self::register(new Sugarcane(new BID(Block::REEDS_BLOCK, 0, ItemIds::REEDS), "Sugarcane")); self::register(new TNT(new BID(Block::TNT), "TNT")); @@ -295,8 +303,7 @@ class BlockFactory{ self::register(new Vine(new BID(Block::VINE), "Vines")); self::register(new WallBanner(new BID(Block::WALL_BANNER, 0, ItemIds::BANNER, \pocketmine\tile\Banner::class), "Wall Banner")); self::register(new WallSign(new BID(Block::WALL_SIGN, 0, ItemIds::SIGN, \pocketmine\tile\Sign::class), "Wall Sign")); - self::register($water = new Water(new BlockIdentifierFlattened(Block::FLOWING_WATER, Block::STILL_WATER), "Water")); - self::register((clone $water)->setStill()); //flattening hack + self::register(new Water(new BlockIdentifierFlattened(Block::FLOWING_WATER, Block::STILL_WATER), "Water")); self::register(new WaterLily(new BID(Block::LILY_PAD), "Lily Pad")); self::register(new WeightedPressurePlateHeavy(new BID(Block::HEAVY_WEIGHTED_PRESSURE_PLATE), "Weighted Pressure Plate Heavy")); self::register(new WeightedPressurePlateLight(new BID(Block::LIGHT_WEIGHTED_PRESSURE_PLATE), "Weighted Pressure Plate Light")); @@ -322,6 +329,7 @@ class BlockFactory{ self::register(new Planks(new BID(Block::PLANKS, $magicNumber), $name . " Planks")); self::register(new Sapling(new BID(Block::SAPLING, $magicNumber), $name . " Sapling", $treeType)); self::register(new WoodenFence(new BID(Block::FENCE, $magicNumber), $name . " Fence")); + self::register(new WoodenSlab(new BlockIdentifierFlattened(Block::WOODEN_SLAB, Block::DOUBLE_WOODEN_SLAB, $treeType->getMagicNumber()), $treeType->getDisplayName())); //TODO: find a better way to deal with this split self::register(new Leaves(new BID($magicNumber >= 4 ? Block::LEAVES2 : Block::LEAVES, $magicNumber & 0x03), $name . " Leaves", $treeType)); @@ -352,33 +360,6 @@ class BlockFactory{ self::register(new Wool(new BID(Block::WOOL, $color->getMagicNumber()), $color->getDisplayName() . " Wool")); } - /** @var Slab[] $slabTypes */ - $slabTypes = [ - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 0), "Stone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 1), "Sandstone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 2), "Fake Wooden"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 3), "Cobblestone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 4), "Brick"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 5), "Stone Brick"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 6), "Quartz"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB, Block::DOUBLE_STONE_SLAB, 7), "Nether Brick"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 0), "Red Sandstone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 1), "Purpur"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 2), "Prismarine"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 3), "Dark Prismarine"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 4), "Prismarine Bricks"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 5), "Mossy Cobblestone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 6), "Smooth Sandstone"), - new StoneSlab(new BlockIdentifierFlattened(Block::STONE_SLAB2, Block::DOUBLE_STONE_SLAB2, 7), "Red Nether Brick") - ]; - foreach(TreeType::getAll() as $woodType){ - $slabTypes[] = new WoodenSlab(new BlockIdentifierFlattened(Block::WOODEN_SLAB, Block::DOUBLE_WOODEN_SLAB, $woodType->getMagicNumber()), $woodType->getDisplayName()); - } - foreach($slabTypes as $type){ - self::register($type); - self::register((clone $type)->setSlabType(SlabType::DOUBLE())); //flattening hack - } - static $wallTypes = [ CobblestoneWall::ANDESITE_WALL => "Andesite", CobblestoneWall::BRICK_WALL => "Brick", @@ -533,7 +514,6 @@ class BlockFactory{ * $override parameter. */ public static function register(Block $block, bool $override = false) : void{ - $id = $block->getId(); $variant = $block->getIdInfo()->getVariant(); $stateMask = $block->getStateBitmask(); @@ -541,36 +521,38 @@ class BlockFactory{ throw new \InvalidArgumentException("Block variant collides with state bitmask"); } - 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; + 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"); } - if(!$override and self::isRegistered($id, $m)){ - throw new \InvalidArgumentException("Block registration " . get_class($block) . " has states which conflict with other blocks"); - } - - $index = ($id << 4) | $m; - - $v = clone $block; - try{ - $v->readStateFromMeta($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 + for($m = $variant; $m <= ($variant | $stateMask); ++$m){ + if(($m & ~$stateMask) !== $variant){ + continue; } - }catch(InvalidBlockStateException $e){ //invalid property combination - continue; + + if(!$override and self::isRegistered($id, $m)){ + 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); - } - - 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 + 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 + } } } diff --git a/src/pocketmine/block/BlockIdentifier.php b/src/pocketmine/block/BlockIdentifier.php index b5e855911..87cae2ad7 100644 --- a/src/pocketmine/block/BlockIdentifier.php +++ b/src/pocketmine/block/BlockIdentifier.php @@ -48,6 +48,13 @@ class BlockIdentifier{ return $this->blockId; } + /** + * @return int[] + */ + public function getAllBlockIds() : array{ + return [$this->blockId]; + } + /** * @return int */ diff --git a/src/pocketmine/block/BlockIdentifierFlattened.php b/src/pocketmine/block/BlockIdentifierFlattened.php index 026134d8a..adbeddede 100644 --- a/src/pocketmine/block/BlockIdentifierFlattened.php +++ b/src/pocketmine/block/BlockIdentifierFlattened.php @@ -39,4 +39,8 @@ class BlockIdentifierFlattened extends BlockIdentifier{ public function getSecondId() : int{ return $this->secondId; } + + public function getAllBlockIds() : array{ + return [$this->getBlockId(), $this->getSecondId()]; + } } diff --git a/src/pocketmine/block/BrewingStand.php b/src/pocketmine/block/BrewingStand.php index 5651d1cc3..f9833823b 100644 --- a/src/pocketmine/block/BrewingStand.php +++ b/src/pocketmine/block/BrewingStand.php @@ -38,10 +38,10 @@ class BrewingStand extends Transparent{ return ($this->eastSlot ? 0x01 : 0) | ($this->southwestSlot ? 0x02 : 0) | ($this->northwestSlot ? 0x04 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->eastSlot = ($meta & 0x01) !== 0; - $this->southwestSlot = ($meta & 0x02) !== 0; - $this->northwestSlot = ($meta & 0x04) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->eastSlot = ($stateMeta & 0x01) !== 0; + $this->southwestSlot = ($stateMeta & 0x02) !== 0; + $this->northwestSlot = ($stateMeta & 0x04) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Button.php b/src/pocketmine/block/Button.php index 1c4316d02..cc5086e87 100644 --- a/src/pocketmine/block/Button.php +++ b/src/pocketmine/block/Button.php @@ -41,10 +41,10 @@ abstract class Button extends Flowable{ return $this->facing | ($this->powered ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ + public function readStateFromData(int $id, int $stateMeta) : void{ //TODO: in PC it's (6 - facing) for every meta except 0 (down) - $this->facing = BlockDataValidator::readFacing($meta & 0x07); - $this->powered = ($meta & 0x08) !== 0; + $this->facing = BlockDataValidator::readFacing($stateMeta & 0x07); + $this->powered = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 0b16b7403..ec8b51400 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -43,8 +43,8 @@ class Cactus extends Transparent{ return $this->age; } - public function readStateFromMeta(int $meta) : void{ - $this->age = BlockDataValidator::readBoundedInt("age", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 670e19e32..d18073243 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -42,8 +42,8 @@ class Cake extends Transparent implements FoodSource{ return $this->bites; } - public function readStateFromMeta(int $meta) : void{ - $this->bites = BlockDataValidator::readBoundedInt("bites", $meta, 0, 6); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->bites = BlockDataValidator::readBoundedInt("bites", $stateMeta, 0, 6); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 173efc56a..14e27f7c5 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -40,8 +40,8 @@ class Chest extends Transparent{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index 18b7fd222..7cb805802 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -45,9 +45,9 @@ class CocoaBlock extends Transparent{ return Bearing::fromFacing(Facing::opposite($this->facing)) | ($this->age << 2); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = Facing::opposite(BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03)); - $this->age = BlockDataValidator::readBoundedInt("age", $meta >> 2, 0, 2); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = Facing::opposite(BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03)); + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta >> 2, 0, 2); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 6d68af781..f38e970db 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -39,8 +39,8 @@ abstract class Crops extends Flowable{ return $this->age; } - public function readStateFromMeta(int $meta) : void{ - $this->age = BlockDataValidator::readBoundedInt("age", $meta, 0, 7); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 7); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 7b60e6518..a379c5f14 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -52,8 +52,9 @@ class DaylightSensor extends Transparent{ return $this->power; } - public function readStateFromMeta(int $meta) : void{ - $this->power = BlockDataValidator::readBoundedInt("power", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->power = BlockDataValidator::readBoundedInt("power", $stateMeta, 0, 15); + $this->inverted = $id === $this->idInfo->getSecondId(); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 44ef368a6..15ad3518a 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -56,14 +56,14 @@ abstract class Door extends Transparent{ return Bearing::fromFacing(Facing::rotateY($this->facing, true)) | ($this->open ? 0x04 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->top = $meta & 0x08; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->top = $stateMeta & 0x08; if($this->top){ - $this->hingeRight = ($meta & 0x01) !== 0; - $this->powered = ($meta & 0x02) !== 0; + $this->hingeRight = ($stateMeta & 0x01) !== 0; + $this->powered = ($stateMeta & 0x02) !== 0; }else{ - $this->facing = Facing::rotateY(BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03), false); - $this->open = ($meta & 0x04) !== 0; + $this->facing = Facing::rotateY(BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03), false); + $this->open = ($stateMeta & 0x04) !== 0; } } diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index f25c842dd..30ecab275 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -39,8 +39,8 @@ class DoublePlant extends Flowable{ return ($this->top ? self::BITFLAG_TOP : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->top = ($meta & self::BITFLAG_TOP) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->top = ($stateMeta & self::BITFLAG_TOP) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/EndPortalFrame.php b/src/pocketmine/block/EndPortalFrame.php index 6d38c4bfa..8f59f1ff3 100644 --- a/src/pocketmine/block/EndPortalFrame.php +++ b/src/pocketmine/block/EndPortalFrame.php @@ -42,9 +42,9 @@ class EndPortalFrame extends Solid{ return Bearing::fromFacing($this->facing) | ($this->eye ? 0x04 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); - $this->eye = ($meta & 0x04) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); + $this->eye = ($stateMeta & 0x04) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index 2975f8f41..f83133705 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -42,12 +42,12 @@ class EndRod extends Flowable{ return $this->facing ^ 1; //TODO: in PC this is always the same as facing, just PE is stupid } - public function readStateFromMeta(int $meta) : void{ - if($meta !== 0 and $meta !== 1){ - $meta ^= 1; + public function readStateFromData(int $id, int $stateMeta) : void{ + if($stateMeta !== 0 and $stateMeta !== 1){ + $stateMeta ^= 1; } - $this->facing = BlockDataValidator::readFacing($meta); + $this->facing = BlockDataValidator::readFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 6995d21e8..32d907990 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -38,8 +38,8 @@ class Farmland extends Transparent{ return $this->wetness; } - public function readStateFromMeta(int $meta) : void{ - $this->wetness = BlockDataValidator::readBoundedInt("wetness", $meta, 0, 7); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->wetness = BlockDataValidator::readBoundedInt("wetness", $stateMeta, 0, 7); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index c378a4ac3..a146b7251 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -44,10 +44,10 @@ class FenceGate extends Transparent{ return Bearing::fromFacing($this->facing) | ($this->open ? 0x04 : 0) | ($this->inWall ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); - $this->open = ($meta & 0x04) !== 0; - $this->inWall = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); + $this->open = ($stateMeta & 0x04) !== 0; + $this->inWall = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index cf155413c..faa722df4 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -44,8 +44,8 @@ class Fire extends Flowable{ return $this->age; } - public function readStateFromMeta(int $meta) : void{ - $this->age = BlockDataValidator::readBoundedInt("age", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 4ff07b9a3..a8af03df7 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -39,8 +39,8 @@ class FlowerPot extends Flowable{ return $this->occupied ? 1 : 0; } - public function readStateFromMeta(int $meta) : void{ - $this->occupied = $meta !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->occupied = $stateMeta !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index 63e5c3948..780771eae 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -48,8 +48,9 @@ class Furnace extends Solid{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); + $this->lit = $id === $this->idInfo->getSecondId(); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index 0fb27de73..83244b556 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -40,8 +40,8 @@ class GlazedTerracotta extends Solid{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 3eff935ca..1f65296f1 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -42,9 +42,9 @@ class ItemFrame extends Flowable{ return (5 - $this->facing) | ($this->hasMap ? 0x04 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($meta & 0x03)); - $this->hasMap = ($meta & 0x04) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($stateMeta & 0x03)); + $this->hasMap = ($stateMeta & 0x04) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index f99fdcc7a..c7af4a453 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -40,8 +40,8 @@ class Ladder extends Transparent{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 85963e14f..a61bacce7 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -51,9 +51,9 @@ class Leaves extends Transparent{ return ($this->noDecay ? 0x04 : 0) | ($this->checkDecay ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->noDecay = ($meta & 0x04) !== 0; - $this->checkDecay = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->noDecay = ($stateMeta & 0x04) !== 0; + $this->checkDecay = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 2f2423328..ce88e9bed 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -53,8 +53,8 @@ class Lever extends Flowable{ return $rotationMeta | ($this->powered ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $rotationMeta = $meta & 0x07; + public function readStateFromData(int $id, int $stateMeta) : void{ + $rotationMeta = $stateMeta & 0x07; if($rotationMeta === 5 or $rotationMeta === 6){ $this->position = self::TOP; $this->facing = $rotationMeta === 5 ? Facing::SOUTH : Facing::EAST; @@ -66,7 +66,7 @@ class Lever extends Flowable{ $this->facing = BlockDataValidator::readHorizontalFacing(6 - $rotationMeta); } - $this->powered = ($meta & 0x08) !== 0; + $this->powered = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index d0280b012..cb98b7ca8 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -71,9 +71,10 @@ abstract class Liquid extends Transparent{ return $this->decay | ($this->falling ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->decay = BlockDataValidator::readBoundedInt("decay", $meta & 0x07, 0, 7); - $this->falling = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->decay = BlockDataValidator::readBoundedInt("decay", $stateMeta & 0x07, 0, 7); + $this->falling = ($stateMeta & 0x08) !== 0; + $this->still = $id === $this->idInfo->getSecondId(); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/NetherReactor.php index 1ec7ab236..3a90117e8 100644 --- a/src/pocketmine/block/NetherReactor.php +++ b/src/pocketmine/block/NetherReactor.php @@ -40,8 +40,8 @@ class NetherReactor extends Solid{ return $this->state; } - public function readStateFromMeta(int $meta) : void{ - $this->state = BlockDataValidator::readBoundedInt("state", $meta, 0, 2); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->state = BlockDataValidator::readBoundedInt("state", $stateMeta, 0, 2); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 9489847e9..60775f882 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -41,8 +41,8 @@ class NetherWartPlant extends Flowable{ return $this->age; } - public function readStateFromMeta(int $meta) : void{ - $this->age = BlockDataValidator::readBoundedInt("age", $meta, 0, 3); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 3); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index 7bd2e08b9..d0abc3653 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -35,8 +35,8 @@ class Pumpkin extends Solid{ /** @var int */ protected $facing = Facing::NORTH; - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); } protected function writeStateToMeta() : int{ diff --git a/src/pocketmine/block/RedMushroomBlock.php b/src/pocketmine/block/RedMushroomBlock.php index 42403f67d..7e2bbf48e 100644 --- a/src/pocketmine/block/RedMushroomBlock.php +++ b/src/pocketmine/block/RedMushroomBlock.php @@ -41,8 +41,8 @@ class RedMushroomBlock extends Solid{ return $this->rotationData; } - public function readStateFromMeta(int $meta) : void{ - $this->rotationData = $meta; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->rotationData = $stateMeta; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/RedstoneLamp.php b/src/pocketmine/block/RedstoneLamp.php index 15df287eb..eae4bdf2c 100644 --- a/src/pocketmine/block/RedstoneLamp.php +++ b/src/pocketmine/block/RedstoneLamp.php @@ -39,6 +39,10 @@ class RedstoneLamp extends Solid{ return $this->lit ? $this->idInfo->getSecondId() : parent::getId(); } + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->lit = $id === $this->idInfo->getSecondId(); + } + public function isLit() : bool{ return $this->lit; } diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 306ae7db0..c5f13c09f 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -45,6 +45,10 @@ class RedstoneOre extends Solid{ return $this->lit ? $this->idInfo->getSecondId() : parent::getId(); } + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->lit = $id === $this->idInfo->getSecondId(); + } + public function getHardness() : float{ return 3; } diff --git a/src/pocketmine/block/RedstoneRail.php b/src/pocketmine/block/RedstoneRail.php index 01b1b10c9..3678a5f9f 100644 --- a/src/pocketmine/block/RedstoneRail.php +++ b/src/pocketmine/block/RedstoneRail.php @@ -33,9 +33,9 @@ abstract class RedstoneRail extends BaseRail{ return parent::writeStateToMeta() | ($this->powered ? self::FLAG_POWERED : 0); } - public function readStateFromMeta(int $meta) : void{ - parent::readStateFromMeta($meta); - $this->powered = ($meta & self::FLAG_POWERED) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + parent::readStateFromData($id, $stateMeta); + $this->powered = ($stateMeta & self::FLAG_POWERED) !== 0; } protected function getConnectionsFromMeta(int $meta) : ?array{ diff --git a/src/pocketmine/block/RedstoneRepeater.php b/src/pocketmine/block/RedstoneRepeater.php index 29c658f32..160703cdc 100644 --- a/src/pocketmine/block/RedstoneRepeater.php +++ b/src/pocketmine/block/RedstoneRepeater.php @@ -50,9 +50,10 @@ class RedstoneRepeater extends Flowable{ return $this->powered ? $this->idInfo->getSecondId() : parent::getId(); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); - $this->delay = BlockDataValidator::readBoundedInt("delay", ($meta >> 2) + 1, 1, 4); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); + $this->delay = BlockDataValidator::readBoundedInt("delay", ($stateMeta >> 2) + 1, 1, 4); + $this->powered = $id === $this->idInfo->getSecondId(); } public function writeStateToMeta() : int{ diff --git a/src/pocketmine/block/RedstoneTorch.php b/src/pocketmine/block/RedstoneTorch.php index 44119dc26..a1974c2ce 100644 --- a/src/pocketmine/block/RedstoneTorch.php +++ b/src/pocketmine/block/RedstoneTorch.php @@ -39,6 +39,11 @@ class RedstoneTorch extends Torch{ return $this->lit ? parent::getId() : $this->idInfo->getSecondId(); } + public function readStateFromData(int $id, int $stateMeta) : void{ + parent::readStateFromData($id, $stateMeta); + $this->lit = $id !== $this->idInfo->getSecondId(); + } + public function isLit() : bool{ return $this->lit; } diff --git a/src/pocketmine/block/RedstoneWire.php b/src/pocketmine/block/RedstoneWire.php index e8d2a3b7d..6f95e906b 100644 --- a/src/pocketmine/block/RedstoneWire.php +++ b/src/pocketmine/block/RedstoneWire.php @@ -30,8 +30,8 @@ class RedstoneWire extends Flowable{ /** @var int */ protected $power = 0; - public function readStateFromMeta(int $meta) : void{ - $this->power = BlockDataValidator::readBoundedInt("power", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->power = BlockDataValidator::readBoundedInt("power", $stateMeta, 0, 15); } protected function writeStateToMeta() : int{ diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 9e07f7ebc..1511ba343 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -48,8 +48,8 @@ class Sapling extends Flowable{ return ($this->ready ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->ready = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->ready = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index 8cd0c16d1..e8a196865 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -39,8 +39,8 @@ class SignPost extends Transparent{ return $this->rotation; } - public function readStateFromMeta(int $meta) : void{ - $this->rotation = $meta; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->rotation = $stateMeta; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 1b14ac161..37d88cdd5 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -46,8 +46,8 @@ class Skull extends Flowable{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = $meta === 1 ? Facing::UP : BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = $stateMeta === 1 ? Facing::UP : BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 311802e7a..e1de5a78e 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -53,9 +53,11 @@ abstract class Slab extends Transparent{ return 0; } - public function readStateFromMeta(int $meta) : void{ - if($this->slabType !== SlabType::DOUBLE()){ - $this->slabType = ($meta & 0x08) !== 0 ? SlabType::TOP() : SlabType::BOTTOM(); + public function readStateFromData(int $id, int $stateMeta) : void{ + if($id === $this->idInfo->getSecondId()){ + $this->slabType = SlabType::DOUBLE(); + }else{ + $this->slabType = ($stateMeta & 0x08) !== 0 ? SlabType::TOP() : SlabType::BOTTOM(); } } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index 733ea2595..617ef79c7 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -46,8 +46,8 @@ class SnowLayer extends Flowable implements Fallable{ return $this->layers - 1; } - public function readStateFromMeta(int $meta) : void{ - $this->layers = BlockDataValidator::readBoundedInt("layers", $meta + 1, 1, 8); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->layers = BlockDataValidator::readBoundedInt("layers", $stateMeta + 1, 1, 8); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Sponge.php b/src/pocketmine/block/Sponge.php index dda5d8e65..f72ec0b7b 100644 --- a/src/pocketmine/block/Sponge.php +++ b/src/pocketmine/block/Sponge.php @@ -33,8 +33,8 @@ class Sponge extends Solid{ return $this->wet ? 1 : 0; } - public function readStateFromMeta(int $meta) : void{ - $this->wet = $meta !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->wet = $stateMeta !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index fba071a54..2af550a0f 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -48,9 +48,9 @@ abstract class Stair extends Transparent{ return (5 - $this->facing) | ($this->upsideDown ? 0x04 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($meta & 0x03)); - $this->upsideDown = ($meta & 0x04) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($stateMeta & 0x03)); + $this->upsideDown = ($stateMeta & 0x04) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/StandingBanner.php b/src/pocketmine/block/StandingBanner.php index fd23d3a74..aa2bf1735 100644 --- a/src/pocketmine/block/StandingBanner.php +++ b/src/pocketmine/block/StandingBanner.php @@ -42,8 +42,8 @@ class StandingBanner extends Transparent{ return $this->rotation; } - public function readStateFromMeta(int $meta) : void{ - $this->rotation = $meta; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->rotation = $stateMeta; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/StonePressurePlate.php b/src/pocketmine/block/StonePressurePlate.php index 501c2ee0f..650f63c36 100644 --- a/src/pocketmine/block/StonePressurePlate.php +++ b/src/pocketmine/block/StonePressurePlate.php @@ -34,8 +34,8 @@ class StonePressurePlate extends Transparent{ return $this->powered ? 1 : 0; } - public function readStateFromMeta(int $meta) : void{ - $this->powered = $meta !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->powered = $stateMeta !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index cdde3cbde..221e1e531 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -39,8 +39,8 @@ class Sugarcane extends Flowable{ return $this->age; } - public function readStateFromMeta(int $meta) : void{ - $this->age = BlockDataValidator::readBoundedInt("age", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 15); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 2055f95a2..46a2036c5 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -38,8 +38,8 @@ class Torch extends Flowable{ return 6 - $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = $meta === 5 ? Facing::UP : BlockDataValidator::readHorizontalFacing(6 - $meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = $stateMeta === 5 ? Facing::UP : BlockDataValidator::readHorizontalFacing(6 - $stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 4349f7fd2..b2c6ddb4f 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -46,12 +46,12 @@ class Trapdoor extends Transparent{ return (5 - $this->facing) | ($this->top ? self::MASK_UPPER : 0) | ($this->open ? self::MASK_OPENED : 0); } - public function readStateFromMeta(int $meta) : void{ + public function readStateFromData(int $id, int $stateMeta) : void{ //TODO: in PC the values are reversed (facing - 2) - $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($meta & 0x03)); - $this->top = ($meta & self::MASK_UPPER) !== 0; - $this->open = ($meta & self::MASK_OPENED) !== 0; + $this->facing = BlockDataValidator::readHorizontalFacing(5 - ($stateMeta & 0x03)); + $this->top = ($stateMeta & self::MASK_UPPER) !== 0; + $this->open = ($stateMeta & self::MASK_OPENED) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Tripwire.php b/src/pocketmine/block/Tripwire.php index b55d283b9..58c45a065 100644 --- a/src/pocketmine/block/Tripwire.php +++ b/src/pocketmine/block/Tripwire.php @@ -39,10 +39,10 @@ class Tripwire extends Flowable{ return ($this->triggered ? 0x01 : 0) | ($this->connected ? 0x04 : 0) | ($this->disarmed ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->triggered = ($meta & 0x01) !== 0; - $this->connected = ($meta & 0x04) !== 0; - $this->disarmed = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->triggered = ($stateMeta & 0x01) !== 0; + $this->connected = ($stateMeta & 0x04) !== 0; + $this->disarmed = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/TripwireHook.php b/src/pocketmine/block/TripwireHook.php index 84356d34c..d35b15bc1 100644 --- a/src/pocketmine/block/TripwireHook.php +++ b/src/pocketmine/block/TripwireHook.php @@ -43,10 +43,10 @@ class TripwireHook extends Flowable{ return Bearing::fromFacing($this->facing) | ($this->connected ? 0x04 : 0) | ($this->powered ? 0x08 : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); - $this->connected = ($meta & 0x04) !== 0; - $this->powered = ($meta & 0x08) !== 0; + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readLegacyHorizontalFacing($stateMeta & 0x03); + $this->connected = ($stateMeta & 0x04) !== 0; + $this->powered = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index a65fc48a8..a4b671652 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -50,11 +50,11 @@ class Vine extends Flowable{ (isset($this->faces[Facing::EAST]) ? self::FLAG_EAST : 0); } - public function readStateFromMeta(int $meta) : void{ - $this->setFaceFromMeta($meta, self::FLAG_SOUTH, Facing::SOUTH); - $this->setFaceFromMeta($meta, self::FLAG_WEST, Facing::WEST); - $this->setFaceFromMeta($meta, self::FLAG_NORTH, Facing::NORTH); - $this->setFaceFromMeta($meta, self::FLAG_EAST, Facing::EAST); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->setFaceFromMeta($stateMeta, self::FLAG_SOUTH, Facing::SOUTH); + $this->setFaceFromMeta($stateMeta, self::FLAG_WEST, Facing::WEST); + $this->setFaceFromMeta($stateMeta, self::FLAG_NORTH, Facing::NORTH); + $this->setFaceFromMeta($stateMeta, self::FLAG_EAST, Facing::EAST); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/WallBanner.php b/src/pocketmine/block/WallBanner.php index 5aa2dc757..7acdba5b7 100644 --- a/src/pocketmine/block/WallBanner.php +++ b/src/pocketmine/block/WallBanner.php @@ -35,8 +35,8 @@ class WallBanner extends StandingBanner{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/WallSign.php b/src/pocketmine/block/WallSign.php index b7c7448da..79f85999a 100644 --- a/src/pocketmine/block/WallSign.php +++ b/src/pocketmine/block/WallSign.php @@ -35,8 +35,8 @@ class WallSign extends SignPost{ return $this->facing; } - public function readStateFromMeta(int $meta) : void{ - $this->facing = BlockDataValidator::readHorizontalFacing($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/WeightedPressurePlateLight.php b/src/pocketmine/block/WeightedPressurePlateLight.php index 9fac934c9..f6d717f5e 100644 --- a/src/pocketmine/block/WeightedPressurePlateLight.php +++ b/src/pocketmine/block/WeightedPressurePlateLight.php @@ -35,8 +35,8 @@ class WeightedPressurePlateLight extends Transparent{ return $this->power; } - public function readStateFromMeta(int $meta) : void{ - $this->power = BlockDataValidator::readBoundedInt("power", $meta, 0, 15); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->power = BlockDataValidator::readBoundedInt("power", $stateMeta, 0, 15); } public function getStateBitmask() : int{ diff --git a/src/pocketmine/block/utils/PillarRotationTrait.php b/src/pocketmine/block/utils/PillarRotationTrait.php index d742792f0..8b4aa32cb 100644 --- a/src/pocketmine/block/utils/PillarRotationTrait.php +++ b/src/pocketmine/block/utils/PillarRotationTrait.php @@ -43,11 +43,13 @@ trait PillarRotationTrait{ } /** - * @see Block::readStateFromMeta() - * @param int $meta + * @see Block::readStateFromData() + * + * @param int $id + * @param int $stateMeta */ - public function readStateFromMeta(int $meta) : void{ - $this->readAxisFromMeta($meta); + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->readAxisFromMeta($stateMeta); } /**