mirror of https://github.com/cabaletta/baritone
Add rotation method to respect relative angles
This commit is contained in:
parent
207947f7dd
commit
5b3eb5a375
|
@ -178,6 +178,6 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||
}
|
||||
|
||||
protected void moveTowards(BlockPos pos) {
|
||||
currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world())).getFirst(), player().rotationPitch))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ 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))));
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations())));
|
||||
|
||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against1) && Minecraft.getMinecraft().player.isSneaking()) {
|
||||
|
@ -158,7 +158,7 @@ public class MovementTraverse extends Movement {
|
|||
double faceZ = (dest.getZ() + src.getZ() + 1.0D) * 0.5D;
|
||||
//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
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ))));
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations())));
|
||||
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||
|
|
|
@ -24,11 +24,15 @@ public interface Helper {
|
|||
}
|
||||
|
||||
default BlockPos playerFeet() {
|
||||
return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
|
||||
return new BlockPos(player().posX, player().posY, player().posZ);
|
||||
}
|
||||
|
||||
default Vec3d playerHead() {
|
||||
return new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ);
|
||||
return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ);
|
||||
}
|
||||
|
||||
default Rotation playerRotations() {
|
||||
return new Rotation(player().rotationYaw, player().rotationPitch);
|
||||
}
|
||||
|
||||
default void displayChatMessageRaw(String message) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package baritone.bot.utils;
|
|||
import net.minecraft.util.Tuple;
|
||||
|
||||
public class Rotation extends Tuple<Float, Float> {
|
||||
|
||||
public Rotation(Float yaw, Float pitch) {
|
||||
super(yaw, pitch);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package baritone.bot.utils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
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;
|
||||
|
||||
|
@ -32,6 +32,17 @@ public final class Utils {
|
|||
(float) (pitch * 180 / Math.PI));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -43,6 +54,13 @@ public final class Utils {
|
|||
orig.getZ() + zDiff);
|
||||
}
|
||||
|
||||
public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) {
|
||||
return new Rotation(
|
||||
MathHelper.wrapDegrees(target.getFirst() - current.getFirst()) + current.getFirst(),
|
||||
MathHelper.wrapDegrees(target.getSecond() - current.getSecond()) + current.getSecond()
|
||||
);
|
||||
}
|
||||
|
||||
public static Vec3d vec3dFromBlockPos(BlockPos orig) {
|
||||
return new Vec3d(orig.getX() + 0.0D, orig.getY() + 0.0D, orig.getZ() + 0.0D);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue