Skip to content

Commit

Permalink
Fixed controller box not working under the track. Fix #93
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Aug 21, 2023
1 parent 8ebfd0c commit 24fed68
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/api/java/mods/railcraft/api/carts/RollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.stream.StreamSupport;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import mods.railcraft.api.track.TrackUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
Expand Down Expand Up @@ -204,6 +205,7 @@ default Stream<RollingStock> traverseTrainWithSelf(Side side) {
return Stream.concat(Stream.of(this), this.traverseTrain(side));
}

@Nullable
Train train();

default boolean isSameTrainAs(@NotNull RollingStock minecart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public class LauncherTrackBlockEntity extends RailcraftBlockEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

public abstract class SignalBoxBlock extends CrossCollisionBlock {

private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 15, 14);

public static final BooleanProperty CAP = BooleanProperty.create("cap");
private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 15, 14);

public SignalBoxBlock(Properties properties) {
super(2.0F, 2.0F, 16.0F, 16.0F, 24.0F, properties);
Expand All @@ -39,6 +38,19 @@ public SignalBoxBlock(Properties properties) {
.setValue(WATERLOGGED, false));
}

public static boolean isConnected(BlockState state, Direction face) {
BooleanProperty property = PROPERTY_BY_DIRECTION.get(face);
return property != null && state.getValue(property);
}

public static boolean isAspectEmitter(BlockState blockState) {
return blockState.is(RailcraftTags.Blocks.ASPECT_EMITTER);
}

public static boolean isAspectReceiver(BlockState blockState) {
return blockState.is(RailcraftTags.Blocks.ASPECT_RECEIVER);
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, WEST, SOUTH, CAP, WATERLOGGED);
Expand All @@ -49,11 +61,6 @@ public VoxelShape getBlockSupportShape(BlockState state, BlockGetter reader, Blo
return Shapes.block();
}

public static boolean isConnected(BlockState state, Direction face) {
BooleanProperty property = PROPERTY_BY_DIRECTION.get(face);
return property != null && state.getValue(property);
}

@Override
public void neighborChanged(BlockState state, Level level, BlockPos pos,
Block neighborBlock, BlockPos neighborPos, boolean isMoving) {
Expand Down Expand Up @@ -91,6 +98,12 @@ public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos,
return SHAPE;
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos,
CollisionContext context) {
return SHAPE;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockGetter level = context.getLevel();
Expand All @@ -109,7 +122,7 @@ public BlockState updateShape(BlockState blockState, Direction direction,
}
return direction.getAxis().isHorizontal()
? blockState.setValue(PROPERTY_BY_DIRECTION.get(direction),
attachesTo(blockState, otherState))
attachesTo(blockState, otherState))
: direction == Direction.UP
? blockState.setValue(CAP, !otherState.isAir())
: blockState;
Expand All @@ -119,11 +132,8 @@ public boolean attachesTo(BlockState blockState, BlockState otherBlockState) {
if (!isAspectEmitter(blockState) && !isAspectReceiver(blockState)) {
return false;
}
if (isAspectReceiver(blockState) && isAspectEmitter(otherBlockState)
|| isAspectEmitter(blockState) && isAspectReceiver(otherBlockState)) {
return true;
}
return false;
return isAspectReceiver(blockState) && isAspectEmitter(otherBlockState)
|| isAspectEmitter(blockState) && isAspectReceiver(otherBlockState);
}

@SuppressWarnings("deprecation")
Expand All @@ -135,12 +145,4 @@ public float getDestroyProgress(BlockState state, Player player, BlockGetter blo
.map(__ -> 0.0F)
.orElseGet(() -> super.getDestroyProgress(state, player, blockGetter, pos));
}

public static boolean isAspectEmitter(BlockState blockState) {
return blockState.is(RailcraftTags.Blocks.ASPECT_EMITTER);
}

public static boolean isAspectReceiver(BlockState blockState) {
return blockState.is(RailcraftTags.Blocks.ASPECT_RECEIVER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
&& TrackSupportTools.isSupported(level, pos, this.getTrackType().getMaxSupportDistance());
}

@Override
public boolean isConduitFrame(BlockState state, LevelReader level, BlockPos pos,
BlockPos conduit) {
return false;
}

@Override
public VoxelShape getShape(BlockState blockState, BlockGetter level, BlockPos blockPos,
CollisionContext context) {
Expand Down

0 comments on commit 24fed68

Please sign in to comment.