diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java index dc697169..ea10c7ec 100644 --- a/src/api/java/baritone/api/utils/Rotation.java +++ b/src/api/java/baritone/api/utils/Rotation.java @@ -86,7 +86,7 @@ public class Rotation { public Rotation clamp() { return new Rotation( this.yaw, - RotationUtils.clampPitch(this.pitch) + clampPitch(this.pitch) ); } @@ -95,7 +95,7 @@ public class Rotation { */ public Rotation normalize() { return new Rotation( - RotationUtils.normalizeYaw(this.yaw), + normalizeYaw(this.yaw), this.pitch ); } @@ -105,8 +105,35 @@ public class Rotation { */ public Rotation normalizeAndClamp() { return new Rotation( - RotationUtils.normalizeYaw(this.yaw), - RotationUtils.clampPitch(this.pitch) + normalizeYaw(this.yaw), + clampPitch(this.pitch) ); } + + /** + * Clamps the specified pitch value between -90 and 90. + * + * @param pitch The input pitch + * @return The clamped pitch + */ + public static float clampPitch(float pitch) { + return Math.max(-90, Math.min(90, pitch)); + } + + /** + * Normalizes the specified yaw value between -180 and 180. + * + * @param yaw The input yaw + * @return The normalized yaw + */ + public static float normalizeYaw(float yaw) { + float newYaw = yaw % 360F; + if (newYaw < -180F) { + newYaw += 360F; + } + if (newYaw >= 180F) { + newYaw -= 360F; + } + return newYaw; + } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 6d9f5487..1089d83e 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -21,9 +21,7 @@ import baritone.Baritone; import baritone.api.pathing.movement.IMovement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.*; -import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; -import baritone.utils.InputOverrideHandler; +import baritone.utils.*; import net.minecraft.block.BlockLiquid; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7f2f4e0d..f9268d4f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -19,12 +19,11 @@ package baritone.pathing.movement; import baritone.Baritone; import baritone.api.pathing.movement.ActionCosts; -import baritone.api.utils.*; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Rotation; +import baritone.api.utils.VecUtils; import baritone.pathing.movement.MovementState.MovementTarget; -import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; -import baritone.utils.InputOverrideHandler; -import baritone.utils.ToolSet; +import baritone.utils.*; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; @@ -393,7 +392,7 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IBlockState b, ToolSet ts) { - mc.player.inventory.currentItem = ts.getBestSlot(b.getBlock()); + Helper.HELPER.player().inventory.currentItem = ts.getBestSlot(b.getBlock()); } static boolean throwaway(boolean select) { @@ -433,10 +432,11 @@ public interface MovementHelper extends ActionCosts, Helper { } static void moveTowards(MovementState state, BlockPos pos) { + EntityPlayerSP player = Helper.HELPER.player(); state.setTarget(new MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F), VecUtils.getBlockPosCenter(pos), - new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getYaw(), mc.player.rotationPitch), + new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), false )).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index cd0744e4..aa1d7a5b 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.api.utils.RayTraceUtils; -import baritone.api.utils.RotationUtils; +import baritone.utils.RayTraceUtils; +import baritone.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 8f9feb41..63930ee8 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -19,13 +19,17 @@ package baritone.pathing.movement.movements; import baritone.Baritone; import baritone.api.pathing.movement.MovementStatus; -import baritone.api.utils.*; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Rotation; +import baritone.api.utils.VecUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; 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.utils.pathing.MutableMoveResult; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; @@ -67,7 +71,7 @@ public class MovementFall extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } - if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) { + if (player().posY - dest.getY() < playerController().getBlockReachDistance()) { player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER); targetRotation = new Rotation(player().rotationYaw, 90.0F); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 68bddae0..fed636a5 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -20,9 +20,9 @@ package baritone.pathing.movement.movements; import baritone.Baritone; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.RayTraceUtils; +import baritone.utils.RayTraceUtils; import baritone.api.utils.Rotation; -import baritone.api.utils.RotationUtils; +import baritone.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/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index b19556fd..795884b0 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -20,7 +20,6 @@ package baritone.pathing.movement.movements; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.Rotation; -import baritone.api.utils.RotationUtils; import baritone.api.utils.VecUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -28,6 +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 net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -157,11 +157,11 @@ public class MovementPillar extends Movement { } boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; boolean vine = fromDown.getBlock() instanceof BlockVine; - Rotation rotation = RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + Rotation rotation = RotationUtils.calcRotationFromVec3d(player().getPositionEyes(1.0F), VecUtils.getBlockPosCenter(positionToPlace), - new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)); + new Rotation(player().rotationYaw, player().rotationPitch)); if (!ladder) { - state.setTarget(new MovementState.MovementTarget(new Rotation(mc.player.rotationYaw, rotation.getPitch()), true)); + state.setTarget(new MovementState.MovementTarget(new Rotation(player().rotationYaw, rotation.getPitch()), true)); } boolean blockIsThere = MovementHelper.canWalkOn(src) || ladder; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 93dfcf44..db31bb00 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -26,6 +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 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 0c39f2fb..1f4a120e 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -22,7 +22,7 @@ import baritone.api.pathing.goals.*; import baritone.api.process.IMineProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; -import baritone.api.utils.RotationUtils; +import baritone.utils.RotationUtils; import baritone.cache.CachedChunk; import baritone.cache.ChunkPacker; import baritone.cache.WorldProvider; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 2fbf05f7..70f6c1b9 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -23,7 +23,6 @@ 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; diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index a80e5660..27aa2bc1 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -23,6 +23,7 @@ import baritone.api.utils.Rotation; import net.minecraft.block.BlockSlab; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; @@ -57,6 +58,13 @@ public interface Helper { return mc.player; } + default PlayerControllerMP playerController() { // idk + if (!mc.isCallingFromMinecraftThread()) { + throw new IllegalStateException("h00000000"); + } + return mc.playerController; + } + default WorldClient world() { return mc.world; } diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/main/java/baritone/utils/RayTraceUtils.java similarity index 85% rename from src/api/java/baritone/api/utils/RayTraceUtils.java rename to src/main/java/baritone/utils/RayTraceUtils.java index 1444c7e1..d4955bf9 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/main/java/baritone/utils/RayTraceUtils.java @@ -15,9 +15,10 @@ * along with Baritone. If not, see . */ -package baritone.api.utils; +package baritone.utils; -import net.minecraft.client.Minecraft; +import baritone.api.utils.Rotation; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -29,11 +30,7 @@ import java.util.Optional; * @author Brady * @since 8/25/2018 */ -public final class RayTraceUtils { - /** - * The {@link Minecraft} instance - */ - private static final Minecraft mc = Minecraft.getMinecraft(); +public final class RayTraceUtils implements Helper { private RayTraceUtils() {} @@ -50,19 +47,20 @@ public final class RayTraceUtils { * @return The calculated raytrace result */ public static RayTraceResult simulateRayTrace(float yaw, float pitch) { + EntityPlayerSP player = Helper.HELPER.player(); RayTraceResult oldTrace = mc.objectMouseOver; - float oldYaw = mc.player.rotationYaw; - float oldPitch = mc.player.rotationPitch; + float oldYaw = player.rotationYaw; + float oldPitch = player.rotationPitch; - mc.player.rotationYaw = yaw; - mc.player.rotationPitch = pitch; + player.rotationYaw = yaw; + player.rotationPitch = pitch; mc.entityRenderer.getMouseOver(1.0F); RayTraceResult result = mc.objectMouseOver; mc.objectMouseOver = oldTrace; - mc.player.rotationYaw = oldYaw; - mc.player.rotationPitch = oldPitch; + player.rotationYaw = oldYaw; + player.rotationPitch = oldPitch; return result; } @@ -76,8 +74,8 @@ public final class RayTraceUtils { * @return The calculated raytrace result */ public static RayTraceResult rayTraceTowards(Rotation rotation) { - double blockReachDistance = mc.playerController.getBlockReachDistance(); - Vec3d start = mc.player.getPositionEyes(1.0F); + double blockReachDistance = Helper.HELPER.playerController().getBlockReachDistance(); + Vec3d start = Helper.HELPER.player().getPositionEyes(1.0F); Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation); Vec3d end = start.add( direction.x * blockReachDistance, diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/main/java/baritone/utils/RotationUtils.java similarity index 90% rename from src/api/java/baritone/api/utils/RotationUtils.java rename to src/main/java/baritone/utils/RotationUtils.java index a8449dc7..b9dc0589 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/main/java/baritone/utils/RotationUtils.java @@ -15,11 +15,12 @@ * along with Baritone. If not, see . */ -package baritone.api.utils; +package baritone.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.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.util.math.*; @@ -29,12 +30,7 @@ import java.util.Optional; * @author Brady * @since 9/25/2018 */ -public final class RotationUtils { - - /** - * The {@link Minecraft} instance - */ - private static final Minecraft mc = Minecraft.getMinecraft(); +public final class RotationUtils implements Helper { /** * Constant that a degree value is multiplied by to get the equivalent radian value @@ -60,33 +56,6 @@ public final class RotationUtils { private RotationUtils() {} - /** - * Clamps the specified pitch value between -90 and 90. - * - * @param pitch The input pitch - * @return The clamped pitch - */ - public static float clampPitch(float pitch) { - return Math.max(-90, Math.min(90, pitch)); - } - - /** - * Normalizes the specified yaw value between -180 and 180. - * - * @param yaw The input yaw - * @return The normalized yaw - */ - public static float normalizeYaw(float yaw) { - float newYaw = yaw % 360F; - if (newYaw < -180F) { - newYaw += 360F; - } - if (newYaw >= 180F) { - newYaw -= 360F; - } - return newYaw; - } - /** * Calculates the rotation from BlockPosdest to BlockPosorig *