Set plush blocks shape and make them waterloggable
Backport of c558bf485e
This commit is contained in:
parent
4f6fc5bb85
commit
1aa1f89dcc
|
|
@ -1,33 +1,65 @@
|
||||||
package xyz.nearmisses.patience.mc_rebalance;
|
package xyz.nearmisses.patience.mc_rebalance;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.level.BlockGetter;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.block.Block;
|
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.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
|
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 net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
//import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
//import net.minecraft.world.level.block.state.properties.EnumProperty;
|
//import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
|
|
||||||
public class PlushBlock extends Block {
|
public class PlushBlock extends Block implements SimpleWaterloggedBlock {
|
||||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
|
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||||
// private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
// private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||||
//public static final EnumProperty<Direction> FACING = BlockStateProperties.FACING;
|
//public static final EnumProperty<Direction> FACING = BlockStateProperties.FACING;
|
||||||
|
|
||||||
public PlushBlock(Block.Properties properties) {
|
public PlushBlock(Block.Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
builder.add(FACING);
|
builder.add(FACING, WATERLOGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidState getFluidState(BlockState pState) {
|
||||||
|
return pState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(pState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||||
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
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 pState, Direction pFacing, BlockState pFacingState, LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pFacingPos) {
|
||||||
|
if (pState.getValue(WATERLOGGED)) {
|
||||||
|
pLevel.scheduleTick(pCurrentPos, Fluids.WATER, Fluids.WATER.getTickDelay(pLevel));
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.updateShape(pState, pFacing, pFacingState, pLevel, pCurrentPos, pFacingPos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue