From d321094081a5c657bab123cee7dbbf83ef41942f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 14 Jul 2022 16:47:55 +0100 Subject: [PATCH] Added hanging roots --- src/block/BlockTypeIds.php | 3 +- src/block/HangingRoots.php | 58 +++++++++++++++++++ src/block/VanillaBlocks.php | 3 + .../BlockObjectToBlockStateSerializer.php | 1 + .../BlockStateToBlockObjectDeserializer.php | 1 + src/item/StringToItemParser.php | 1 + 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/block/HangingRoots.php diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index 5197b672f..11c6b87da 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -689,6 +689,7 @@ final class BlockTypeIds{ public const CAKE_WITH_CANDLE = 10662; public const CAKE_WITH_DYED_CANDLE = 10663; public const WITHER_ROSE = 10664; + public const HANGING_ROOTS = 10665; - public const FIRST_UNUSED_BLOCK_ID = 10665; + public const FIRST_UNUSED_BLOCK_ID = 10666; } diff --git a/src/block/HangingRoots.php b/src/block/HangingRoots.php new file mode 100644 index 000000000..cd85bcea7 --- /dev/null +++ b/src/block/HangingRoots.php @@ -0,0 +1,58 @@ +isSolid(); //TODO: not sure if this is the correct logic + } + + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if(!$blockReplace->getSide(Facing::UP)->isSolid()){ + return false; + } + return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + } + + public function onNearbyBlockChange() : void{ + if(!$this->canBeSupportedBy($this->getSide(Facing::UP))){ + $this->position->getWorld()->useBreakOn($this->position); + } + } + + public function getDropsForIncompatibleTool(Item $item) : array{ + if($item->hasEnchantment(VanillaEnchantments::SILK_TOUCH())){ + return $this->getDropsForCompatibleTool($item); + } + return []; + } +} diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 377b5a962..a3d0514e4 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -406,6 +406,7 @@ use function mb_strtolower; * @method static GrassPath GRASS_PATH() * @method static Gravel GRAVEL() * @method static Torch GREEN_TORCH() + * @method static HangingRoots HANGING_ROOTS() * @method static HardenedClay HARDENED_CLAY() * @method static HardenedGlass HARDENED_GLASS() * @method static HardenedGlassPane HARDENED_GLASS_PANE() @@ -1478,6 +1479,8 @@ final class VanillaBlocks{ $cakeBreakInfo = new BreakInfo(0.5); self::register("cake_with_candle", new CakeWithCandle(new BID(Ids::CAKE_WITH_CANDLE), "Cake With Candle", $cakeBreakInfo)); self::register("cake_with_dyed_candle", new CakeWithDyedCandle(new BID(Ids::CAKE_WITH_DYED_CANDLE), "Cake With Dyed Candle", $cakeBreakInfo)); + + self::register("hanging_roots", new HangingRoots(new BID(Ids::HANGING_ROOTS), "Hanging Roots", BreakInfo::instant(ToolType::SHEARS, 1))); } private static function registerMudBlocks() : void{ diff --git a/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php index 2ad760c62..7ca09189c 100644 --- a/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php @@ -872,6 +872,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{ $this->mapSimple(Blocks::GRASS_PATH(), Ids::GRASS_PATH); $this->mapSimple(Blocks::GRAVEL(), Ids::GRAVEL); $this->map(Blocks::GREEN_TORCH(), fn(Torch $block) => Helper::encodeColoredTorch($block, true, Writer::create(Ids::COLORED_TORCH_RG))); + $this->mapSimple(Blocks::HANGING_ROOTS(), Ids::HANGING_ROOTS); $this->mapSimple(Blocks::HARDENED_CLAY(), Ids::HARDENED_CLAY); $this->mapSimple(Blocks::HARDENED_GLASS(), Ids::HARD_GLASS); $this->mapSimple(Blocks::HARDENED_GLASS_PANE(), Ids::HARD_GLASS_PANE); diff --git a/src/data/bedrock/block/convert/BlockStateToBlockObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToBlockObjectDeserializer.php index 3c5a64e53..f12559ffc 100644 --- a/src/data/bedrock/block/convert/BlockStateToBlockObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToBlockObjectDeserializer.php @@ -643,6 +643,7 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize $this->map(Ids::GRAVEL, fn() => Blocks::GRAVEL()); $this->map(Ids::GRAY_GLAZED_TERRACOTTA, fn(Reader $in) => Helper::decodeGlazedTerracotta(DyeColor::GRAY(), $in)); $this->map(Ids::GREEN_GLAZED_TERRACOTTA, fn(Reader $in) => Helper::decodeGlazedTerracotta(DyeColor::GREEN(), $in)); + $this->map(Ids::HANGING_ROOTS, fn() => Blocks::HANGING_ROOTS()); $this->map(Ids::HARD_GLASS, fn() => Blocks::HARDENED_GLASS()); $this->map(Ids::HARD_GLASS_PANE, fn() => Blocks::HARDENED_GLASS_PANE()); $this->map(Ids::HARD_STAINED_GLASS, function(Reader $in) : Block{ diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 6042fb3b7..fb034e109 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -634,6 +634,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("grass_path", fn() => Blocks::GRASS_PATH()); $result->registerBlock("gravel", fn() => Blocks::GRAVEL()); $result->registerBlock("green_torch", fn() => Blocks::GREEN_TORCH()); + $result->registerBlock("hanging_roots", fn() => Blocks::HANGING_ROOTS()); $result->registerBlock("hard_glass", fn() => Blocks::HARDENED_GLASS()); $result->registerBlock("hard_glass_pane", fn() => Blocks::HARDENED_GLASS_PANE()); $result->registerBlock("hard_stained_glass", fn() => Blocks::STAINED_HARDENED_GLASS());