Clamp yaw properly for smoothrotationtrait

This commit is contained in:
fullwall 2022-08-09 23:07:48 +08:00
parent 4bb3ee8845
commit 0645934c1e
2 changed files with 12 additions and 3 deletions

View File

@ -187,12 +187,12 @@ public class SmoothRotationTrait extends Trait {
public float rotateHeadYawTowards(int t, float yaw, float targetYaw) {
float out = rotateTowards(yaw, targetYaw, maxYawPerTick);
return clamp(out, yawRange[0], yawRange[1]);
return Util.clamp(out, yawRange[0], yawRange[1], 360);
}
public float rotatePitchTowards(int t, float pitch, float targetPitch) {
float out = rotateTowards(pitch, targetPitch, maxPitchPerTick);
return clamp(out, pitchRange[0], pitchRange[1]);
return Util.clamp(out, pitchRange[0], pitchRange[1], 360);
}
/*

View File

@ -78,6 +78,16 @@ public class Util {
return angle;
}
public static float clamp(float angle, float min, float max, float d) {
while (angle < min) {
angle += d;
}
while (angle >= max) {
angle -= d;
}
return angle;
}
public static ItemStack createItem(Material mat, String name) {
return createItem(mat, name, null);
}
@ -357,7 +367,6 @@ public class Util {
}
private static final Location AT_LOCATION = new Location(null, 0, 0, 0);
private static final Scoreboard DUMMY_SCOREBOARD = Bukkit.getScoreboardManager().getNewScoreboard();
private static String MINECRAFT_REVISION;
private static Boolean REQUIRES_CHANNEL_METADATA;