Azaleas can dream

- Azaleas (and all other Bonemealable blocks tagged with #minecraft:saplings) are now eligible for tree fertilizer
- fix #2942
This commit is contained in:
Grimmauld 2022-05-19 22:45:35 +02:00
parent f8180ee91d
commit f724504b44

View file

@ -4,14 +4,18 @@ import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationS
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.BoneMealItem;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext; 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.Block;
import net.minecraft.world.level.block.Blocks; 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.SaplingBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
public class TreeFertilizerItem extends Item { public class TreeFertilizerItem extends Item {
@ -24,7 +28,7 @@ public class TreeFertilizerItem extends Item {
BlockState state = context.getLevel() BlockState state = context.getLevel()
.getBlockState(context.getClickedPos()); .getBlockState(context.getClickedPos());
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof SaplingBlock) { if (block instanceof BonemealableBlock bonemealableBlock && state.is(BlockTags.SAPLINGS)) {
if (context.getLevel().isClientSide) { if (context.getLevel().isClientSide) {
BoneMealItem.addGrowthParticles(context.getLevel(), context.getClickedPos(), 100); BoneMealItem.addGrowthParticles(context.getLevel(), context.getClickedPos(), 100);
@ -38,11 +42,11 @@ public class TreeFertilizerItem extends Item {
if (context.getLevel() if (context.getLevel()
.getBlockState(saplingPos.offset(pos)) .getBlockState(saplingPos.offset(pos))
.getBlock() == block) .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), bonemealableBlock.performBonemeal(world, world.getRandom(), BlockPos.ZERO.above(10),
state.setValue(SaplingBlock.STAGE, 1)); withStage(state, 1));
for (BlockPos pos : world.blocksAdded.keySet()) { for (BlockPos pos : world.blocksAdded.keySet()) {
BlockPos actualPos = pos.offset(saplingPos).below(10); BlockPos actualPos = pos.offset(saplingPos).below(10);
@ -76,6 +80,12 @@ public class TreeFertilizerItem extends Item {
return super.useOn(context); 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 static class TreesDreamWorld extends PlacementSimulationServerWorld {
private final BlockPos saplingPos; private final BlockPos saplingPos;
private final BlockState soil; private final BlockState soil;