Reinforced the face boundary checks

Now throws an exception when the function encounters an impossible situation.
This commit is contained in:
Daniel E 2019-11-19 16:17:28 -07:00
parent 59b16c2877
commit c8fdd8f472

View File

@ -30,6 +30,7 @@ import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.BiFunction;
/** /**
* @author Daniel E * @author Daniel E
@ -148,10 +149,17 @@ public final class ObsidianReplaceModule extends Module {
private EnumFacing calculateFaceForPlacement(final BlockPos structurePosition, private EnumFacing calculateFaceForPlacement(final BlockPos structurePosition,
final BlockPos blockPosition) { final BlockPos blockPosition) {
final int diffX = structurePosition.getX() - blockPosition.getX(); final BiFunction<Integer, String, Integer> throwingClampCheck = (number, axis) -> {
if (diffX < -1 || diffX > 1) if (number < -1 || number > 1)
return null; throw new IllegalStateException(
String.format("Difference in %s illegal usage with " +
"calculateFaceForPlacement.", axis));
return number;
};
final int diffX = throwingClampCheck.apply(
structurePosition.getX() - blockPosition.getX(), "diffX");
switch (diffX) { switch (diffX) {
case 1: case 1:
return EnumFacing.WEST; return EnumFacing.WEST;
@ -161,10 +169,8 @@ public final class ObsidianReplaceModule extends Module {
break; break;
} }
final int diffY = structurePosition.getY() - blockPosition.getY(); final int diffY = throwingClampCheck.apply(
if (diffY < -1 || diffY > 1) structurePosition.getY() - blockPosition.getY(), "diffY");
return null;
switch (diffY) { switch (diffY) {
case 1: case 1:
return EnumFacing.DOWN; return EnumFacing.DOWN;
@ -174,10 +180,8 @@ public final class ObsidianReplaceModule extends Module {
break; break;
} }
final int diffZ = structurePosition.getZ() - blockPosition.getZ(); final int diffZ = throwingClampCheck.apply(
if (diffZ < -1 || diffZ > 1) structurePosition.getZ() - blockPosition.getZ(), "diffZ");
return null;
switch (diffZ) { switch (diffZ) {
case 1: case 1:
return EnumFacing.NORTH; return EnumFacing.NORTH;