Cactus fixes
This commit is contained in:
parent
6d7e0b4719
commit
ed35e28e94
1 changed files with 34 additions and 33 deletions
|
@ -107,10 +107,7 @@ public class NeonCactusPlantBlock extends BlockBaseNotFull implements SimpleWate
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
|
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
|
||||||
if (!canSurvive(state, world, pos)) {
|
world.getBlockTicks().scheduleTick(pos, this, 2);
|
||||||
world.getBlockTicks().scheduleTick(pos, this, MHelper.randRange(1, 4, world.getRandom()));
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
if ((Boolean) state.getValue(WATERLOGGED)) {
|
if ((Boolean) state.getValue(WATERLOGGED)) {
|
||||||
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
|
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
|
||||||
}
|
}
|
||||||
|
@ -131,7 +128,7 @@ public class NeonCactusPlantBlock extends BlockBaseNotFull implements SimpleWate
|
||||||
@Override
|
@Override
|
||||||
public void tick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, Random random) {
|
public void tick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, Random random) {
|
||||||
if (!blockState.canSurvive(serverLevel, blockPos)) {
|
if (!blockState.canSurvive(serverLevel, blockPos)) {
|
||||||
serverLevel.destroyBlock(blockPos, true);
|
serverLevel.destroyBlock(blockPos, true, null, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +187,8 @@ public class NeonCactusPlantBlock extends BlockBaseNotFull implements SimpleWate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (length > 1 && world.getBlockState(pos.below()).is(this)) {
|
else if (length > 1 && world.getBlockState(pos.relative(dir.getOpposite())).is(this)) {
|
||||||
Direction side = BlocksHelper.randomHorizontal(random);
|
Direction side = getSideDirection(world, pos, state, dir, random);
|
||||||
BlockPos sidePos = pos.relative(side);
|
BlockPos sidePos = pos.relative(side);
|
||||||
if (world.isEmptyBlock(sidePos)) {
|
if (world.isEmptyBlock(sidePos)) {
|
||||||
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, side);
|
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, side);
|
||||||
|
@ -252,11 +249,26 @@ public class NeonCactusPlantBlock extends BlockBaseNotFull implements SimpleWate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (length > 1 && world.getBlockState(pos.below()).is(this)) {
|
else if (length > 1 && world.getBlockState(pos.below()).is(this)) {
|
||||||
|
Direction side = getSideDirection(world, pos, state, dir, random);
|
||||||
|
BlockPos sidePos = pos.relative(side);
|
||||||
|
if (world.isEmptyBlock(sidePos)) {
|
||||||
|
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, side);
|
||||||
|
BlocksHelper.setWithoutUpdate(world, sidePos, placement);
|
||||||
|
ends.add(sidePos.mutable());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, dir);
|
||||||
|
BlocksHelper.setWithoutUpdate(world, pos.relative(dir), placement);
|
||||||
|
mutateStem(placement, world, pos, MAX_LENGTH);
|
||||||
|
pos.move(dir);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Direction getSideDirection(WorldGenLevel world, BlockPos pos, BlockState iterState, Direction dir, Random random) {
|
||||||
MutableBlockPos iterPos = pos.mutable();
|
MutableBlockPos iterPos = pos.mutable();
|
||||||
BlockState iterState = state;
|
Direction startDir = dir;
|
||||||
Direction startDir = null;
|
|
||||||
Direction lastDir = null;
|
Direction lastDir = null;
|
||||||
while (iterState.is(this)) {
|
while (iterState.is(this) && startDir.getAxis().isVertical()) {
|
||||||
startDir = iterState.getValue(FACING);
|
startDir = iterState.getValue(FACING);
|
||||||
if (lastDir == null) {
|
if (lastDir == null) {
|
||||||
for (Direction side: BlocksHelper.HORIZONTAL) {
|
for (Direction side: BlocksHelper.HORIZONTAL) {
|
||||||
|
@ -276,20 +288,9 @@ public class NeonCactusPlantBlock extends BlockBaseNotFull implements SimpleWate
|
||||||
|
|
||||||
Direction side = lastDir == null ? BlocksHelper.randomHorizontal(random) : lastDir.getClockWise();
|
Direction side = lastDir == null ? BlocksHelper.randomHorizontal(random) : lastDir.getClockWise();
|
||||||
if (side.getOpposite() == startDir) {
|
if (side.getOpposite() == startDir) {
|
||||||
side = side.getClockWise();
|
side = side.getOpposite();
|
||||||
}
|
}
|
||||||
BlockPos sidePos = pos.relative(side);
|
return side;
|
||||||
if (world.isEmptyBlock(sidePos)) {
|
|
||||||
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, side);
|
|
||||||
BlocksHelper.setWithoutUpdate(world, sidePos, placement);
|
|
||||||
ends.add(sidePos.mutable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BlockState placement = state.setValue(SHAPE, TripleShape.TOP).setValue(CACTUS_BOTTOM, CactusBottom.EMPTY).setValue(WATERLOGGED, false).setValue(FACING, dir);
|
|
||||||
BlocksHelper.setWithoutUpdate(world, pos.relative(dir), placement);
|
|
||||||
mutateStem(placement, world, pos, MAX_LENGTH);
|
|
||||||
pos.move(dir);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue