Simplify LookBehaviorUtils's reachableCenter method

This commit is contained in:
Brady 2018-08-09 18:24:46 -05:00
parent ef3c9999c8
commit 4ea4e5fa43
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 7 additions and 11 deletions

View File

@ -70,7 +70,7 @@ public final class LookBehaviorUtils implements Helper {
double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x); double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableRotation(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff)); possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
if (possibleRotation.isPresent()) if (possibleRotation.isPresent())
return possibleRotation; return possibleRotation;
} }
@ -96,7 +96,7 @@ public final class LookBehaviorUtils implements Helper {
* @param offsetPos * @param offsetPos
* @return * @return
*/ */
protected static Optional<Rotation> reachableRotation(BlockPos pos, Vec3d offsetPos) { protected static Optional<Rotation> reachableOffset(BlockPos pos, Vec3d offsetPos) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offsetPos); Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offsetPos);
RayTraceResult result = rayTraceTowards(rotation); RayTraceResult result = rayTraceTowards(rotation);
if (result != null if (result != null
@ -113,13 +113,7 @@ public final class LookBehaviorUtils implements Helper {
* @return * @return
*/ */
protected static Optional<Rotation> reachableCenter(BlockPos pos) { protected static Optional<Rotation> reachableCenter(BlockPos pos) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), Utils.calcCenterFromCoords(pos, mc.world)); return reachableOffset(pos, Utils.calcCenterFromCoords(pos, mc.world));
RayTraceResult result = rayTraceTowards(rotation);
if (result != null
&& result.typeOfHit == RayTraceResult.Type.BLOCK
&& result.getBlockPos().equals(pos))
return Optional.of(rotation);
return Optional.empty();
} }
/** /**

View File

@ -79,9 +79,11 @@ public final class Utils {
double xDiff = (bbox.minX + bbox.maxX) / 2; double xDiff = (bbox.minX + bbox.maxX) / 2;
double yDiff = (bbox.minY + bbox.maxY) / 2; double yDiff = (bbox.minY + bbox.maxY) / 2;
double zDiff = (bbox.minZ + bbox.maxZ) / 2; double zDiff = (bbox.minZ + bbox.maxZ) / 2;
return new Vec3d(orig.getX() + xDiff, return new Vec3d(
orig.getX() + xDiff,
orig.getY() + yDiff, orig.getY() + yDiff,
orig.getZ() + zDiff); orig.getZ() + zDiff
);
} }
public static Vec3d getBlockPosCenter(BlockPos pos) { public static Vec3d getBlockPosCenter(BlockPos pos) {