Skip to content

Commit

Permalink
Fixed switch track rotation Fix #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Aug 30, 2023
1 parent a9f7177 commit e085dac
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,34 @@ public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
@Override
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldBlockState,
boolean moved) {
// this.updateAdjacentBlocks(state, level, pos);
this.updateAdjacentBlocks(state, level, pos);
}

protected void updateAdjacentBlocks(BlockState blockState, Level level, BlockPos pos) {
var railShape = TrackUtil.getRailShapeRaw(blockState);
if (railShape != RailShape.NORTH_SOUTH) {
return;
}

var offset = BaseRailBlock.isRail(level, pos.west()) ? pos.west() : pos.east();
if (!BaseRailBlock.isRail(level, offset)) {
return;
}
boolean reversed = blockState.getValue(REVERSED);

var otherShape = TrackUtil.getTrackDirection(level, offset);
if (otherShape == RailShape.NORTH_SOUTH) {
TrackUtil.setRailShape(level, offset, RailShape.EAST_WEST);
switch (railShape) {
case EAST_WEST -> {
var offset = reversed ? pos.north() : pos.south();
if (!BaseRailBlock.isRail(level, offset)) {
return;
}
var otherShape = TrackUtil.getTrackDirection(level, offset);
if (otherShape != RailShape.NORTH_SOUTH) {
TrackUtil.setRailShape(level, offset, RailShape.NORTH_SOUTH);
}
}
case NORTH_SOUTH -> {
var offset = reversed ? pos.west() : pos.east();
if (!BaseRailBlock.isRail(level, offset)) {
return;
}
var otherShape = TrackUtil.getTrackDirection(level, offset);
if (otherShape != RailShape.EAST_WEST) {
TrackUtil.setRailShape(level, offset, RailShape.EAST_WEST);
}
}
}
}

Expand Down

0 comments on commit e085dac

Please sign in to comment.