diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index bf85505de..926bae0df 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -403,12 +403,13 @@ class BlockFactory{ //TODO: find a better way to deal with this split $this->register(new Leaves(new BID($magicNumber >= 4 ? Ids::LEAVES2 : Ids::LEAVES, $magicNumber & 0x03), $name . " Leaves", $treeType)); - $this->register(new Log(new BID($magicNumber >= 4 ? Ids::LOG2 : Ids::LOG, $magicNumber & 0x03), $name . " Log", $treeType)); + $this->register(new Log(new BID($magicNumber >= 4 ? Ids::LOG2 : Ids::LOG, $magicNumber & 0x03), $name . " Log", $treeType, false)); - $wood = new Wood(new BID(Ids::WOOD, $magicNumber), $name . " Wood", $treeType); + $wood = new Wood(new BID(Ids::WOOD, $magicNumber), $name . " Wood", $treeType, false); $this->register($wood); $this->remap($magicNumber >= 4 ? Ids::LOG2 : Ids::LOG, ($magicNumber & 0x03) | 0b1100, $wood); + $this->register(new Log(BlockLegacyIdHelper::getStrippedLogIdentifier($treeType), "Stripped " . $treeType->getDisplayName() . " Log", $treeType, true)); $this->register(new FenceGate(BlockLegacyIdHelper::getWoodenFenceIdentifier($treeType), $treeType->getDisplayName() . " Fence Gate")); $this->register(new WoodenStairs(BlockLegacyIdHelper::getWoodenStairsIdentifier($treeType), $treeType->getDisplayName() . " Stairs")); $this->register(new WoodenDoor(BlockLegacyIdHelper::getWoodenDoorIdentifier($treeType), $treeType->getDisplayName() . " Door")); diff --git a/src/block/BlockLegacyIdHelper.php b/src/block/BlockLegacyIdHelper.php index c9408afb5..082f5132a 100644 --- a/src/block/BlockLegacyIdHelper.php +++ b/src/block/BlockLegacyIdHelper.php @@ -178,6 +178,24 @@ final class BlockLegacyIdHelper{ throw new AssumptionFailedError("Switch should cover all wood types"); } + public static function getStrippedLogIdentifier(TreeType $treeType) : BlockIdentifier{ + switch($treeType->id()){ + case TreeType::OAK()->id(): + return new BlockIdentifier(Ids::STRIPPED_OAK_LOG, 0); + case TreeType::SPRUCE()->id(): + return new BlockIdentifier(Ids::STRIPPED_SPRUCE_LOG, 0); + case TreeType::BIRCH()->id(): + return new BlockIdentifier(Ids::STRIPPED_BIRCH_LOG, 0); + case TreeType::JUNGLE()->id(): + return new BlockIdentifier(Ids::STRIPPED_JUNGLE_LOG, 0); + case TreeType::ACACIA()->id(): + return new BlockIdentifier(Ids::STRIPPED_ACACIA_LOG, 0); + case TreeType::DARK_OAK()->id(): + return new BlockIdentifier(Ids::STRIPPED_DARK_OAK_LOG, 0); + } + throw new AssumptionFailedError("Switch should cover all wood types"); + } + public static function getGlazedTerracottaIdentifier(DyeColor $color) : BlockIdentifier{ switch($color->id()){ case DyeColor::WHITE()->id(): diff --git a/src/block/Log.php b/src/block/Log.php index 06364c746..eacb817b5 100644 --- a/src/block/Log.php +++ b/src/block/Log.php @@ -27,4 +27,8 @@ use pocketmine\block\utils\PillarRotationInMetadataTrait; class Log extends Wood{ use PillarRotationInMetadataTrait; + + protected function getAxisMetaShift() : int{ + return $this->isStripped() ? 0 : 2; + } } diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 3f23880f9..7cd2df77e 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -607,6 +607,12 @@ use function assert; * @method static StonePressurePlate STONE_PRESSURE_PLATE() * @method static Slab STONE_SLAB() * @method static Stair STONE_STAIRS() + * @method static Log STRIPPED_ACACIA_LOG() + * @method static Log STRIPPED_BIRCH_LOG() + * @method static Log STRIPPED_DARK_OAK_LOG() + * @method static Log STRIPPED_JUNGLE_LOG() + * @method static Log STRIPPED_OAK_LOG() + * @method static Log STRIPPED_SPRUCE_LOG() * @method static Sugarcane SUGARCANE() * @method static DoublePlant SUNFLOWER() * @method static TallGrass TALL_GRASS() @@ -1241,6 +1247,12 @@ final class VanillaBlocks{ self::register("stone_pressure_plate", $factory->get(70, 0)); self::register("stone_slab", $factory->get(421, 2)); self::register("stone_stairs", $factory->get(435, 0)); + self::register("stripped_acacia_log", $factory->get(263, 0)); + self::register("stripped_birch_log", $factory->get(261, 0)); + self::register("stripped_dark_oak_log", $factory->get(264, 0)); + self::register("stripped_jungle_log", $factory->get(262, 0)); + self::register("stripped_oak_log", $factory->get(265, 0)); + self::register("stripped_spruce_log", $factory->get(260, 0)); self::register("sugarcane", $factory->get(83, 0)); self::register("sunflower", $factory->get(175, 0)); self::register("tall_grass", $factory->get(31, 1)); diff --git a/src/block/Wood.php b/src/block/Wood.php index 6db53bee0..56cab4cad 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -24,13 +24,19 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\TreeType; +use pocketmine\item\Item; +use pocketmine\math\Vector3; +use pocketmine\player\Player; class Wood extends Opaque{ /** @var TreeType */ private $treeType; - public function __construct(BlockIdentifier $idInfo, string $name, TreeType $treeType, ?BlockBreakInfo $breakInfo = null){ + private bool $stripped; + + public function __construct(BlockIdentifier $idInfo, string $name, TreeType $treeType, bool $stripped, ?BlockBreakInfo $breakInfo = null){ + $this->stripped = $stripped; //TODO: this should be dynamic, but right now legacy shit gets in the way parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.0, BlockToolType::AXE)); $this->treeType = $treeType; } @@ -42,6 +48,8 @@ class Wood extends Opaque{ return $this->treeType; } + public function isStripped() : bool{ return $this->stripped; } + public function getFuelTime() : int{ return 300; } @@ -53,4 +61,12 @@ class Wood extends Opaque{ public function getFlammability() : int{ return 5; } + + public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if(!$this->stripped && ($item->getBlockToolType() & BlockToolType::AXE) !== 0){ + //TODO: strip logs; can't implement this yet because of legacy limitations :( + return true; + } + return false; + } }