Move a lot of utils to api
This commit is contained in:
parent
83fc11e75b
commit
c80b855dab
@ -15,22 +15,29 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
package baritone.api.utils;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import static baritone.behavior.LookBehaviorUtils.calcVec3dFromRotation;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 8/25/2018
|
||||
*/
|
||||
public final class RayTraceUtils implements Helper {
|
||||
public final class RayTraceUtils {
|
||||
|
||||
private RayTraceUtils() {}
|
||||
|
||||
/**
|
||||
* The {@link Minecraft} instance
|
||||
*/
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -72,7 +79,7 @@ public final class RayTraceUtils implements Helper {
|
||||
public static RayTraceResult rayTraceTowards(Rotation rotation) {
|
||||
double blockReachDistance = mc.playerController.getBlockReachDistance();
|
||||
Vec3d start = mc.player.getPositionEyes(1.0F);
|
||||
Vec3d direction = calcVec3dFromRotation(rotation);
|
||||
Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation);
|
||||
Vec3d end = start.add(
|
||||
direction.x * blockReachDistance,
|
||||
direction.y * blockReachDistance,
|
||||
@ -80,4 +87,28 @@ public final class RayTraceUtils implements Helper {
|
||||
);
|
||||
return mc.world.rayTraceBlocks(start, end, false, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block that the crosshair is currently placed over. Updated once per render tick.
|
||||
*
|
||||
* @return The position of the highlighted block
|
||||
*/
|
||||
public static Optional<BlockPos> getSelectedBlock() {
|
||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
return Optional.of(mc.objectMouseOver.getBlockPos());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity that the crosshair is currently placed over. Updated once per render tick.
|
||||
*
|
||||
* @return The entity
|
||||
*/
|
||||
public static Optional<Entity> getSelectedEntity() {
|
||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||
return Optional.of(mc.objectMouseOver.entityHit);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@ -17,6 +17,14 @@
|
||||
|
||||
package baritone.api.utils;
|
||||
|
||||
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.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/25/2018
|
||||
@ -25,6 +33,33 @@ public final class RotationUtils {
|
||||
|
||||
private RotationUtils() {}
|
||||
|
||||
/**
|
||||
* The {@link Minecraft} instance
|
||||
*/
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
/**
|
||||
* Constant that a degree value is multiplied by to get the equivalent radian value
|
||||
*/
|
||||
public static final double DEG_TO_RAD = Math.PI / 180.0;
|
||||
|
||||
/**
|
||||
* Constant that a radian value is multiplied by to get the equivalent degree value
|
||||
*/
|
||||
public static final double RAD_TO_DEG = 180.0 / Math.PI;
|
||||
|
||||
/**
|
||||
* Offsets from the root block position to the center of each side.
|
||||
*/
|
||||
private static final Vec3d[] BLOCK_SIDE_MULTIPLIERS = new Vec3d[]{
|
||||
new Vec3d(0.5, 0, 0.5), // Down
|
||||
new Vec3d(0.5, 1, 0.5), // Up
|
||||
new Vec3d(0.5, 0.5, 0), // North
|
||||
new Vec3d(0.5, 0.5, 1), // South
|
||||
new Vec3d(0, 0.5, 0.5), // West
|
||||
new Vec3d(1, 0.5, 0.5) // East
|
||||
};
|
||||
|
||||
/**
|
||||
* Clamps the specified pitch value between -90 and 90.
|
||||
*
|
||||
@ -51,4 +86,157 @@ public final class RotationUtils {
|
||||
}
|
||||
return newYaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation from BlockPos<sub>dest</sub> to BlockPos<sub>orig</sub>
|
||||
*
|
||||
* @param orig The origin position
|
||||
* @param dest The destination position
|
||||
* @return The rotation from the origin to the destination
|
||||
*/
|
||||
public static Rotation calcRotationFromCoords(BlockPos orig, BlockPos dest) {
|
||||
return calcRotationFromVec3d(new Vec3d(orig), new Vec3d(dest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the target angles to a relative value from the current angles. This is done by
|
||||
* subtracting the current from the target, normalizing it, and then adding the current
|
||||
* angles back to it.
|
||||
*
|
||||
* @param current The current angles
|
||||
* @param target The target angles
|
||||
* @return The wrapped angles
|
||||
*/
|
||||
public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) {
|
||||
return target.subtract(current).normalize().add(current);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation from Vec<sub>dest</sub> to Vec<sub>orig</sub> and makes the
|
||||
* return value relative to the specified current rotations.
|
||||
*
|
||||
* @see #wrapAnglesToRelative(Rotation, Rotation)
|
||||
*
|
||||
* @param orig The origin position
|
||||
* @param dest The destination position
|
||||
* @param current The current rotations
|
||||
* @return The rotation from the origin to the destination
|
||||
*/
|
||||
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest, Rotation current) {
|
||||
return wrapAnglesToRelative(current, calcRotationFromVec3d(orig, dest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation from Vec<sub>dest</sub> to Vec<sub>orig</sub>
|
||||
*
|
||||
* @param orig The origin position
|
||||
* @param dest The destination position
|
||||
* @return The rotation from the origin to the destination
|
||||
*/
|
||||
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) {
|
||||
double[] delta = { orig.x - dest.x, orig.y - dest.y, orig.z - dest.z };
|
||||
double yaw = MathHelper.atan2(delta[0], -delta[2]);
|
||||
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
|
||||
double pitch = MathHelper.atan2(delta[1], dist);
|
||||
return new Rotation(
|
||||
(float) (yaw * RAD_TO_DEG),
|
||||
(float) (pitch * RAD_TO_DEG)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the look vector for the specified yaw/pitch rotations.
|
||||
*
|
||||
* @param rotation The input rotation
|
||||
* @return Look vector for the rotation
|
||||
*/
|
||||
public static Vec3d calcVec3dFromRotation(Rotation rotation) {
|
||||
float f = MathHelper.cos(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
|
||||
float f1 = MathHelper.sin(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
|
||||
float f2 = -MathHelper.cos(-rotation.getPitch() * (float) DEG_TO_RAD);
|
||||
float f3 = MathHelper.sin(-rotation.getPitch() * (float) DEG_TO_RAD);
|
||||
return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified entity is able to reach the center of any of the sides
|
||||
* of the specified block. It first checks if the block center is reachable, and if so,
|
||||
* that rotation will be returned. If not, it will return the first center of a given
|
||||
* side that is reachable. The return type will be {@link Optional#empty()} if the entity is
|
||||
* unable to reach any of the sides of the block.
|
||||
*
|
||||
* @param entity The viewing entity
|
||||
* @param pos The target block position
|
||||
* @return The optional rotation
|
||||
*/
|
||||
public static Optional<Rotation> reachable(Entity entity, BlockPos pos) {
|
||||
if (pos.equals(RayTraceUtils.getSelectedBlock().orElse(null))) {
|
||||
/*
|
||||
* why add 0.0001?
|
||||
* to indicate that we actually have a desired pitch
|
||||
* the way we indicate that the pitch can be whatever and we only care about the yaw
|
||||
* is by setting the desired pitch to the current pitch
|
||||
* setting the desired pitch to the current pitch + 0.0001 means that we do have a desired pitch, it's
|
||||
* just what it currently is
|
||||
*/
|
||||
return Optional.of(new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F));
|
||||
}
|
||||
Optional<Rotation> possibleRotation = reachableCenter(entity, pos);
|
||||
//System.out.println("center: " + possibleRotation);
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
|
||||
IBlockState state = mc.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));
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified entity is able to reach the specified block with
|
||||
* the given offsetted position. The return type will be {@link Optional#empty()} if
|
||||
* the entity is unable to reach the block with the offset applied.
|
||||
*
|
||||
* @param entity The viewing entity
|
||||
* @param pos The target block position
|
||||
* @param offsetPos The position of the block with the offset applied.
|
||||
* @return The optional rotation
|
||||
*/
|
||||
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos) {
|
||||
Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos);
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(rotation);
|
||||
System.out.println(result);
|
||||
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
if (result.getBlockPos().equals(pos)) {
|
||||
return Optional.of(rotation);
|
||||
}
|
||||
if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire) {
|
||||
if (result.getBlockPos().equals(pos.down())) {
|
||||
return Optional.of(rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified entity is able to reach the specified block where it is
|
||||
* looking at the direct center of it's hitbox.
|
||||
*
|
||||
* @param entity The viewing entity
|
||||
* @param pos The target block position
|
||||
* @return The optional rotation
|
||||
*/
|
||||
public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos) {
|
||||
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(pos));
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SettingsUtil {
|
||||
|
||||
private static final File settingsFile = new File(new File(Minecraft.getMinecraft().gameDir, "baritone"), "settings.txt");
|
||||
|
||||
private static final Map<Class<?>, SettingsIO> map;
|
||||
|
126
src/api/java/baritone/api/utils/VecUtils.java
Normal file
126
src/api/java/baritone/api/utils/VecUtils.java
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.utils;
|
||||
|
||||
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.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 10/13/2018
|
||||
*/
|
||||
public final class VecUtils {
|
||||
|
||||
private VecUtils() {}
|
||||
|
||||
/**
|
||||
* The {@link Minecraft} instance
|
||||
*/
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
/**
|
||||
* Calculates the center of the block at the specified position's bounding box
|
||||
*
|
||||
* @see #getBlockPosCenter(BlockPos)
|
||||
*
|
||||
* @param pos The block position
|
||||
* @return The center of the block's bounding box
|
||||
*/
|
||||
public static Vec3d calculateBlockCenter(BlockPos pos) {
|
||||
IBlockState b = mc.world.getBlockState(pos);
|
||||
AxisAlignedBB bbox = b.getBoundingBox(mc.world, pos);
|
||||
double xDiff = (bbox.minX + bbox.maxX) / 2;
|
||||
double yDiff = (bbox.minY + bbox.maxY) / 2;
|
||||
double zDiff = (bbox.minZ + bbox.maxZ) / 2;
|
||||
if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out
|
||||
yDiff = 0;
|
||||
}
|
||||
return new Vec3d(
|
||||
pos.getX() + xDiff,
|
||||
pos.getY() + yDiff,
|
||||
pos.getZ() + zDiff
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the assumed center position of the given block position.
|
||||
* This is done by adding 0.5 to the X, Y, and Z axes.
|
||||
* <p>
|
||||
* TODO: We may want to consider replacing many usages of this method with #calculateBlockCenter(BlockPos)
|
||||
*
|
||||
* @see #calculateBlockCenter(BlockPos)
|
||||
*
|
||||
* @param pos The block position
|
||||
* @return The assumed center of the position
|
||||
*/
|
||||
public static Vec3d getBlockPosCenter(BlockPos pos) {
|
||||
return new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance from the specified position to the assumed center of the specified block position.
|
||||
*
|
||||
* @see #getBlockPosCenter(BlockPos)
|
||||
*
|
||||
* @param pos The block position
|
||||
* @param x The x pos
|
||||
* @param y The y pos
|
||||
* @param z The z pos
|
||||
* @return The distance from the assumed block center to the position
|
||||
*/
|
||||
public static double distanceToCenter(BlockPos pos, double x, double y, double z) {
|
||||
Vec3d center = getBlockPosCenter(pos);
|
||||
double xdiff = x - center.x;
|
||||
double ydiff = y - center.y;
|
||||
double zdiff = z - center.z;
|
||||
return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance from the specified entity's position to the assumed
|
||||
* center of the specified block position.
|
||||
*
|
||||
* @see #getBlockPosCenter(BlockPos)
|
||||
*
|
||||
* @param entity The entity
|
||||
* @param pos The block position
|
||||
* @return The distance from the entity to the block's assumed center
|
||||
*/
|
||||
public static double entityDistanceToCenter(Entity entity, BlockPos pos) {
|
||||
return distanceToCenter(pos, entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance from the specified entity's position to the assumed
|
||||
* center of the specified block position, ignoring the Y axis.
|
||||
*
|
||||
* @see #getBlockPosCenter(BlockPos)
|
||||
*
|
||||
* @param entity The entity
|
||||
* @param pos The block position
|
||||
* @return The horizontal distance from the entity to the block's assumed center
|
||||
*/
|
||||
public static double entityFlatDistanceToCenter(Entity entity, BlockPos pos) {
|
||||
return distanceToCenter(pos, entity.posX, pos.getY() + 0.5, entity.posZ);
|
||||
}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.behavior;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.RayTraceUtils;
|
||||
import baritone.utils.Utils;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static baritone.utils.Utils.DEG_TO_RAD;
|
||||
|
||||
public final class LookBehaviorUtils implements Helper {
|
||||
|
||||
/**
|
||||
* Offsets from the root block position to the center of each side.
|
||||
*/
|
||||
private static final Vec3d[] BLOCK_SIDE_MULTIPLIERS = new Vec3d[]{
|
||||
new Vec3d(0.5, 0, 0.5), // Down
|
||||
new Vec3d(0.5, 1, 0.5), // Up
|
||||
new Vec3d(0.5, 0.5, 0), // North
|
||||
new Vec3d(0.5, 0.5, 1), // South
|
||||
new Vec3d(0, 0.5, 0.5), // West
|
||||
new Vec3d(1, 0.5, 0.5) // East
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates a vector given a rotation array
|
||||
*
|
||||
* @param rotation {@link LookBehavior#target}
|
||||
* @return vector of the rotation
|
||||
*/
|
||||
public static Vec3d calcVec3dFromRotation(Rotation rotation) {
|
||||
float f = MathHelper.cos(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
|
||||
float f1 = MathHelper.sin(-rotation.getYaw() * (float) DEG_TO_RAD - (float) Math.PI);
|
||||
float f2 = -MathHelper.cos(-rotation.getPitch() * (float) DEG_TO_RAD);
|
||||
float f3 = MathHelper.sin(-rotation.getPitch() * (float) DEG_TO_RAD);
|
||||
return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2));
|
||||
}
|
||||
|
||||
public static Optional<Rotation> reachable(BlockPos pos) {
|
||||
if (pos.equals(getSelectedBlock().orElse(null))) {
|
||||
/*
|
||||
* why add 0.0001?
|
||||
* to indicate that we actually have a desired pitch
|
||||
* the way we indicate that the pitch can be whatever and we only care about the yaw
|
||||
* is by setting the desired pitch to the current pitch
|
||||
* setting the desired pitch to the current pitch + 0.0001 means that we do have a desired pitch, it's
|
||||
* just what it currently is
|
||||
*/
|
||||
return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f));
|
||||
}
|
||||
Optional<Rotation> possibleRotation = reachableCenter(pos);
|
||||
//System.out.println("center: " + possibleRotation);
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(pos);
|
||||
AxisAlignedBB aabb = state.getBoundingBox(mc.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(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
|
||||
if (possibleRotation.isPresent()) {
|
||||
return possibleRotation;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if coordinate is reachable with the given block-face rotation offset
|
||||
*
|
||||
* @param pos
|
||||
* @param offsetPos
|
||||
* @return
|
||||
*/
|
||||
protected static Optional<Rotation> reachableOffset(BlockPos pos, Vec3d offsetPos) {
|
||||
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offsetPos);
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(rotation);
|
||||
System.out.println(result);
|
||||
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
if (result.getBlockPos().equals(pos)) {
|
||||
return Optional.of(rotation);
|
||||
}
|
||||
if (BlockStateInterface.get(pos).getBlock() instanceof BlockFire) {
|
||||
if (result.getBlockPos().equals(pos.down())) {
|
||||
return Optional.of(rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if center of block at coordinate is reachable
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
protected static Optional<Rotation> reachableCenter(BlockPos pos) {
|
||||
return reachableOffset(pos, Utils.calcCenterFromCoords(pos, mc.world));
|
||||
}
|
||||
|
||||
/**
|
||||
* The currently highlighted block.
|
||||
* Updated once a tick by Minecraft.
|
||||
*
|
||||
* @return the position of the highlighted block
|
||||
*/
|
||||
public static Optional<BlockPos> getSelectedBlock() {
|
||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
return Optional.of(mc.objectMouseOver.getBlockPos());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@ -22,8 +22,9 @@ import baritone.api.pathing.movement.IMovement;
|
||||
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.behavior.LookBehavior;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
import baritone.utils.*;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@ -171,7 +172,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<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(player(), blockPos);
|
||||
if (reachable.isPresent()) {
|
||||
MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos));
|
||||
state.setTarget(new MovementState.MovementTarget(reachable.get(), true)).setInput(Input.CLICK_LEFT, true);
|
||||
@ -181,8 +182,8 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
||||
//i'm doing it anyway
|
||||
//i dont care if theres snow in the way!!!!!!!
|
||||
//you dont own me!!!!
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
Utils.getBlockPosCenter(blockPos)), true)
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(player().getPositionEyes(1.0F),
|
||||
VecUtils.getBlockPosCenter(blockPos)), true)
|
||||
).setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
|
||||
return false;
|
||||
}
|
||||
|
@ -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.behavior.LookBehaviorUtils;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.*;
|
||||
import net.minecraft.block.*;
|
||||
@ -29,14 +27,12 @@ import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemPickaxe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
|
||||
import java.util.Optional;
|
||||
@ -374,23 +370,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return isBottomSlab(BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity the player is currently looking at
|
||||
*
|
||||
* @return the entity object
|
||||
*/
|
||||
static Optional<Entity> whatEntityAmILookingAt() {
|
||||
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||
return Optional.of(mc.objectMouseOver.entityHit);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoTool
|
||||
*/
|
||||
static void switchToBestTool() {
|
||||
LookBehaviorUtils.getSelectedBlock().ifPresent(pos -> {
|
||||
RayTraceUtils.getSelectedBlock().ifPresent(pos -> {
|
||||
IBlockState state = BlockStateInterface.get(pos);
|
||||
if (state.getBlock().equals(Blocks.AIR)) {
|
||||
return;
|
||||
@ -456,8 +440,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static void moveTowards(MovementState state, BlockPos pos) {
|
||||
state.setTarget(new MovementTarget(
|
||||
new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
Utils.getBlockPosCenter(pos),
|
||||
new Rotation(RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
VecUtils.getBlockPosCenter(pos),
|
||||
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getYaw(), mc.player.rotationPitch),
|
||||
false
|
||||
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
|
@ -84,9 +84,6 @@ public class MovementState {
|
||||
|
||||
/**
|
||||
* Yaw and pitch angles that must be matched
|
||||
* <p>
|
||||
* getFirst() -> YAW
|
||||
* getSecond() -> PITCH
|
||||
*/
|
||||
public Rotation rotation;
|
||||
|
||||
|
@ -20,14 +20,14 @@ package baritone.pathing.movement.movements;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
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;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -181,10 +181,10 @@ public class MovementAscend extends Movement {
|
||||
double faceX = (dest.getX() + anAgainst.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
|
||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||
|
||||
LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
RayTraceUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
||||
ticksWithoutPlacement++;
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||
|
@ -19,8 +19,7 @@ package baritone.pathing.movement.movements;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
@ -28,8 +27,6 @@ import baritone.pathing.movement.MovementState;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.RayTraceUtils;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.MutableMoveResult;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
@ -85,7 +82,7 @@ public class MovementFall extends Movement {
|
||||
if (targetRotation != null) {
|
||||
state.setTarget(new MovementTarget(targetRotation, true));
|
||||
} else {
|
||||
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
||||
state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.getBlockPosCenter(dest)), false));
|
||||
}
|
||||
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads
|
||||
if (BlockStateInterface.isWater(dest)) {
|
||||
@ -105,7 +102,7 @@ public class MovementFall extends Movement {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
}
|
||||
Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
|
||||
Vec3d destCenter = VecUtils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
|
||||
if (Math.abs(player().posX - destCenter.x) > 0.15 || Math.abs(player().posZ - destCenter.z) > 0.15) {
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
}
|
||||
|
@ -20,8 +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.api.utils.Rotation;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
@ -209,12 +210,12 @@ public class MovementParkour extends Movement {
|
||||
double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + against1.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
Rotation place = Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
|
||||
Rotation place = RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
|
||||
RayTraceResult res = RayTraceUtils.rayTraceTowards(place);
|
||||
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));
|
||||
}
|
||||
LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
RayTraceUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||
if (Objects.equals(selectedBlock, against1) && selectedBlock.offset(side).equals(dest.down())) {
|
||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
|
@ -20,13 +20,14 @@ 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;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -149,8 +150,8 @@ public class MovementPillar extends Movement {
|
||||
IBlockState fromDown = BlockStateInterface.get(src);
|
||||
if (BlockStateInterface.isWater(fromDown.getBlock()) && BlockStateInterface.isWater(dest)) {
|
||||
// stay centered while swimming up a water column
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
||||
Vec3d destCenter = Utils.getBlockPosCenter(dest);
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.getBlockPosCenter(dest)), false));
|
||||
Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
|
||||
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
}
|
||||
@ -162,8 +163,8 @@ public class MovementPillar extends Movement {
|
||||
boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine;
|
||||
boolean vine = fromDown.getBlock() instanceof BlockVine;
|
||||
if (!ladder) {
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
Utils.getBlockPosCenter(positionToPlace),
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||
VecUtils.getBlockPosCenter(positionToPlace),
|
||||
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)), true));
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,13 @@ package baritone.pathing.movement.movements;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
import baritone.api.utils.*;
|
||||
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.InputOverrideHandler;
|
||||
import baritone.utils.Utils;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -169,7 +166,7 @@ public class MovementTraverse extends Movement {
|
||||
|
||||
// combine the yaw to the center of the destination, and the pitch to the specific block we're trying to break
|
||||
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
|
||||
float yawToDest = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(dest, world())).getYaw();
|
||||
float yawToDest = RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.calculateBlockCenter(dest)).getYaw();
|
||||
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
|
||||
|
||||
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
|
||||
@ -194,7 +191,7 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
if (isDoorActuallyBlockingUs) {
|
||||
if (!(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
|
||||
return state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[0], world())), true))
|
||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.calculateBlockCenter(positionsToBreak[0])), true))
|
||||
.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
}
|
||||
}
|
||||
@ -209,7 +206,7 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
|
||||
if (blocked != null) {
|
||||
return state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(blocked, world())), true))
|
||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.calculateBlockCenter(blocked)), true))
|
||||
.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
}
|
||||
}
|
||||
@ -267,16 +264,16 @@ public class MovementTraverse extends Movement {
|
||||
double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + against1.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
|
||||
|
||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get())) {
|
||||
if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
||||
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get())) {
|
||||
if (RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
||||
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
}
|
||||
// wrong side?
|
||||
}
|
||||
System.out.println("Trying to look at " + against1 + ", actually looking at" + LookBehaviorUtils.getSelectedBlock());
|
||||
System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
|
||||
return state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
|
||||
}
|
||||
}
|
||||
@ -296,18 +293,18 @@ public class MovementTraverse extends Movement {
|
||||
// faceX, faceY, faceZ is the middle of the face between from and to
|
||||
BlockPos goalLook = src.down(); // this is the block we were just standing on, and the one we want to place against
|
||||
|
||||
Rotation backToFace = Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
|
||||
Rotation backToFace = RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
|
||||
float pitch = backToFace.getPitch();
|
||||
double dist = Math.max(Math.abs(player().posX - faceX), Math.abs(player().posZ - faceZ));
|
||||
if (dist < 0.29) {
|
||||
float yaw = Utils.calcRotationFromVec3d(Utils.getBlockPosCenter(dest), playerHead(), playerRotations()).getYaw();
|
||||
float yaw = RotationUtils.calcRotationFromVec3d(VecUtils.getBlockPosCenter(dest), playerHead(), playerRotations()).getYaw();
|
||||
state.setTarget(new MovementState.MovementTarget(new Rotation(yaw, pitch), true));
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||
} else {
|
||||
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
||||
}
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), goalLook)) {
|
||||
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), goalLook)) {
|
||||
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||
}
|
||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
|
@ -25,6 +25,7 @@ import baritone.api.pathing.movement.IMovement;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.pathing.path.IPathExecutor;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.VecUtils;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
@ -279,7 +280,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
double best = -1;
|
||||
BlockPos bestPos = null;
|
||||
for (BlockPos pos : path.positions()) {
|
||||
double dist = Utils.playerDistanceToCenter(pos);
|
||||
double dist = VecUtils.entityDistanceToCenter(player(), pos);
|
||||
if (dist < best || best == -1) {
|
||||
best = dist;
|
||||
bestPos = pos;
|
||||
@ -327,7 +328,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
// when we're midair in the middle of a fall, we're very far from both the beginning and the end, but we aren't actually off path
|
||||
if (path.movements().get(pathPosition) instanceof MovementFall) {
|
||||
BlockPos fallDest = path.positions().get(pathPosition + 1); // .get(pathPosition) is the block we fell off of
|
||||
if (Utils.playerFlatDistanceToCenter(fallDest) < leniency) { // ignore Y by using flat distance
|
||||
if (VecUtils.entityFlatDistanceToCenter(player(), fallDest) < leniency) { // ignore Y by using flat distance
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -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.FollowBehavior;
|
||||
@ -255,7 +256,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
String name = msg.substring(6).trim();
|
||||
Optional<Entity> toFollow = Optional.empty();
|
||||
if (name.length() == 0) {
|
||||
toFollow = MovementHelper.whatEntityAmILookingAt();
|
||||
toFollow = RayTraceUtils.getSelectedEntity();
|
||||
} else {
|
||||
for (EntityPlayer pl : world().playerEntities) {
|
||||
String theirName = pl.getName().trim().toLowerCase();
|
||||
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import static baritone.utils.Helper.HELPER;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 8/1/2018 12:56 AM
|
||||
*/
|
||||
public final class Utils {
|
||||
|
||||
/**
|
||||
* Constant that a degree value is multiplied by to get the equivalent radian value
|
||||
*/
|
||||
public static final double DEG_TO_RAD = Math.PI / 180.0;
|
||||
|
||||
/**
|
||||
* Constant that a radian value is multiplied by to get the equivalent degree value
|
||||
*/
|
||||
public static final double RAD_TO_DEG = 180.0 / Math.PI;
|
||||
|
||||
public static Rotation calcRotationFromCoords(BlockPos orig, BlockPos dest) {
|
||||
return calcRotationFromVec3d(vec3dFromBlockPos(orig), vec3dFromBlockPos(dest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates rotation to given Vec<sub>dest</sub> from Vec<sub>orig</sub>
|
||||
*
|
||||
* @param orig
|
||||
* @param dest
|
||||
* @return Rotation {@link Rotation}
|
||||
*/
|
||||
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) {
|
||||
double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
|
||||
double yaw = MathHelper.atan2(delta[0], -delta[2]);
|
||||
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
|
||||
double pitch = MathHelper.atan2(delta[1], dist);
|
||||
return new Rotation(
|
||||
(float) radToDeg(yaw),
|
||||
(float) radToDeg(pitch)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates rotation to given Vec<sub>dest</sub> from Vec<sub>orig</sub>
|
||||
*
|
||||
* @param orig
|
||||
* @param dest
|
||||
* @return Rotation {@link Rotation}
|
||||
*/
|
||||
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest, Rotation current) {
|
||||
return wrapAnglesToRelative(current, calcRotationFromVec3d(orig, dest));
|
||||
}
|
||||
|
||||
public static Vec3d calcCenterFromCoords(BlockPos orig, World world) {
|
||||
IBlockState b = BlockStateInterface.get(orig);
|
||||
AxisAlignedBB bbox = b.getBoundingBox(world, orig);
|
||||
double xDiff = (bbox.minX + bbox.maxX) / 2;
|
||||
double yDiff = (bbox.minY + bbox.maxY) / 2;
|
||||
double zDiff = (bbox.minZ + bbox.maxZ) / 2;
|
||||
if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out
|
||||
yDiff = 0;
|
||||
}
|
||||
return new Vec3d(
|
||||
orig.getX() + xDiff,
|
||||
orig.getY() + yDiff,
|
||||
orig.getZ() + zDiff
|
||||
);
|
||||
}
|
||||
|
||||
public static Vec3d getBlockPosCenter(BlockPos pos) {
|
||||
return new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
}
|
||||
|
||||
public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) {
|
||||
return target.subtract(current).normalize().add(current);
|
||||
}
|
||||
|
||||
public static Vec3d vec3dFromBlockPos(BlockPos orig) {
|
||||
return new Vec3d(orig.getX() + 0.0D, orig.getY() + 0.0D, orig.getZ() + 0.0D);
|
||||
}
|
||||
|
||||
public static double distanceToCenter(BlockPos pos, double x, double y, double z) {
|
||||
double xdiff = x - (pos.getX() + 0.5D);
|
||||
double ydiff = y - (pos.getY() + 0.5D);
|
||||
double zdiff = z - (pos.getZ() + 0.5D);
|
||||
return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
|
||||
}
|
||||
|
||||
public static double playerDistanceToCenter(BlockPos pos) {
|
||||
EntityPlayerSP player = HELPER.player();
|
||||
return distanceToCenter(pos, player.posX, player.posY, player.posZ);
|
||||
}
|
||||
|
||||
public static double playerFlatDistanceToCenter(BlockPos pos) {
|
||||
EntityPlayerSP player = HELPER.player();
|
||||
return distanceToCenter(pos, player.posX, pos.getY() + 0.5, player.posZ);
|
||||
}
|
||||
|
||||
public static double degToRad(double deg) {
|
||||
return deg * DEG_TO_RAD;
|
||||
}
|
||||
|
||||
public static double radToDeg(double rad) {
|
||||
return rad * RAD_TO_DEG;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user