Stalactite block fixes
This commit is contained in:
parent
0402394201
commit
293f12de45
1 changed files with 69 additions and 33 deletions
|
@ -37,7 +37,6 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
|
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
|
||||||
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
||||||
public static final IntProperty SIZE = BlockProperties.SIZE;
|
public static final IntProperty SIZE = BlockProperties.SIZE;
|
||||||
private static final Mutable POS = new Mutable();
|
|
||||||
private static final VoxelShape[] SHAPES;
|
private static final VoxelShape[] SHAPES;
|
||||||
|
|
||||||
public StalactiteBlock(Block source) {
|
public StalactiteBlock(Block source) {
|
||||||
|
@ -57,16 +56,19 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
WorldView worldView = ctx.getWorld();
|
WorldView world = ctx.getWorld();
|
||||||
BlockPos blockPos = ctx.getBlockPos();
|
BlockPos pos = ctx.getBlockPos();
|
||||||
Direction dir = ctx.getSide();
|
Direction dir = ctx.getSide();
|
||||||
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER;
|
boolean water = world.getFluidState(pos).getFluid() == Fluids.WATER;
|
||||||
|
|
||||||
if (dir == Direction.UP) {
|
if (dir == Direction.DOWN) {
|
||||||
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
|
System.out.println("Check up!");
|
||||||
|
if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
|
||||||
|
System.out.println("Up true!");
|
||||||
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
||||||
}
|
}
|
||||||
else if (sideCoversSmallSquare(worldView, blockPos.down(), Direction.UP)) {
|
else if (isThis(world, pos.down()) || sideCoversSmallSquare(world, pos.down(), Direction.UP)) {
|
||||||
|
System.out.println("Up false!");
|
||||||
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -74,12 +76,15 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
|
System.out.println("Check down!");
|
||||||
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
if (isThis(world, pos.down()) || sideCoversSmallSquare(world, pos.down(), Direction.UP)) {
|
||||||
}
|
System.out.println("Down true!");
|
||||||
else if (sideCoversSmallSquare(worldView, blockPos.down(), Direction.UP)) {
|
|
||||||
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
||||||
}
|
}
|
||||||
|
else if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
|
||||||
|
System.out.println("Down false!");
|
||||||
|
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -88,16 +93,44 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||||
if (world.getBlockState(pos.down()).getBlock() instanceof StalactiteBlock) {
|
boolean hasUp = isThis(world, pos.up());
|
||||||
POS.setX(pos.getX());
|
boolean hasDown = isThis(world, pos.down());
|
||||||
POS.setZ(pos.getZ());
|
Mutable mut = new Mutable();
|
||||||
|
if (hasUp && hasDown) {
|
||||||
|
boolean floor = state.get(IS_FLOOR);
|
||||||
|
BlockPos second = floor ? pos.up() : pos.down();
|
||||||
|
BlockState bState = world.getBlockState(second);
|
||||||
|
world.setBlockState(pos, state.with(SIZE, 1).with(IS_FLOOR, floor));
|
||||||
|
world.setBlockState(second, bState.with(SIZE, 1).with(IS_FLOOR, !floor));
|
||||||
|
|
||||||
|
bState = state;
|
||||||
|
int startSize = floor ? 1 : 2;
|
||||||
|
mut.set(pos.getX(), pos.getY() + 1, pos.getZ());
|
||||||
|
for (int i = 0; i < 8 && isThis(bState); i++) {
|
||||||
|
world.setBlockState(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, false));
|
||||||
|
mut.setY(mut.getY() + 1);
|
||||||
|
bState = world.getBlockState(mut);
|
||||||
|
}
|
||||||
|
|
||||||
|
bState = state;
|
||||||
|
startSize = floor ? 2 : 1;
|
||||||
|
mut.set(pos.getX(), pos.getY() - 1, pos.getZ());
|
||||||
|
for (int i = 0; i < 8 && isThis(bState); i++) {
|
||||||
|
world.setBlockState(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, true));
|
||||||
|
mut.setY(mut.getY() - 1);
|
||||||
|
bState = world.getBlockState(mut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (hasDown) {
|
||||||
|
mut.setX(pos.getX());
|
||||||
|
mut.setZ(pos.getZ());
|
||||||
for (int i = 1; i < 8; i++) {
|
for (int i = 1; i < 8; i++) {
|
||||||
POS.setY(pos.getY() - i);
|
mut.setY(pos.getY() - i);
|
||||||
if (world.getBlockState(POS).getBlock() instanceof StalactiteBlock) {
|
if (isThis(world, mut)) {
|
||||||
BlockState state2 = world.getBlockState(POS);
|
BlockState state2 = world.getBlockState(mut);
|
||||||
int size = state2.get(SIZE);
|
int size = state2.get(SIZE);
|
||||||
if (size < i) {
|
if (size < i) {
|
||||||
world.setBlockState(POS, state2.with(SIZE, i).with(IS_FLOOR, true));
|
world.setBlockState(mut, state2.with(SIZE, i).with(IS_FLOOR, true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
|
@ -108,16 +141,16 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (world.getBlockState(pos.up()).getBlock() instanceof StalactiteBlock) {
|
else if (hasUp) {
|
||||||
POS.setX(pos.getX());
|
mut.setX(pos.getX());
|
||||||
POS.setZ(pos.getZ());
|
mut.setZ(pos.getZ());
|
||||||
for (int i = 1; i < 8; i++) {
|
for (int i = 1; i < 8; i++) {
|
||||||
POS.setY(pos.getY() + i);
|
mut.setY(pos.getY() + i);
|
||||||
if (world.getBlockState(POS).getBlock() instanceof StalactiteBlock) {
|
if (isThis(world, mut)) {
|
||||||
BlockState state2 = world.getBlockState(POS);
|
BlockState state2 = world.getBlockState(mut);
|
||||||
int size = state2.get(SIZE);
|
int size = state2.get(SIZE);
|
||||||
if (size < i) {
|
if (size < i) {
|
||||||
world.setBlockState(POS, state2.with(SIZE, i).with(IS_FLOOR, false));
|
world.setBlockState(mut, state2.with(SIZE, i).with(IS_FLOOR, false));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
|
@ -130,17 +163,20 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isThis(WorldView world, BlockPos pos) {
|
||||||
|
return isThis(world.getBlockState(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isThis(BlockState state) {
|
||||||
|
return state.getBlock() instanceof StalactiteBlock;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||||
if (!canPlaceAt(state, world, pos)) {
|
if (!canPlaceAt(state, world, pos)) {
|
||||||
return Blocks.AIR.getDefaultState();
|
return Blocks.AIR.getDefaultState();
|
||||||
}
|
}
|
||||||
else {
|
return state;
|
||||||
if (checkUp(world, neighborPos, state.get(SIZE))) {
|
|
||||||
state = state.with(IS_FLOOR, false);
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -152,13 +188,13 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
||||||
private boolean checkUp(BlockView world, BlockPos pos, int size) {
|
private boolean checkUp(BlockView world, BlockPos pos, int size) {
|
||||||
BlockPos p = pos.up();
|
BlockPos p = pos.up();
|
||||||
BlockState state = world.getBlockState(p);
|
BlockState state = world.getBlockState(p);
|
||||||
return (state.getBlock() instanceof StalactiteBlock && state.get(SIZE) >= size) || state.isFullCube(world, p);
|
return (isThis(state) && state.get(SIZE) >= size) || state.isFullCube(world, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkDown(BlockView world, BlockPos pos, int size) {
|
private boolean checkDown(BlockView world, BlockPos pos, int size) {
|
||||||
BlockPos p = pos.down();
|
BlockPos p = pos.down();
|
||||||
BlockState state = world.getBlockState(p);
|
BlockState state = world.getBlockState(p);
|
||||||
return (state.getBlock() instanceof StalactiteBlock && state.get(SIZE) >= size) || state.isFullCube(world, p);
|
return (isThis(state) && state.get(SIZE) >= size) || state.isFullCube(world, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue