Created
April 10, 2016 12:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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