diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index ac76e6db9..8ce4cae7c 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -51,7 +51,7 @@ class DoublePlant extends Flowable{ 4 => "Rose Bush", 5 => "Peony" ]; - return $names[$this->meta & 0x07] ?? ""; + return $names[$this->getVariant()] ?? ""; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ @@ -79,7 +79,7 @@ class DoublePlant extends Flowable{ return ( $other->getId() === $this->getId() and - ($other->getDamage() & 0x07) === ($this->getDamage() & 0x07) and + $other->getVariant() === $this->getVariant() and ($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP) ); } diff --git a/src/pocketmine/block/DoubleStoneSlab.php b/src/pocketmine/block/DoubleStoneSlab.php index 82128b355..44982906d 100644 --- a/src/pocketmine/block/DoubleStoneSlab.php +++ b/src/pocketmine/block/DoubleStoneSlab.php @@ -54,13 +54,13 @@ class DoubleStoneSlab extends Solid{ 6 => "Quartz", 7 => "Nether Brick" ]; - return "Double " . $names[$this->meta & 0x07] . " Slab"; + return "Double " . $names[$this->getVariant()] . " Slab"; } public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2) + ItemFactory::get(Item::STONE_SLAB, $this->getVariant(), 2) ]; } diff --git a/src/pocketmine/block/DoubleWoodenSlab.php b/src/pocketmine/block/DoubleWoodenSlab.php index 640a06896..05fd73155 100644 --- a/src/pocketmine/block/DoubleWoodenSlab.php +++ b/src/pocketmine/block/DoubleWoodenSlab.php @@ -52,12 +52,12 @@ class DoubleWoodenSlab extends Solid{ 4 => "Acacia", 5 => "Dark Oak" ]; - return "Double " . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab"; + return "Double " . ($names[$this->getVariant()] ?? "") . " Wooden Slab"; } public function getDrops(Item $item) : array{ return [ - ItemFactory::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2) + ItemFactory::get(Item::WOODEN_SLAB, $this->getVariant(), 2) ]; } diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 5b0047330..f79166841 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -61,7 +61,7 @@ class Leaves extends Transparent{ self::BIRCH => "Birch Leaves", self::JUNGLE => "Jungle Leaves" ]; - return $names[$this->meta & 0x03]; + return $names[$this->getVariant()]; } public function diffusesSkyLight() : bool{ diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index 553ab0c5c..cd929aa7a 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -36,11 +36,11 @@ class Leaves2 extends Leaves{ self::ACACIA => "Acacia Leaves", self::DARK_OAK => "Dark Oak Leaves" ]; - return $names[$this->meta & 0x03] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getDrops(Item $item) : array{ - $variantMeta = $this->getDamage() & 0x03; + $variantMeta = $this->getVariant(); if($item->isShears()){ return [ diff --git a/src/pocketmine/block/Planks.php b/src/pocketmine/block/Planks.php index 5ae7a9dbf..d6253dfa5 100644 --- a/src/pocketmine/block/Planks.php +++ b/src/pocketmine/block/Planks.php @@ -56,7 +56,7 @@ class Planks extends Solid{ self::ACACIA => "Acacia Wood Planks", self::DARK_OAK => "Dark Oak Wood Planks" ]; - return $names[$this->meta & 0x07] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getFuelTime() : int{ diff --git a/src/pocketmine/block/Prismarine.php b/src/pocketmine/block/Prismarine.php index 498417674..0365d0499 100644 --- a/src/pocketmine/block/Prismarine.php +++ b/src/pocketmine/block/Prismarine.php @@ -48,7 +48,7 @@ class Prismarine extends Solid{ self::DARK => "Dark Prismarine", self::BRICKS => "Prismarine Bricks" ]; - return $names[$this->meta & 0x03] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getToolType() : int{ diff --git a/src/pocketmine/block/Sandstone.php b/src/pocketmine/block/Sandstone.php index a178e8a3d..80f88d9fd 100644 --- a/src/pocketmine/block/Sandstone.php +++ b/src/pocketmine/block/Sandstone.php @@ -48,7 +48,7 @@ class Sandstone extends Solid{ self::CHISELED => "Chiseled Sandstone", self::SMOOTH => "Smooth Sandstone" ]; - return $names[$this->meta & 0x03] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getToolType() : int{ diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index e29faebbb..236b4957b 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -54,7 +54,7 @@ class Sapling extends Flowable{ 4 => "Acacia Sapling", 5 => "Dark Oak Sapling" ]; - return $names[$this->meta & 0x07] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function ticksRandomly() : bool{ @@ -75,7 +75,7 @@ class Sapling extends Flowable{ public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal //TODO: change log type - Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07); + Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant()); $item->count--; @@ -95,7 +95,7 @@ class Sapling extends Flowable{ }elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth if(mt_rand(1, 7) === 1){ if(($this->meta & 0x08) === 0x08){ - Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07); + Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant()); }else{ $this->meta |= 0x08; $this->getLevel()->setBlock($this, $this, true); @@ -110,10 +110,8 @@ class Sapling extends Flowable{ return false; } - public function getDrops(Item $item) : array{ - return [ - ItemFactory::get($this->getItemId(), $this->getDamage() & 0x07, 1) - ]; + public function getVariantBitmask() : int{ + return 0x07; } public function getFuelTime() : int{ diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index 9c9360794..751e16c5b 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -60,7 +60,7 @@ class Stone extends Solid{ self::ANDESITE => "Andesite", self::POLISHED_ANDESITE => "Polished Andesite" ]; - return $names[$this->meta & 0x07] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getDrops(Item $item) : array{ diff --git a/src/pocketmine/block/StoneBricks.php b/src/pocketmine/block/StoneBricks.php index 50db48a68..d5b866236 100644 --- a/src/pocketmine/block/StoneBricks.php +++ b/src/pocketmine/block/StoneBricks.php @@ -53,7 +53,7 @@ class StoneBricks extends Solid{ self::CRACKED => "Cracked Stone Bricks", self::CHISELED => "Chiseled Stone Bricks" ]; - return $names[$this->meta & 0x03]; + return $names[$this->getVariant()] ?? "Unknown"; } public function getDrops(Item $item) : array{ diff --git a/src/pocketmine/block/StoneSlab.php b/src/pocketmine/block/StoneSlab.php index e6d5077a6..f1f1b285d 100644 --- a/src/pocketmine/block/StoneSlab.php +++ b/src/pocketmine/block/StoneSlab.php @@ -55,7 +55,7 @@ class StoneSlab extends WoodenSlab{ self::QUARTZ => "Quartz", self::NETHER_BRICK => "Nether Brick" ]; - return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; + return (($this->meta & 0x08) > 0 ? "Upper " : "") . ($names[$this->getVariant()] ?? "") . " Slab"; } public function getToolType() : int{ diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 54337f3de..c23fab27e 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -47,7 +47,7 @@ class TallGrass extends Flowable{ 1 => "Tall Grass", 2 => "Fern" ]; - return $names[$this->meta & 0x03] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index baaf09303..7603201d3 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -52,7 +52,7 @@ class Wood extends Solid{ self::BIRCH => "Birch Wood", self::JUNGLE => "Jungle Wood" ]; - return $names[$this->meta & 0x03]; + return $names[$this->getVariant()] ?? "Unknown"; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Wood2.php b/src/pocketmine/block/Wood2.php index 2db985f0c..320caa928 100644 --- a/src/pocketmine/block/Wood2.php +++ b/src/pocketmine/block/Wood2.php @@ -36,6 +36,6 @@ class Wood2 extends Wood{ 0 => "Acacia Wood", 1 => "Dark Oak Wood" ]; - return $names[$this->meta & 0x03] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } } diff --git a/src/pocketmine/block/WoodenFence.php b/src/pocketmine/block/WoodenFence.php index 63891b5d4..d48a462d3 100644 --- a/src/pocketmine/block/WoodenFence.php +++ b/src/pocketmine/block/WoodenFence.php @@ -52,7 +52,7 @@ class WoodenFence extends Fence{ self::FENCE_ACACIA => "Acacia Fence", self::FENCE_DARKOAK => "Dark Oak Fence" ]; - return $names[$this->meta & 0x07] ?? "Unknown"; + return $names[$this->getVariant()] ?? "Unknown"; } public function getFuelTime() : int{ diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 9cf7bf220..b649b3dbc 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -52,7 +52,7 @@ class WoodenSlab extends Transparent{ 4 => "Acacia", 5 => "Dark Oak" ]; - return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab"; + return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->getVariant()] ?? "") . " Wooden Slab"; } protected function recalculateBoundingBox() : ?AxisAlignedBB{ @@ -93,31 +93,31 @@ class WoodenSlab extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta &= 0x07; if($face === Vector3::SIDE_DOWN){ - if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and ($blockClicked->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){ + $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->getVariant()), true); return true; - }elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); + }elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true); return true; }else{ $this->meta |= 0x08; } }elseif($face === Vector3::SIDE_UP){ - if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and ($blockClicked->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){ + $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->getVariant()), true); return true; - }elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); + }elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true); return true; } }else{ //TODO: collision if($blockReplace->getId() === $this->id){ - if(($blockReplace->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockReplace->getVariant() === $this->meta){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true); return true; } @@ -130,7 +130,7 @@ class WoodenSlab extends Transparent{ } } - if($blockReplace->getId() === $this->id and ($blockClicked->getDamage() & 0x07) !== ($this->meta & 0x07)){ + if($blockReplace->getId() === $this->id and $blockClicked->getVariant() !== $this->getVariant()){ return false; } $this->getLevel()->setBlock($blockReplace, $this, true, true);