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,7 +20,9 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ReinforcedRailBlock extends AbstractRailBlock {
|
||||
|
||||
public static IProperty<RailShape> RAIL_SHAPE =
|
||||
EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH);
|
||||
|
@ -32,6 +34,8 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
|||
super(true, properties);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IProperty<RailShape> getShapeProperty() {
|
||||
return RAIL_SHAPE;
|
||||
|
@ -50,18 +54,19 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) {
|
||||
public boolean canMakeSlopes(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateState(BlockState state, World world, BlockPos pos, Block block) {
|
||||
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
|
||||
protected BlockState getUpdatedState(World world, BlockPos pos, BlockState state,
|
||||
@Nonnull
|
||||
protected BlockState getUpdatedState(@Nonnull World world, BlockPos pos, BlockState state,
|
||||
boolean p_208489_4_) {
|
||||
|
||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||
|
@ -75,14 +80,23 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
|||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
||||
@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 VoxelShapes.fullCube();
|
||||
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;
|
||||
}
|
||||
|
@ -93,14 +107,21 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) {
|
||||
return true;
|
||||
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(BlockState state, World world, BlockPos pos, Block block, BlockPos pos2, boolean p_220069_6_) {
|
||||
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