Fix tree fertilizer spreading podzol. Backport a440ab6

This commit is contained in:
Snownee 2021-04-01 01:41:57 +08:00
parent 65d21c374b
commit ba63cc3e7f

View file

@ -31,8 +31,8 @@ public class TreeFertilizerItem extends Item {
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
TreesDreamWorld world = new TreesDreamWorld((ServerWorld) context.getWorld());
BlockPos saplingPos = context.getPos(); BlockPos saplingPos = context.getPos();
TreesDreamWorld world = new TreesDreamWorld((ServerWorld) context.getWorld(), saplingPos);
for (BlockPos pos : BlockPos.getAllInBoxMutable(-1, 0, -1, 1, 0, 1)) { for (BlockPos pos : BlockPos.getAllInBoxMutable(-1, 0, -1, 1, 0, 1)) {
if (context.getWorld() if (context.getWorld()
@ -45,8 +45,8 @@ public class TreeFertilizerItem extends Item {
state.with(SaplingBlock.STAGE, 1)); state.with(SaplingBlock.STAGE, 1));
for (BlockPos pos : world.blocksAdded.keySet()) { for (BlockPos pos : world.blocksAdded.keySet()) {
BlockPos actualPos = pos.add(saplingPos) BlockPos actualPos = pos.add(saplingPos).down(10);
.down(10); BlockState newState = world.blocksAdded.get(pos);
// Don't replace Bedrock // Don't replace Bedrock
if (context.getWorld() if (context.getWorld()
@ -54,21 +54,15 @@ public class TreeFertilizerItem extends Item {
.getBlockHardness(context.getWorld(), actualPos) == -1) .getBlockHardness(context.getWorld(), actualPos) == -1)
continue; continue;
// Don't replace solid blocks with leaves // Don't replace solid blocks with leaves
if (!world.getBlockState(pos) if (!newState.isNormalCube(world, pos)
.isNormalCube(world, pos)
&& !context.getWorld() && !context.getWorld()
.getBlockState(actualPos) .getBlockState(actualPos)
.getCollisionShape(context.getWorld(), actualPos) .getCollisionShape(context.getWorld(), actualPos)
.isEmpty()) .isEmpty())
continue; continue;
if (world.getBlockState(pos)
.getBlock() == Blocks.GRASS_BLOCK
|| world.getBlockState(pos)
.getBlock() == Blocks.PODZOL)
continue;
context.getWorld() context.getWorld()
.setBlockState(actualPos, world.getBlockState(pos)); .setBlockState(actualPos, newState);
} }
if (context.getPlayer() != null && !context.getPlayer() if (context.getPlayer() != null && !context.getPlayer()
@ -83,18 +77,26 @@ public class TreeFertilizerItem extends Item {
} }
private class TreesDreamWorld extends PlacementSimulationServerWorld { private class TreesDreamWorld extends PlacementSimulationServerWorld {
private final BlockState soil;
protected TreesDreamWorld(ServerWorld wrapped) { protected TreesDreamWorld(ServerWorld wrapped, BlockPos saplingPos) {
super(wrapped); super(wrapped);
soil = wrapped.getBlockState(saplingPos.down());
} }
@Override @Override
public BlockState getBlockState(BlockPos pos) { public BlockState getBlockState(BlockPos pos) {
if (pos.getY() <= 9) if (pos.getY() <= 9)
return Blocks.GRASS_BLOCK.getDefaultState(); return soil;
return super.getBlockState(pos); return super.getBlockState(pos);
} }
@Override
public boolean setBlockState(BlockPos pos, BlockState newState, int flags) {
if (newState.getBlock() == Blocks.PODZOL)
return true;
return super.setBlockState(pos, newState, flags);
}
} }
} }