package openonyx.events; import net.minecraft.entity.Entity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import openonyx.core.MinecraftAccess; public class GeometryUtils implements MinecraftAccess { private static final double e = 0.05; public static double L(Entity entity) { return mc.thePlayer == null ? Double.MAX_VALUE : L(entity.getEntityBoundingBox(), L()); } public static Vec3 L(float f, float g) { float j = MathHelper.cos(-f * (float) (Math.PI / 180.0) - (float) Math.PI); float i = MathHelper.sin(-f * (float) (Math.PI / 180.0) - (float) Math.PI); float h = -MathHelper.cos(-g * (float) (Math.PI / 180.0)); g = MathHelper.sin(-g * (float) (Math.PI / 180.0)); return new Vec3(i * h, g, j * h); } public static Vec3 L() { return new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ); } private static double L(double d, double e, double f) { return ex + d * (f - ex); } public static Vec3 L(Vec3 vec3, AxisAlignedBB axisAlignedBB) { return new Vec3( MathHelper.clamp_double(vec3.xCoord, axisAlignedBB.minX, axisAlignedBB.maxX), MathHelper.clamp_double(vec3.yCoord, axisAlignedBB.minY, axisAlignedBB.maxY), MathHelper.clamp_double(vec3.zCoord, axisAlignedBB.minZ, axisAlignedBB.maxZ) ); } public static Vec3 L(Entity entity, double d, double e, double f, double g) { Entity entity1 = entity; Vec3 vec3 = L(); AxisAlignedBB axisAlignedBB; double h = Math.min( (axisAlignedBB = entity1.getEntityBoundingBox()).maxX - axisAlignedBB.minX, Math.min(axisAlignedBB.maxY - axisAlignedBB.minY, axisAlignedBB.maxZ - axisAlignedBB.minZ) ); AxisAlignedBB axisAlignedBB1; double i; Vec3 vec31 = (axisAlignedBB1 = axisAlignedBB.expand(-(i = Math.min(0.05, h * 0.25)), -i, -i)).isVecInside(vec3) ? L(axisAlignedBB1) : L(vec3, axisAlignedBB1); if (g <= 0.0) { return vec31; } vec3 = new Vec3( L(d, axisAlignedBB1.minX, axisAlignedBB1.maxX), L(ex, axisAlignedBB1.minY, axisAlignedBB1.maxY), L(f, axisAlignedBB1.minZ, axisAlignedBB1.maxZ) ); return L(vec31, vec3, g); } private static Vec3 L(Vec3 vec3, Vec3 vec31, double d) { return new Vec3(L(d, vec3.xCoord, vec31.xCoord), L(d, vec3.yCoord, vec31.yCoord), L(d, vec3.zCoord, vec31.zCoord)); } public static Vec3 L(Entity entity) { return L(entity, 0.0, 0.0, 0.0, 0.0); } public static Vec3 L(AxisAlignedBB axisAlignedBB) { return new Vec3( (axisAlignedBB.minX + axisAlignedBB.maxX) * 0.5, (axisAlignedBB.minY + axisAlignedBB.maxY) * 0.5, (axisAlignedBB.minZ + axisAlignedBB.maxZ) * 0.5 ); } public static double L(AxisAlignedBB axisAlignedBB, Vec3 vec3) { double d = Math.max(Math.max(axisAlignedBB.minX - vec3.xCoord, 0.0), vec3.xCoord - axisAlignedBB.maxX); double ex = Math.max(Math.max(axisAlignedBB.minY - vec3.yCoord, 0.0), vec3.yCoord - axisAlignedBB.maxY); double f = Math.max(Math.max(axisAlignedBB.minZ - vec3.zCoord, 0.0), vec3.zCoord - axisAlignedBB.maxZ); return d * d + ex * ex + f * f; } }