Cleaned up PlushBlock
This commit is contained in:
parent
c558bf485e
commit
509367b7a9
|
|
@ -18,41 +18,51 @@ import net.minecraft.world.level.material.FluidState;
|
||||||
import net.minecraft.world.level.material.Fluids;
|
import net.minecraft.world.level.material.Fluids;
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlushBlock extends Block implements SimpleWaterloggedBlock {
|
public class PlushBlock extends Block implements SimpleWaterloggedBlock {
|
||||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
||||||
// tfw you can copy-paste the class across modloaders :)
|
// tfw you can copy-paste the class across modloaders :)
|
||||||
public PlushBlock(Block.Properties properties) {
|
public PlushBlock(Block.Properties properties) {
|
||||||
super(properties.noOcclusion().sound(SoundType.WOOL));
|
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 DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
|
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
builder.add(FACING, WATERLOGGED);
|
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
|
@Override
|
||||||
public FluidState getFluidState(BlockState blockState) {
|
public @NotNull FluidState getFluidState(BlockState blockState) {
|
||||||
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
|
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
public @NotNull BlockState updateShape(BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) {
|
||||||
BlockPos blockPos = context.getClickedPos();
|
if (blockState.getValue(WATERLOGGED)) {
|
||||||
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)) {
|
|
||||||
levelAccessor.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
|
levelAccessor.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.updateShape(blockState, direction, blockState2, levelAccessor, blockPos, blockPos2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue