diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index e699c62ab..5ef3dd82f 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -134,7 +134,8 @@ class BlockFactory{ $this->register(new CoarseDirt(new BID(Ids::DIRT, Meta::DIRT_COARSE), "Coarse Dirt")); $cobblestoneBreakInfo = new BlockBreakInfo(2.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 30.0); - $this->register(new Opaque(new BID(Ids::COBBLESTONE), "Cobblestone", $cobblestoneBreakInfo)); + $this->register($cobblestone = new Opaque(new BID(Ids::COBBLESTONE), "Cobblestone", $cobblestoneBreakInfo)); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_COBBLESTONE), "Infested Cobblestone", $cobblestone)); $this->register(new Opaque(new BID(Ids::MOSSY_COBBLESTONE), "Mossy Cobblestone", $cobblestoneBreakInfo)); $this->register(new Stair(new BID(Ids::COBBLESTONE_STAIRS), "Cobblestone Stairs", $cobblestoneBreakInfo)); $this->register(new Stair(new BID(Ids::MOSSY_COBBLESTONE_STAIRS), "Mossy Cobblestone Stairs", $cobblestoneBreakInfo)); @@ -202,36 +203,6 @@ class BlockFactory{ $this->register(new HayBale(new BID(Ids::HAY_BALE), "Hay Bale")); $this->register(new Hopper(new BID(Ids::HOPPER_BLOCK, 0, ItemIds::HOPPER, TileHopper::class), "Hopper", new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 15.0))); $this->register(new Ice(new BID(Ids::ICE), "Ice")); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE), "Infested Stone") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::STONE()->asItem()]; - } - }); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_COBBLESTONE), "Infested Cobblestone") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::COBBLESTONE()->asItem()]; - } - }); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK), "Infested Stone Brick") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::STONE_BRICKS()->asItem()]; - } - }); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_MOSSY), "Infested Mossy Stone Brick") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::MOSSY_STONE_BRICKS()->asItem()]; - } - }); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_CRACKED), "Infested Cracked Stone Brick") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::CRACKED_STONE_BRICKS()->asItem()]; - } - }); - $this->register(new class(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_CHISELED), "Infested Chiseled Stone Brick") extends InfestedStone{ - public function getSilkTouchDrops(Item $item) : array{ - return [VanillaBlocks::CHISELED_STONE_BRICKS()->asItem()]; - } - }); $updateBlockBreakInfo = new BlockBreakInfo(1.0); $this->register(new Opaque(new BID(Ids::INFO_UPDATE), "update!", $updateBlockBreakInfo)); @@ -335,7 +306,7 @@ class BlockFactory{ $this->register(new Sponge(new BID(Ids::SPONGE), "Sponge")); $stoneBreakInfo = new BlockBreakInfo(1.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 30.0); - $this->register(new class(new BID(Ids::STONE, Meta::STONE_NORMAL), "Stone", $stoneBreakInfo) extends Opaque{ + $this->register($stone = new class(new BID(Ids::STONE, Meta::STONE_NORMAL), "Stone", $stoneBreakInfo) extends Opaque{ public function getDropsForCompatibleTool(Item $item) : array{ return [VanillaBlocks::COBBLESTONE()->asItem()]; } @@ -344,6 +315,7 @@ class BlockFactory{ return true; } }); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE), "Infested Stone", $stone)); $this->register(new Stair(new BID(Ids::NORMAL_STONE_STAIRS), "Stone Stairs", $stoneBreakInfo)); $this->register(new Opaque(new BID(Ids::SMOOTH_STONE), "Smooth Stone", $stoneBreakInfo)); $this->register(new Opaque(new BID(Ids::STONE, Meta::STONE_ANDESITE), "Andesite", $stoneBreakInfo)); @@ -359,11 +331,15 @@ class BlockFactory{ $this->register(new Opaque(new BID(Ids::STONE, Meta::STONE_POLISHED_GRANITE), "Polished Granite", $stoneBreakInfo)); $this->register(new Stair(new BID(Ids::POLISHED_GRANITE_STAIRS), "Polished Granite Stairs", $stoneBreakInfo)); $this->register(new Stair(new BID(Ids::STONE_BRICK_STAIRS), "Stone Brick Stairs", $stoneBreakInfo)); - $this->register(new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_CHISELED), "Chiseled Stone Bricks", $stoneBreakInfo)); - $this->register(new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_CRACKED), "Cracked Stone Bricks", $stoneBreakInfo)); - $this->register(new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_MOSSY), "Mossy Stone Bricks", $stoneBreakInfo)); + $this->register($chiseledStoneBrick = new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_CHISELED), "Chiseled Stone Bricks", $stoneBreakInfo)); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_CHISELED), "Infested Chiseled Stone Brick", $chiseledStoneBrick)); + $this->register($crackedStoneBrick = new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_CRACKED), "Cracked Stone Bricks", $stoneBreakInfo)); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_CRACKED), "Infested Cracked Stone Brick", $crackedStoneBrick)); + $this->register($mossyStoneBrick = new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_MOSSY), "Mossy Stone Bricks", $stoneBreakInfo)); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK_MOSSY), "Infested Mossy Stone Brick", $mossyStoneBrick)); $this->register(new Stair(new BID(Ids::MOSSY_STONE_BRICK_STAIRS), "Mossy Stone Brick Stairs", $stoneBreakInfo)); - $this->register(new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_NORMAL), "Stone Bricks", $stoneBreakInfo)); + $this->register($stoneBrick = new Opaque(new BID(Ids::STONEBRICK, Meta::STONE_BRICK_NORMAL), "Stone Bricks", $stoneBreakInfo)); + $this->register(new InfestedStone(new BID(Ids::MONSTER_EGG, Meta::INFESTED_STONE_BRICK), "Infested Stone Brick", $stoneBrick)); $this->register(new StoneButton(new BID(Ids::STONE_BUTTON), "Stone Button")); $this->register(new StonePressurePlate(new BID(Ids::STONE_PRESSURE_PLATE), "Stone Pressure Plate")); diff --git a/src/block/InfestedStone.php b/src/block/InfestedStone.php index d19737ebd..00188ff2f 100644 --- a/src/block/InfestedStone.php +++ b/src/block/InfestedStone.php @@ -25,16 +25,27 @@ namespace pocketmine\block; use pocketmine\item\Item; -abstract class InfestedStone extends Opaque{ +final class InfestedStone extends Opaque{ - public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){ + private int $imitated; + + public function __construct(BlockIdentifier $idInfo, string $name, Block $imitated, ?BlockBreakInfo $breakInfo = null){ parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.75)); + $this->imitated = $imitated->getFullId(); + } + + public function getImitatedBlock() : Block{ + return BlockFactory::getInstance()->fromFullBlock($this->imitated); } public function getDropsForCompatibleTool(Item $item) : array{ return []; } + public function getSilkTouchDrops(Item $item) : array{ + return [$this->getImitatedBlock()->asItem()]; + } + public function isAffectedBySilkTouch() : bool{ return true; }