Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand All @@ -25,7 +29,9 @@
import java.util.Map;
import java.util.function.Supplier;

public class FancyCableBlock extends CableBlock implements IFacadableBlock {
public class FancyCableBlock extends CableBlock implements IFacadableBlock, SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public static final BooleanProperty NORTH = BooleanProperty.create("north");

public static final BooleanProperty SOUTH = BooleanProperty.create("south");
Expand Down Expand Up @@ -73,6 +79,7 @@ public FancyCableBlock(Properties properties) {
super(properties);
registerDefaultState(
defaultBlockState()
.setValue(WATERLOGGED, false)
.setValue(NORTH, false)
.setValue(SOUTH, false)
.setValue(EAST, false)
Expand All @@ -82,6 +89,13 @@ public FancyCableBlock(Properties properties) {
);
}

@SuppressWarnings("deprecation")
@Override
public FluidState getFluidState(BlockState state) {

return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

@Override
public IFacadableBlock getNonFacadeBlock() {

Expand All @@ -97,7 +111,9 @@ public IFacadableBlock getFacadeBlock() {
@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext ctx) {

return getState(defaultBlockState(), ctx.getLevel(), ctx.getClickedPos());
FluidState fluid = ctx.getLevel().getFluidState(ctx.getClickedPos());
BlockState base = defaultBlockState().setValue(WATERLOGGED, fluid.getType() == Fluids.WATER);
return getState(base, ctx.getLevel(), ctx.getClickedPos());
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -139,6 +155,9 @@ public BlockState updateShape(
BlockPos facingPos
) {

if (state.getValue(WATERLOGGED)) {
world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
return getState(state, world, pos);
}

Expand All @@ -148,7 +167,9 @@ public BlockState getStateForPlacementByFacadePlan(
BlockPos pos
) {

return getState(defaultBlockState(), level, pos);
FluidState fluid = level.getFluidState(pos);
BlockState base = defaultBlockState().setValue(WATERLOGGED, fluid.getType() == Fluids.WATER);
return getState(base, level, pos);
}

protected static VoxelShape getShape(BlockState state) {
Expand Down Expand Up @@ -178,7 +199,7 @@ protected static VoxelShape combineShapes(
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {

super.createBlockStateDefinition(builder);
builder.add(NORTH, SOUTH, EAST, WEST, UP, DOWN);
builder.add(WATERLOGGED, NORTH, SOUTH, EAST, WEST, UP, DOWN);
}

protected BlockState getState(
Expand Down