diff --git a/src/main/java/baritone/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java
similarity index 61%
rename from src/main/java/baritone/utils/RayTraceUtils.java
rename to src/api/java/baritone/api/utils/RayTraceUtils.java
index d4955bf9..8b37ef9d 100644
--- a/src/main/java/baritone/utils/RayTraceUtils.java
+++ b/src/api/java/baritone/api/utils/RayTraceUtils.java
@@ -15,10 +15,9 @@
* along with Baritone. If not, see .
*/
-package baritone.utils;
+package baritone.api.utils;
-import baritone.api.utils.Rotation;
-import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@@ -30,41 +29,12 @@ import java.util.Optional;
* @author Brady
* @since 8/25/2018
*/
-public final class RayTraceUtils implements Helper {
+public final class RayTraceUtils {
+
+ private static final Minecraft mc = Minecraft.getMinecraft();
private RayTraceUtils() {}
- /**
- * Simulates a "vanilla" raytrace. A RayTraceResult returned by this method
- * will be that of the next render pass given that the local player's yaw and
- * pitch match the specified yaw and pitch values. This is particularly useful
- * when you would like to simulate a "legit" raytrace with certainty that the only
- * thing to achieve the desired outcome (whether it is hitting and entity or placing
- * a block) can be done just by modifying user input.
- *
- * @param yaw The yaw to raytrace with
- * @param pitch The pitch to raytrace with
- * @return The calculated raytrace result
- */
- public static RayTraceResult simulateRayTrace(float yaw, float pitch) {
- EntityPlayerSP player = Helper.HELPER.player();
- RayTraceResult oldTrace = mc.objectMouseOver;
- float oldYaw = player.rotationYaw;
- float oldPitch = player.rotationPitch;
-
- player.rotationYaw = yaw;
- player.rotationPitch = pitch;
-
- mc.entityRenderer.getMouseOver(1.0F);
- RayTraceResult result = mc.objectMouseOver;
- mc.objectMouseOver = oldTrace;
-
- player.rotationYaw = oldYaw;
- player.rotationPitch = oldPitch;
-
- return result;
- }
-
/**
* Performs a block raytrace with the specified rotations. This should only be used when
* any entity collisions can be ignored, because this method will not recognize if an
@@ -73,9 +43,8 @@ public final class RayTraceUtils implements Helper {
* @param rotation The rotation to raytrace towards
* @return The calculated raytrace result
*/
- public static RayTraceResult rayTraceTowards(Rotation rotation) {
- double blockReachDistance = Helper.HELPER.playerController().getBlockReachDistance();
- Vec3d start = Helper.HELPER.player().getPositionEyes(1.0F);
+ public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) {
+ Vec3d start = entity.getPositionEyes(1.0F);
Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation);
Vec3d end = start.add(
direction.x * blockReachDistance,
diff --git a/src/main/java/baritone/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java
similarity index 94%
rename from src/main/java/baritone/utils/RotationUtils.java
rename to src/api/java/baritone/api/utils/RotationUtils.java
index b9dc0589..e1726812 100644
--- a/src/main/java/baritone/utils/RotationUtils.java
+++ b/src/api/java/baritone/api/utils/RotationUtils.java
@@ -15,10 +15,8 @@
* along with Baritone. If not, see .
*/
-package baritone.utils;
+package baritone.api.utils;
-import baritone.api.utils.Rotation;
-import baritone.api.utils.VecUtils;
import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
@@ -30,7 +28,7 @@ import java.util.Optional;
* @author Brady
* @since 9/25/2018
*/
-public final class RotationUtils implements Helper {
+public final class RotationUtils {
/**
* Constant that a degree value is multiplied by to get the equivalent radian value
@@ -137,7 +135,7 @@ public final class RotationUtils implements Helper {
* @param pos The target block position
* @return The optional rotation
*/
- public static Optional reachable(Entity entity, BlockPos pos) {
+ public static Optional reachable(Entity entity, BlockPos pos, double blockReachDistance) {
if (pos.equals(RayTraceUtils.getSelectedBlock().orElse(null))) {
/*
* why add 0.0001?
@@ -151,19 +149,19 @@ public final class RotationUtils implements Helper {
*/
return Optional.of(new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F));
}
- Optional possibleRotation = reachableCenter(entity, pos);
+ Optional possibleRotation = reachableCenter(entity, pos, blockReachDistance);
//System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
- IBlockState state = mc.world.getBlockState(pos);
+ IBlockState state = entity.world.getBlockState(pos);
AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos);
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
- possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
+ possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
@@ -181,9 +179,9 @@ public final class RotationUtils implements Helper {
* @param offsetPos The position of the block with the offset applied.
* @return The optional rotation
*/
- public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos) {
+ public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) {
Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos);
- RayTraceResult result = RayTraceUtils.rayTraceTowards(rotation);
+ RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance);
//System.out.println(result);
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
if (result.getBlockPos().equals(pos)) {
@@ -204,7 +202,7 @@ public final class RotationUtils implements Helper {
* @param pos The target block position
* @return The optional rotation
*/
- public static Optional reachableCenter(Entity entity, BlockPos pos) {
- return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(pos));
+ public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance) {
+ return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(pos), blockReachDistance);
}
}
diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java
index 1089d83e..f5c569c0 100644
--- a/src/main/java/baritone/pathing/movement/Movement.java
+++ b/src/main/java/baritone/pathing/movement/Movement.java
@@ -147,7 +147,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
for (BetterBlockPos blockPos : positionsToBreak) {
if (!MovementHelper.canWalkThrough(blockPos) && !(BlockStateInterface.getBlock(blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try
somethingInTheWay = true;
- Optional reachable = RotationUtils.reachable(player(), blockPos);
+ Optional reachable = RotationUtils.reachable(player(), blockPos, playerController().getBlockReachDistance());
if (reachable.isPresent()) {
MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos));
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java
index f9268d4f..b20cbf5f 100644
--- a/src/main/java/baritone/pathing/movement/MovementHelper.java
+++ b/src/main/java/baritone/pathing/movement/MovementHelper.java
@@ -19,9 +19,7 @@ package baritone.pathing.movement;
import baritone.Baritone;
import baritone.api.pathing.movement.ActionCosts;
-import baritone.api.utils.BetterBlockPos;
-import baritone.api.utils.Rotation;
-import baritone.api.utils.VecUtils;
+import baritone.api.utils.*;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.*;
import net.minecraft.block.*;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java
index aa1d7a5b..cd0744e4 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java
@@ -20,8 +20,8 @@ package baritone.pathing.movement.movements;
import baritone.Baritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
-import baritone.utils.RayTraceUtils;
-import baritone.utils.RotationUtils;
+import baritone.api.utils.RayTraceUtils;
+import baritone.api.utils.RotationUtils;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java
index 63930ee8..1467fe1b 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java
@@ -28,8 +28,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.InputOverrideHandler;
-import baritone.utils.RayTraceUtils;
-import baritone.utils.RotationUtils;
+import baritone.api.utils.RotationUtils;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
@@ -76,7 +75,7 @@ public class MovementFall extends Movement {
targetRotation = new Rotation(player().rotationYaw, 90.0F);
- RayTraceResult trace = RayTraceUtils.simulateRayTrace(player().rotationYaw, 90.0F);
+ RayTraceResult trace = mc.objectMouseOver;
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
index fed636a5..73aace38 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java
@@ -20,16 +20,14 @@ package baritone.pathing.movement.movements;
import baritone.Baritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
-import baritone.utils.RayTraceUtils;
+import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.Rotation;
-import baritone.utils.RotationUtils;
+import baritone.api.utils.RotationUtils;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
-import baritone.utils.BlockStateInterface;
-import baritone.utils.Helper;
-import baritone.utils.InputOverrideHandler;
+import baritone.utils.*;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -227,7 +225,7 @@ public class MovementParkour extends Movement {
double faceY = (dest.getY() + against1.getY()) * 0.5D;
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
Rotation place = RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
- RayTraceResult res = RayTraceUtils.rayTraceTowards(place);
+ RayTraceResult res = RayTraceUtils.rayTraceTowards(player(), place, playerController().getBlockReachDistance());
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) {
state.setTarget(new MovementState.MovementTarget(place, true));
}
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
index 795884b0..76006da5 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java
@@ -27,7 +27,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
-import baritone.utils.RotationUtils;
+import baritone.api.utils.RotationUtils;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
index db31bb00..0cf64a72 100644
--- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
+++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java
@@ -26,8 +26,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
-import baritone.utils.RayTraceUtils;
-import baritone.utils.RotationUtils;
+import baritone.api.utils.RayTraceUtils;
+import baritone.api.utils.RotationUtils;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java
index 1f4a120e..27da4496 100644
--- a/src/main/java/baritone/process/MineProcess.java
+++ b/src/main/java/baritone/process/MineProcess.java
@@ -22,7 +22,6 @@ import baritone.api.pathing.goals.*;
import baritone.api.process.IMineProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
-import baritone.utils.RotationUtils;
import baritone.cache.CachedChunk;
import baritone.cache.ChunkPacker;
import baritone.cache.WorldProvider;
@@ -31,6 +30,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
+import baritone.api.utils.RotationUtils;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@@ -248,7 +248,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) {
for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) {
BlockPos pos = new BlockPos(x, y, z);
- if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(player(), pos).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
+ if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(player(), pos, playerController().getBlockReachDistance()).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
knownOreLocations.add(pos);
}
}
diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java
index 70f6c1b9..2fbf05f7 100644
--- a/src/main/java/baritone/utils/ExampleBaritoneControl.java
+++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java
@@ -23,6 +23,7 @@ import baritone.api.cache.IWaypoint;
import baritone.api.event.events.ChatEvent;
import baritone.api.pathing.goals.*;
import baritone.api.pathing.movement.ActionCosts;
+import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.SettingsUtil;
import baritone.behavior.Behavior;
import baritone.behavior.PathingBehavior;