Skip to content

Commit

Permalink
Deduplicate trapdoor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloeDawn committed Dec 8, 2021
1 parent 8361afc commit 8c6c394
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main/java/dev/sapphic/couplings/impl/TrapdoorBlockCoupling.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@ private static void tryOpenCloseEach(final BlockState state, final Level level,
}

if (continuePos) {
relative = relative.offset(traverseZ ? offset : 0, 0, traverseZ ? 0 : offset);

if ((player == null) || level.mayInteract(player, relative)) {
tryOpenClose(state, relative, level, player, facing.getOpposite(), half, open);
}
tryOpenCloseAt(state, level, player, open, half, facing, traverseZ, offset, relative);
}
}

if (continueNeg && (step != 0)) {
BlockPos relative = pos.offset(traverseZ ? 0 : -step, 0, traverseZ ? -step : 0);
final BlockPos relative = pos.offset(traverseZ ? 0 : -step, 0, traverseZ ? -step : 0);

continueNeg = ((player == null) || level.mayInteract(player, relative))
&& tryOpenClose(state, relative, level, player, facing, half, open);

if (continueNeg) {
relative = relative.offset(traverseZ ? offset : 0, 0, traverseZ ? 0 : offset);

if ((player == null) || level.mayInteract(player, relative)) {
tryOpenClose(state, relative, level, player, facing.getOpposite(), half, open);
}
tryOpenCloseAt(state, level, player, open, half, facing, traverseZ, offset, relative);
}
}
}
}

private static void tryOpenCloseAt(final BlockState state, final Level level, final @Nullable Player player, final boolean open, final Half half, final Direction facing, final boolean traverseZ, final int offset, final BlockPos pos) {
final BlockPos relative = pos.offset(traverseZ ? offset : 0, 0, traverseZ ? 0 : offset);

if ((player == null) || level.mayInteract(player, relative)) {
tryOpenClose(state, relative, level, player, facing.getOpposite(), half, open);
}
}

private static boolean tryOpenClose(final BlockState state, final BlockPos pos, final Level level, final @Nullable Player player, final Direction facing, final Half half, final boolean open) {
final BlockState other = level.getBlockState(pos);

Expand Down

0 comments on commit 8c6c394

Please sign in to comment.