mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 07:27:15 +01:00
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:
parent
f8180ee91d
commit
f724504b44
1 changed files with 14 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue