mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 13:43:43 +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.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ReinforcedRailBlock extends AbstractRailBlock{
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
public ReinforcedRailBlock(Properties properties) {
|
public class ReinforcedRailBlock extends AbstractRailBlock {
|
||||||
super(true, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public static IProperty<RailShape> RAIL_SHAPE =
|
||||||
public IProperty<RailShape> getShapeProperty() {
|
EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH);
|
||||||
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 static IProperty<Boolean> CONNECTS_N = BooleanProperty.create("connects_n");
|
||||||
public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) {
|
public static IProperty<Boolean> CONNECTS_S = BooleanProperty.create("connects_s");
|
||||||
return false;
|
|
||||||
}
|
public ReinforcedRailBlock(Properties properties) {
|
||||||
|
super(true, properties);
|
||||||
@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));
|
@Nonnull
|
||||||
}
|
@Override
|
||||||
|
public IProperty<RailShape> getShapeProperty() {
|
||||||
@Override
|
return RAIL_SHAPE;
|
||||||
protected BlockState getUpdatedState(World world, BlockPos pos, BlockState state,
|
}
|
||||||
boolean p_208489_4_) {
|
|
||||||
|
@Override
|
||||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||||
BlockPos sPos = pos.add(alongX ? -1 : 0, 0, alongX ? 0 : 1);
|
builder.add(RAIL_SHAPE, CONNECTS_N, CONNECTS_S);
|
||||||
BlockPos nPos = pos.add(alongX ? 1 : 0, 0, alongX ? 0 : -1);
|
super.fillStateContainer(builder);
|
||||||
|
}
|
||||||
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)))
|
@Override
|
||||||
.with(CONNECTS_N, world.getBlockState(nPos).getBlock() instanceof ReinforcedRailBlock &&
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||||
(world.getBlockState(nPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)));
|
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 VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
@Override
|
||||||
ISelectionContext context) { //FIXME
|
public boolean canMakeSlopes(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
|
||||||
if (context.getEntity() instanceof AbstractMinecartEntity)
|
return false;
|
||||||
return VoxelShapes.empty();
|
}
|
||||||
return VoxelShapes.fullCube();
|
|
||||||
}
|
@Override
|
||||||
|
protected void updateState(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Block block) {
|
||||||
@Override
|
super.updateState(state, world, pos, block);
|
||||||
public PushReaction getPushReaction(BlockState state) {
|
world.setBlockState(pos, getUpdatedState(world, pos, state, true));
|
||||||
return PushReaction.BLOCK;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
@Nonnull
|
||||||
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
protected BlockState getUpdatedState(@Nonnull World world, BlockPos pos, BlockState state,
|
||||||
return false;
|
boolean p_208489_4_) {
|
||||||
}
|
|
||||||
|
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||||
@Override
|
BlockPos sPos = pos.add(alongX ? -1 : 0, 0, alongX ? 0 : 1);
|
||||||
public boolean isValidPosition(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) {
|
BlockPos nPos = pos.add(alongX ? 1 : 0, 0, alongX ? 0 : -1);
|
||||||
return true;
|
|
||||||
}
|
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)))
|
||||||
@Override
|
.with(CONNECTS_N, world.getBlockState(nPos).getBlock() instanceof ReinforcedRailBlock &&
|
||||||
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos pos2, boolean p_220069_6_) {
|
(world.getBlockState(nPos).get(RAIL_SHAPE) == state.get(RAIL_SHAPE)));
|
||||||
if (!world.isRemote) {
|
}
|
||||||
this.updateState(state, world, pos, block);
|
|
||||||
}
|
@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