Skip to content

Commit

Permalink
fix cable
Browse files Browse the repository at this point in the history
  • Loading branch information
PTOM76 committed Sep 19, 2024
1 parent 444a98f commit f07f141
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/main/java/net/pitan76/itemalchemy/block/EMCCable.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public void onStateReplaced(StateReplacedEvent e) {
@Override
public void onPlaced(BlockPlacedEvent e) {
super.onPlaced(e);

BlockState north = WorldUtil.getBlockState(e.world, e.pos.north());
BlockState south = WorldUtil.getBlockState(e.world, e.pos.south());
BlockState east = WorldUtil.getBlockState(e.world, e.pos.east());
BlockState west = WorldUtil.getBlockState(e.world, e.pos.west());
BlockState up = WorldUtil.getBlockState(e.world, e.pos.up());
BlockState down = WorldUtil.getBlockState(e.world, e.pos.down());

if (north.getBlock() == this || south.getBlock() == this || east.getBlock() == this || west.getBlock() == this || up.getBlock() == this || down.getBlock() == this)
return;

WorldUtil.setBlockState(e.world, e.pos ,getStateForNeighborUpdate(new StateForNeighborUpdateArgs(e.state, null, null, e.world, e.pos, null)));
}

Expand Down Expand Up @@ -144,14 +155,26 @@ public BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args) {
state = state.with(FACING, Direction.UP);
}

// 交差
if (both_ns && both_ew || both_ns && both_ud || both_ew && both_ud) {
return state.with(CROSS, true);
return state.with(CROSS, true).with(T_CHAR, false).with(CONNER, false);
} else {
state = state.with(CROSS, false);
}

if (both_ns && east_only || both_ns && west_only || both_ew && north_only || both_ew && south_only || both_ud && east_only || both_ud && west_only) {
return state.with(T_CHAR, true);
// T字
if (both_ns && east_only) {
return state.with(T_CHAR, true).with(CROSS, false)
.with(CONNER, false).with(FACING, Direction.SOUTH);
} else if (both_ns && west_only) {
return state.with(T_CHAR, true).with(CROSS, false)
.with(CONNER, false).with(FACING, Direction.NORTH);
} else if (both_ew && north_only) {
return state.with(T_CHAR, true).with(CROSS, false)
.with(CONNER, false).with(FACING, Direction.EAST);
} else if (both_ew && south_only) {
return state.with(T_CHAR, true).with(CROSS, false)
.with(CONNER, false).with(FACING, Direction.WEST);
} else {
state = state.with(T_CHAR, false);
}
Expand Down

0 comments on commit f07f141

Please sign in to comment.