diff --git a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java index efc548e31..d2b15211c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java @@ -4,14 +4,18 @@ import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationS import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.BlockTags; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.AzaleaBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.SaplingBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; public class TreeFertilizerItem extends Item { @@ -24,7 +28,7 @@ public class TreeFertilizerItem extends Item { BlockState state = context.getLevel() .getBlockState(context.getClickedPos()); Block block = state.getBlock(); - if (block instanceof SaplingBlock) { + if (block instanceof BonemealableBlock bonemealableBlock && state.is(BlockTags.SAPLINGS)) { if (context.getLevel().isClientSide) { BoneMealItem.addGrowthParticles(context.getLevel(), context.getClickedPos(), 100); @@ -38,11 +42,11 @@ public class TreeFertilizerItem extends Item { if (context.getLevel() .getBlockState(saplingPos.offset(pos)) .getBlock() == block) - world.setBlockAndUpdate(pos.above(10), state.setValue(SaplingBlock.STAGE, 1)); + world.setBlockAndUpdate(pos.above(10), withStage(state, 1)); } - ((SaplingBlock) block).performBonemeal(world, world.getRandom(), BlockPos.ZERO.above(10), - state.setValue(SaplingBlock.STAGE, 1)); + bonemealableBlock.performBonemeal(world, world.getRandom(), BlockPos.ZERO.above(10), + withStage(state, 1)); for (BlockPos pos : world.blocksAdded.keySet()) { BlockPos actualPos = pos.offset(saplingPos).below(10); @@ -76,6 +80,12 @@ public class TreeFertilizerItem extends Item { return super.useOn(context); } + private BlockState withStage(BlockState original, int stage) { + if (!original.hasProperty(BlockStateProperties.STAGE)) + return original; + return original.setValue(BlockStateProperties.STAGE, 1); + } + private static class TreesDreamWorld extends PlacementSimulationServerWorld { private final BlockPos saplingPos; private final BlockState soil;