mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-04 03:16: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,6 +20,8 @@ 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;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ReinforcedRailBlock extends AbstractRailBlock {
|
public class ReinforcedRailBlock extends AbstractRailBlock {
|
||||||
|
|
||||||
public static IProperty<RailShape> RAIL_SHAPE =
|
public static IProperty<RailShape> RAIL_SHAPE =
|
||||||
|
@ -32,6 +34,8 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||||
super(true, properties);
|
super(true, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IProperty<RailShape> getShapeProperty() {
|
public IProperty<RailShape> getShapeProperty() {
|
||||||
return RAIL_SHAPE;
|
return RAIL_SHAPE;
|
||||||
|
@ -50,18 +54,19 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) {
|
public boolean canMakeSlopes(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
super.updateState(state, world, pos, block);
|
||||||
world.setBlockState(pos, getUpdatedState(world, pos, state, true));
|
world.setBlockState(pos, getUpdatedState(world, pos, state, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 p_208489_4_) {
|
||||||
|
|
||||||
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
boolean alongX = state.get(RAIL_SHAPE) == RailShape.EAST_WEST;
|
||||||
|
@ -75,14 +80,23 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
ISelectionContext context) { //FIXME
|
||||||
if (context.getEntity() instanceof AbstractMinecartEntity)
|
if (context.getEntity() instanceof AbstractMinecartEntity)
|
||||||
return VoxelShapes.empty();
|
return VoxelShapes.empty();
|
||||||
return VoxelShapes.fullCube();
|
return getShape(state, worldIn, pos, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
public PushReaction getPushReaction(BlockState state) {
|
||||||
return PushReaction.BLOCK;
|
return PushReaction.BLOCK;
|
||||||
}
|
}
|
||||||
|
@ -93,14 +107,21 @@ public class ReinforcedRailBlock extends AbstractRailBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidPosition(BlockState p_196260_1_, IWorldReader p_196260_2_, BlockPos p_196260_3_) {
|
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
|
||||||
return true;
|
return !(world.getBlockState(pos.down()).getBlock() instanceof AbstractRailBlock || world.getBlockState(pos.up()).getBlock() instanceof AbstractRailBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.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);
|
this.updateState(state, world, pos, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue