mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
reinforced rail collision
This commit is contained in:
parent
a57a35e867
commit
89f22c60cc
1 changed files with 101 additions and 80 deletions
|
@ -20,87 +20,108 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||
|
||||
public static IProperty<RailShape> RAIL_SHAPE =
|
||||
EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH);
|
||||
|
||||
public static IProperty<Boolean> CONNECTS_N = BooleanProperty.create("connects_n");
|
||||
public static IProperty<Boolean> CONNECTS_S = BooleanProperty.create("connects_s");
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public ReinforcedRailBlock(Properties properties) {
|
||||
super(true, properties);
|
||||
}
|
||||
public class ReinforcedRailBlock extends AbstractRailBlock {
|
||||
|
||||
@Override
|
||||
public IProperty<RailShape> getShapeProperty() {
|
||||
return RAIL_SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(RAIL_SHAPE, CONNECTS_N, CONNECTS_S);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
boolean alongX = context.getPlacementHorizontalFacing().getAxis() == Axis.X;
|
||||
return super.getStateForPlacement(context).with(RAIL_SHAPE, alongX ? RailShape.EAST_WEST : RailShape.NORTH_SOUTH).with(CONNECTS_N, false).with(CONNECTS_S, false);
|
||||
}
|
||||
public static IProperty<RailShape> RAIL_SHAPE =
|
||||
EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH);
|
||||
|
||||
@Override
|
||||
public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateState(BlockState state, World world, BlockPos pos, Block block) {
|
||||
super.updateState(state, world, pos, block);
|
||||
world.setBlockState(pos, getUpdatedState(world, pos, state, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState getUpdatedState(World world, BlockPos pos, BlockState state,
|
||||
boolean p_208489_4_) {
|
||||
|
||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||
BlockPos sPos = pos.add(alongX ? -1 : 0, 0, alongX ? 0 : 1);
|
||||
BlockPos nPos = pos.add(alongX ? 1 : 0, 0, alongX ? 0 : -1);
|
||||
|
||||
return super.getUpdatedState(world, pos, state, p_208489_4_).with(CONNECTS_S, world.getBlockState(sPos).getBlock() instanceof ReinforcedRailBlock &&
|
||||
(world.getBlockState(sPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)))
|
||||
.with(CONNECTS_N, world.getBlockState(nPos).getBlock() instanceof ReinforcedRailBlock &&
|
||||
(world.getBlockState(nPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
||||
ISelectionContext context) { //FIXME
|
||||
if (context.getEntity() instanceof AbstractMinecartEntity)
|
||||
return VoxelShapes.empty();
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos pos2, boolean p_220069_6_) {
|
||||
if (!world.isRemote) {
|
||||
this.updateState(state, world, pos, block);
|
||||
}
|
||||
}
|
||||
public static IProperty<Boolean> CONNECTS_N = BooleanProperty.create("connects_n");
|
||||
public static IProperty<Boolean> CONNECTS_S = BooleanProperty.create("connects_s");
|
||||
|
||||
public ReinforcedRailBlock(Properties properties) {
|
||||
super(true, properties);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IProperty<RailShape> getShapeProperty() {
|
||||
return RAIL_SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(RAIL_SHAPE, CONNECTS_N, CONNECTS_S);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
boolean alongX = context.getPlacementHorizontalFacing().getAxis() == Axis.X;
|
||||
return super.getStateForPlacement(context).with(RAIL_SHAPE, alongX ? RailShape.EAST_WEST : RailShape.NORTH_SOUTH).with(CONNECTS_N, false).with(CONNECTS_S, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMakeSlopes(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateState(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Block block) {
|
||||
super.updateState(state, world, pos, block);
|
||||
world.setBlockState(pos, getUpdatedState(world, pos, state, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
protected BlockState getUpdatedState(@Nonnull World world, BlockPos pos, BlockState state,
|
||||
boolean p_208489_4_) {
|
||||
|
||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||
BlockPos sPos = pos.add(alongX ? -1 : 0, 0, alongX ? 0 : 1);
|
||||
BlockPos nPos = pos.add(alongX ? 1 : 0, 0, alongX ? 0 : -1);
|
||||
|
||||
return super.getUpdatedState(world, pos, state, p_208489_4_).with(CONNECTS_S, world.getBlockState(sPos).getBlock() instanceof ReinforcedRailBlock &&
|
||||
(world.getBlockState(sPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)))
|
||||
.with(CONNECTS_N, world.getBlockState(nPos).getBlock() instanceof ReinforcedRailBlock &&
|
||||
(world.getBlockState(nPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public VoxelShape getCollisionShape(@Nonnull BlockState state, @Nonnull IBlockReader worldIn, @Nonnull BlockPos pos,
|
||||
ISelectionContext context) { //FIXME
|
||||
if (context.getEntity() instanceof AbstractMinecartEntity)
|
||||
return VoxelShapes.empty();
|
||||
return getShape(state, worldIn, pos, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public VoxelShape getShape(BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos, ISelectionContext context) {
|
||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||
return VoxelShapes.or(super.getShape(state, reader, pos, context), VoxelShapes.or(makeCuboidShape(0, 0, 0, alongX ? 16 : 1, 12, alongX ? 1 : 16), makeCuboidShape(alongX ? 0 : 15, 0, alongX ? 15 : 0, 16, 12, 16)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
|
||||
return !(world.getBlockState(pos.down()).getBlock() instanceof AbstractRailBlock || world.getBlockState(pos.up()).getBlock() instanceof AbstractRailBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(@Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull Block block, @Nonnull BlockPos pos2, boolean p_220069_6_) {
|
||||
if (!world.isRemote) {
|
||||
if ((world.getBlockState(pos.down()).getBlock() instanceof AbstractRailBlock)) {
|
||||
if (!p_220069_6_) {
|
||||
spawnDrops(state, world, pos);
|
||||
}
|
||||
world.removeBlock(pos, false);
|
||||
} else {
|
||||
this.updateState(state, world, pos, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue