Skip to content

Instantly share code, notes, and snippets.

@SaadArdati
Created April 10, 2016 12:09
Show Gist options
  • Save SaadArdati/75c97a1fdd02946bf6eee3e996d68373 to your computer and use it in GitHub Desktop.
Save SaadArdati/75c97a1fdd02946bf6eee3e996d68373 to your computer and use it in GitHub Desktop.
Correct side referenced up/down/left/right hit checks. It supports every axis. It's used to split a block's side/plane into 4 quadrants (rectangular). hitting the center does nothing but you can 'else' every if statement for that.
if (side != EnumFacing.UP && side != EnumFacing.DOWN) {
boolean top = hitY >= 0.7f, bottom = hitY <= 0.3;
boolean left = (side.getAxis() == EnumFacing.Axis.Z ? hitX : hitZ) >= 0.7f;
boolean right = (side.getAxis() == EnumFacing.Axis.Z ? hitX : hitZ) <= 0.3f;
if (side == EnumFacing.NORTH || side == EnumFacing.SOUTH) {
if (side == EnumFacing.SOUTH) {
if (top) mirror.setPitch(mirror.getPitch() - 1);
else if (bottom) mirror.setPitch(mirror.getPitch() + 1);
} else {
if (top) mirror.setPitch(mirror.getPitch() + 1);
else if (bottom) mirror.setPitch(mirror.getPitch() - 1);
}
if (left) mirror.setYaw(mirror.getYaw() - 1);
else if (right) mirror.setYaw(mirror.getYaw() + 1);
} else {
if (side == EnumFacing.EAST) {
if (top) mirror.setYaw(mirror.getYaw() + 1);
else if (bottom) mirror.setYaw(mirror.getYaw() - 1);
} else {
if (top) mirror.setYaw(mirror.getYaw() - 1);
else if (bottom) mirror.setYaw(mirror.getYaw() + 1);
}
if (left) mirror.setPitch(mirror.getPitch() + 1);
else if (right) mirror.setPitch(mirror.getPitch() - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment