helper for 0.5 center

This commit is contained in:
Leijurv 2018-08-08 15:31:41 -07:00
parent b1462d5649
commit 38afa1b63c
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 7 additions and 4 deletions

View File

@ -35,7 +35,6 @@ 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.util.math.Vec3d;
import java.util.Arrays;
import java.util.List;
@ -204,7 +203,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static MovementState moveTowards(MovementState state, BlockPos pos) {
return state.setTarget(new MovementTarget(new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5),
Utils.getBlockPosCenter(pos),
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getFirst(), mc.player.rotationPitch))
).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}

View File

@ -89,7 +89,7 @@ public class MovementFall extends Movement {
}
return state.setStatus(MovementStatus.SUCCESS);
}
Vec3d destCenter = Utils.calcCenterFromCoords(dest, world());
Vec3d destCenter = Utils.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.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}

View File

@ -42,7 +42,7 @@ public final class Utils {
* @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[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
double yaw = Math.atan2(delta[0], -delta[2]);
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
double pitch = Math.atan2(delta[1], dist);
@ -74,6 +74,10 @@ public final class Utils {
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 new Rotation(
MathHelper.wrapDegrees(target.getFirst() - current.getFirst()) + current.getFirst(),