Cleaned up PlushBlock

This commit is contained in:
patience 2026-02-06 14:51:31 +00:00
parent c558bf485e
commit 509367b7a9
No known key found for this signature in database

View file

@ -18,41 +18,51 @@ 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.VoxelShape;
import org.jetbrains.annotations.NotNull;
public class PlushBlock extends Block implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
// tfw you can copy-paste the class across modloaders :)
public PlushBlock(Block.Properties properties) {
super(properties.noOcclusion().sound(SoundType.WOOL));
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
this.registerDefaultState(this.stateDefinition.any()
.setValue(FACING, Direction.NORTH)
.setValue(WATERLOGGED, false)
);
}
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED);
}
@Override // New collision box
public @NotNull VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return Block.box(3.0, 0.0, 3.0, 13.0, 15.0, 13.0);
}
// Water functions
@Override
public FluidState getFluidState(BlockState blockState) {
public @NotNull FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockPos blockPos = context.getClickedPos();
FluidState fluidState = context.getLevel().getFluidState(blockPos);
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
@Override
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return Block.box(3.0, 0.0, 3.0, 13.0, 15.0, 13.0);
}
@Override
public BlockState updateShape(BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) {
if ((Boolean)blockState.getValue(WATERLOGGED)) {
public @NotNull BlockState updateShape(BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) {
if (blockState.getValue(WATERLOGGED)) {
levelAccessor.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
}
return super.updateShape(blockState, direction, blockState2, levelAccessor, blockPos, blockPos2);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockPos blockPos = context.getClickedPos();
FluidState fluidState = context.getLevel().getFluidState(blockPos);
return this.defaultBlockState()
.setValue(FACING, context.getHorizontalDirection().getOpposite())
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}