diff --git a/src/main/java/org/violetmoon/quark/content/building/block/WoodPostBlock.java b/src/main/java/org/violetmoon/quark/content/building/block/WoodPostBlock.java index c4818d764..c6f6989c7 100644 --- a/src/main/java/org/violetmoon/quark/content/building/block/WoodPostBlock.java +++ b/src/main/java/org/violetmoon/quark/content/building/block/WoodPostBlock.java @@ -35,10 +35,10 @@ public class WoodPostBlock extends ZetaBlock implements SimpleWaterloggedBlock { - private static float START = 0F; - private static float END = 16F; - private static float LEFT_EDGE = 6F; - private static float RIGHT_EDGE = 10F; + private static final float START = 0F; + private static final float END = 16F; + private static final float LEFT_EDGE = 6F; + private static final float RIGHT_EDGE = 10F; private static final VoxelShape CENTER_SHAPE = Block.box(LEFT_EDGE, LEFT_EDGE, LEFT_EDGE, RIGHT_EDGE, RIGHT_EDGE, RIGHT_EDGE); @@ -132,7 +132,18 @@ public FluidState getFluidState(BlockState state) { @Override public BlockState getStateForPlacement(BlockPlaceContext context) { - return getState(context.getLevel(), context.getClickedPos(), context.getClickedFace().getAxis()); + Axis axis = context.getClickedFace().getAxis(); + BlockPos pos = context.getClickedPos(); + Level level = context.getLevel(); + BlockState state = defaultBlockState().setValue(WATERLOGGED, level.getFluidState(pos).getType() == Fluids.WATER) + .setValue(AXIS, axis); + + for(Direction d : Direction.values()) { + if(axis != d.getAxis()) { + state = state.setValue(SIDES[d.ordinal()], PostSideType.get(level, pos, d)); + } + } + return state; } @NotNull @@ -141,46 +152,10 @@ public BlockState updateShape(BlockState state, @NotNull Direction facing, @NotN if(state.getValue(WATERLOGGED)) { level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } - + state = state.setValue(SIDES[facing.ordinal()], PostSideType.get(level, pos, facing)); return super.updateShape(state, facing, facingState, level, pos, facingPos); } - @Override - public void neighborChanged(@NotNull BlockState state, @NotNull Level worldIn, @NotNull BlockPos pos, @NotNull Block blockIn, @NotNull BlockPos fromPos, boolean isMoving) { - super.neighborChanged(state, worldIn, pos, blockIn, fromPos, isMoving); - - BlockState newState = getState(worldIn, pos, state.getValue(AXIS)); - if(!newState.equals(state)) - worldIn.setBlockAndUpdate(pos, newState); - } - - private BlockState getState(Level world, BlockPos pos, Axis axis) { - BlockState state = defaultBlockState().setValue(WATERLOGGED, world.getFluidState(pos).getType() == Fluids.WATER).setValue(AXIS, axis); - - for(Direction d : Direction.values()) { - if(d.getAxis() == axis) - continue; - - EnumProperty prop = SIDES[d.ordinal()]; - BlockState sideState = world.getBlockState(pos.relative(d)); - - if((sideState.getBlock() instanceof ChainBlock && sideState.getValue(BlockStateProperties.AXIS) == d.getAxis()) - || (d == Direction.DOWN && sideState.getBlock() instanceof LanternBlock && sideState.getValue(LanternBlock.HANGING)) - || (d == Direction.DOWN && sideState.getBlock() instanceof CeilingHangingSignBlock)) { - - state = state.setValue(prop, PostSideType.CHAIN); - continue; - } - - if(sideState.getBlock() instanceof WoodPostBlock && sideState.getValue(AXIS) == d.getAxis()) { - state = state.setValue(prop, PostSideType.OTHER_POST); - continue; - } - } - - return state; - } - @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(WATERLOGGED, AXIS); @@ -193,9 +168,9 @@ public enum PostSideType implements StringRepresentable { CHAIN("chain"), OTHER_POST("other_post"); - private String name; + private final String name; - private PostSideType(String name) { + PostSideType(String name) { this.name = name; } @@ -212,8 +187,22 @@ public String getSerializedName() { public boolean isSolid() { return this != NONE; } - - } + private static PostSideType get(LevelAccessor world, BlockPos pos, Direction d) { + BlockState sideState = world.getBlockState(pos.relative(d)); + + if((sideState.getBlock() instanceof ChainBlock && sideState.getValue(BlockStateProperties.AXIS) == d.getAxis()) + || (d == Direction.DOWN && sideState.getBlock() instanceof LanternBlock && sideState.getValue(LanternBlock.HANGING)) + || (d == Direction.DOWN && sideState.getBlock() instanceof CeilingHangingSignBlock)) { + + return PostSideType.CHAIN; + } + + if(sideState.getBlock() instanceof WoodPostBlock && sideState.getValue(AXIS) == d.getAxis()) { + return PostSideType.OTHER_POST; + } + return PostSideType.NONE; + } + } } diff --git a/src/main/resources/assets/quark/models/block/bamboo_post.json b/src/main/resources/assets/quark/models/block/bamboo_post.json index cdd0b71d4..1fa5cf909 100644 --- a/src/main/resources/assets/quark/models/block/bamboo_post.json +++ b/src/main/resources/assets/quark/models/block/bamboo_post.json @@ -1,7 +1,7 @@ { "parent": "quark:block/template/custom_fence_post", "textures": { - "particle": "minecraft:block/bamboo_post", + "particle": "quark:block/bamboo_post", "texture": "quark:block/bamboo_post" } } \ No newline at end of file diff --git a/src/main/resources/assets/quark/models/block/stripped_bamboo_post.json b/src/main/resources/assets/quark/models/block/stripped_bamboo_post.json index b16e6a568..ea07036f6 100644 --- a/src/main/resources/assets/quark/models/block/stripped_bamboo_post.json +++ b/src/main/resources/assets/quark/models/block/stripped_bamboo_post.json @@ -1,7 +1,7 @@ { "parent": "quark:block/template/custom_fence_post", "textures": { - "particle": "minecraft:block/stripped_bamboo_post", + "particle": "quark:block/stripped_bamboo_post", "texture": "quark:block/stripped_bamboo_post" } } \ No newline at end of file