From f89025e5ecdc1a246ece9ee639543530202207dd Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Sun, 28 Jul 2024 14:37:52 -0400 Subject: [PATCH] Allow BoneMealing Allium Flower Bushes into Tall Alliums Signed-off-by: Joseph T. McQuigg --- .../world/level/block/BWGBlocks.java | 12 +++-- .../flower/BWGBonemealableFlowerBlock.java | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/flower/BWGBonemealableFlowerBlock.java diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/BWGBlocks.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/BWGBlocks.java index ded100b09..15d8106f9 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/BWGBlocks.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/BWGBlocks.java @@ -22,6 +22,7 @@ import net.potionstudios.biomeswevegone.world.level.block.plants.bush.*; import net.potionstudios.biomeswevegone.world.level.block.plants.cactus.BarrelCactusBlock; import net.potionstudios.biomeswevegone.world.level.block.plants.cactus.CarvedBarrelCactusBlock; +import net.potionstudios.biomeswevegone.world.level.block.plants.flower.BWGBonemealableFlowerBlock; import net.potionstudios.biomeswevegone.world.level.block.plants.flower.BWGFlowerBlock; import net.potionstudios.biomeswevegone.world.level.block.plants.flower.BWGTallFlowerBlock; import net.potionstudios.biomeswevegone.world.level.block.plants.flower.FlowerBlockFeature; @@ -116,15 +117,15 @@ public class BWGBlocks { /** Alliums */ public static final Supplier TALL_ALLIUM = registerTallFlower("tall_allium", MapColor.COLOR_PURPLE); - public static final FlowerBlockFeature ALLIUM_FLOWER_BUSH = registerFlower("allium_flower_bush", MapColor.COLOR_PURPLE, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0)); + public static final FlowerBlockFeature ALLIUM_FLOWER_BUSH = registerFlower("allium_flower_bush", MapColor.COLOR_PURPLE, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0), TALL_ALLIUM); public static final Supplier ALLIUM_PETAL_BLOCK = registerCubeAllBlockItem("allium_petal_block", () -> new Block(BlockBehaviour.Properties.copy(Blocks.HAY_BLOCK).mapColor(MapColor.COLOR_PURPLE).sound(SoundType.AZALEA))); public static final FlowerBlockFeature PINK_ALLIUM = registerFlower("pink_allium", MapColor.COLOR_PINK, Block.box(5.0, 0.0, 5.0, 11.0, 14.0, 11.0)); public static final Supplier TALL_PINK_ALLIUM = registerTallFlower("tall_pink_allium", MapColor.COLOR_PINK); - public static final FlowerBlockFeature PINK_ALLIUM_FLOWER_BUSH = registerFlower("pink_allium_flower_bush", MapColor.COLOR_PINK, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0)); + public static final FlowerBlockFeature PINK_ALLIUM_FLOWER_BUSH = registerFlower("pink_allium_flower_bush", MapColor.COLOR_PINK, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0), TALL_PINK_ALLIUM); public static final Supplier PINK_ALLIUM_PETAL_BLOCK = registerCubeAllBlockItem("pink_allium_petal_block", () -> new Block(BlockBehaviour.Properties.copy(Blocks.HAY_BLOCK).mapColor(MapColor.COLOR_PINK).sound(SoundType.AZALEA))); public static final FlowerBlockFeature WHITE_ALLIUM = registerFlower("white_allium", MapColor.TERRACOTTA_WHITE, Block.box(5.0, 0.0, 5.0, 11.0, 14.0, 11.0)); public static final Supplier TALL_WHITE_ALLIUM = registerTallFlower("tall_white_allium", MapColor.TERRACOTTA_WHITE); - public static final FlowerBlockFeature WHITE_ALLIUM_FLOWER_BUSH = registerFlower("white_allium_flower_bush", MapColor.TERRACOTTA_WHITE, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0)); + public static final FlowerBlockFeature WHITE_ALLIUM_FLOWER_BUSH = registerFlower("white_allium_flower_bush", MapColor.TERRACOTTA_WHITE, Block.box(2.0, 0.0, 2.0, 14.0, 13.0, 14.0), TALL_WHITE_ALLIUM); public static final Supplier WHITE_ALLIUM_PETAL_BLOCK = registerCubeAllBlockItem("white_allium_petal_block", () -> new Block(BlockBehaviour.Properties.copy(Blocks.HAY_BLOCK).mapColor(MapColor.TERRACOTTA_WHITE).sound(SoundType.AZALEA))); /** Glowing Pitcher Plants */ @@ -384,6 +385,11 @@ private static FlowerBlockFeature registerFlower(String key, MapColor mapColor, return new FlowerBlockFeature(key, flower); } + private static FlowerBlockFeature registerFlower(String key, MapColor mapColor, VoxelShape shape, Supplier growAble) { + Supplier flower = registerBlockItem(key, () -> new BWGBonemealableFlowerBlock(BlockBehaviour.Properties.copy(Blocks.WHITE_TULIP).mapColor(mapColor), BlockTags.DIRT, shape, growAble)); + return new FlowerBlockFeature(key, flower); + } + private static Supplier registerTallFlower(String key, MapColor mapColor) { return registerBlockItem(key, () -> new BWGTallFlowerBlock(BlockBehaviour.Properties.copy(Blocks.SUNFLOWER).mapColor(mapColor))); } diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/flower/BWGBonemealableFlowerBlock.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/flower/BWGBonemealableFlowerBlock.java new file mode 100644 index 000000000..5a061ff05 --- /dev/null +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/flower/BWGBonemealableFlowerBlock.java @@ -0,0 +1,50 @@ +package net.potionstudios.biomeswevegone.world.level.block.plants.flower; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.TagKey; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.DoublePlantBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Supplier; + +public class BWGBonemealableFlowerBlock extends BWGFlowerBlock implements BonemealableBlock { + + private final Supplier growableBlock; + + public BWGBonemealableFlowerBlock(Properties properties, TagKey validGround, VoxelShape shape, Supplier growableBlock) { + super(properties, validGround, shape); + this.growableBlock = growableBlock; + } + + public BWGBonemealableFlowerBlock(Properties properties, Supplier growableBlock) { + super(properties); + this.growableBlock = growableBlock; + } + + @Override + public boolean isValidBonemealTarget(@NotNull LevelReader level, @NotNull BlockPos pos, @NotNull BlockState state, boolean isClient) { + return true; + } + + @Override + public boolean isBonemealSuccess(@NotNull Level level, @NotNull RandomSource random, @NotNull BlockPos pos, @NotNull BlockState state) { + return true; + } + + @Override + public void performBonemeal(@NotNull ServerLevel level, @NotNull RandomSource random, @NotNull BlockPos pos, @NotNull BlockState state) { + BlockState growableState = growableBlock.get().defaultBlockState(); + if (growableState.canSurvive(level, pos)) + if (growableBlock.get() instanceof DoublePlantBlock) + DoublePlantBlock.placeAt(level, growableState, pos, 2); + else level.setBlock(pos, growableState, 3); + } +}