Fix SmoothRotationTrait rotating towards 0 on respawn

This commit is contained in:
fullwall 2022-06-26 23:28:38 +08:00
parent c6a1aba5bd
commit d7617637b7
7 changed files with 6 additions and 259 deletions

View File

@ -79,7 +79,7 @@ public class SmoothRotationTrait extends Trait {
@Override
public void run() {
if (!npc.isSpawned() || npc.getNavigator().isNavigating()) {
// npc.yHeadRot = Mth.rotateIfNecessary(npc.yHeadRot, npc.yBodyRot, 75);
// npc.yHeadRot = rotateIfNecessary(npc.yHeadRot, npc.yBodyRot, 75);
return;
}
if (!globalSession.hasTarget()) {
@ -103,7 +103,7 @@ public class SmoothRotationTrait extends Trait {
defaultPitch = pitch;
}
public static class EntityRotation {
private static class EntityRotation {
public float bodyYaw, headYaw, pitch;
public EntityRotation(Entity entity) {
@ -200,7 +200,7 @@ public class SmoothRotationTrait extends Trait {
public class SmoothRotationSession {
private final RotationParams params;
private int t;
private int t = -1;
private double tx, ty, tz;
public SmoothRotationSession(RotationParams params) {

View File

@ -353,24 +353,17 @@ public class Messages {
public static final String TEXT_EDITOR_BEGIN = "citizens.editors.text.begin";
public static final String TEXT_EDITOR_CLOSE_TALKER_SET = "citizens.editors.text.close-talker-set";
public static final String TEXT_EDITOR_DELAY_SET = "citizens.editors.text.delay-set";
public static final String TEXT_EDITOR_EDIT_BEGIN_PROMPT = "citizens.editors.text.edit-begin-prompt";
public static final String TEXT_EDITOR_EDIT_PROMPT = "citizens.editors.text.edit-prompt";
public static final String TEXT_EDITOR_EDITED_TEXT = "citizens.editors.text.edited-text";
public static final String TEXT_EDITOR_END = "citizens.editors.text.end";
public static final String TEXT_EDITOR_INVALID_DELAY = "citizens.editors.text.invalid-delay";
public static final String TEXT_EDITOR_INVALID_EDIT_TYPE = "citizens.editors.text.invalid-edit-type";
public static final String TEXT_EDITOR_INVALID_INDEX = "citizens.editors.text.invalid-index";
public static final String TEXT_EDITOR_INVALID_INPUT = "citizens.editors.text.invalid-input";
public static final String TEXT_EDITOR_INVALID_PAGE = "citizens.editors.text.invalid-page";
public static final String TEXT_EDITOR_INVALID_RANGE = "citizens.editors.text.invalid-range";
public static final String TEXT_EDITOR_LIST = "citizens.editors.text.text-list-header";
public static final String TEXT_EDITOR_MISSING_ITEM_PATTERN = "citizens.editors.text.missing-item-set-pattern";
public static final String TEXT_EDITOR_PAGE_PROMPT = "citizens.editors.text.change-page-prompt";
public static final String TEXT_EDITOR_RANDOM_TALKER_SET = "citizens.editors.text.random-talker-set";
public static final String TEXT_EDITOR_RANGE_SET = "citizens.editors.text.range-set";
public static final String TEXT_EDITOR_REALISTIC_LOOKING_SET = "citizens.editors.text.realistic-looking-set";
public static final String TEXT_EDITOR_REMOVE_PROMPT = "citizens.editors.text.remove-prompt";
public static final String TEXT_EDITOR_REMOVED_ENTRY = "citizens.editors.text.removed-entry";
public static final String TEXT_EDITOR_SET_ITEM = "citizens.editors.text.talk-item-set";
public static final String TEXT_EDITOR_SPEECH_BUBBLES_SET = "citizens.editors.text.speech-bubbles-set";
public static final String TEXT_EDITOR_START_PROMPT = "citizens.editors.text.start-prompt";

View File

@ -323,10 +323,7 @@ citizens.editors.text.add-prompt=Enter text to add to the NPC.
citizens.editors.text.added-entry=[[Added]] the entry [[{0}]].
citizens.editors.text.begin=<b>Entered the text editor! Type ''exit'' to leave the editor.
citizens.editors.text.change-page-prompt=Enter a page number to view more text entries.
citizens.editors.text.close-talker-set=[[Close talker]] set to [[{0}]].
citizens.editors.text.edit-begin-prompt=Enter the index of the entry you wish to edit or [[page]] to view more pages.
citizens.editors.text.edit-prompt=Enter text to edit the entry.
citizens.editors.text.edited-text=Changed entry at index [[{0}]] to [[{1}]].
citizens.editors.text.close-talker-set=[[Close talker]] set to [[{0}]].
citizens.editors.text.end=Exited the text editor.
citizens.editors.text.missing-item-set-pattern=Missing item in hand pattern.
citizens.editors.text.invalid-edit-type=Invalid edit type.
@ -340,8 +337,6 @@ citizens.editors.text.range-set=[[Range]] set to [[{0}]].
citizens.editors.text.delay-set=[[Delay]] set to [[{0}]] seconds.
citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]].
citizens.editors.text.speech-bubbles-set=[[Speech bubbles]] set to [[{0}]].
citizens.editors.text.remove-prompt=Enter the index of the entry you wish to remove or [[page]] to view more pages.
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
citizens.editors.text.start-prompt=<<[[add:command(add ):Add text>> | <<[[item:suggest(item ):Set the talk item in hand pattern (set to ''default'' to clear)>> | <<[[range:suggest(range ):Set the talking range in blocks>> | <<[[delay:suggest(delay ):Set the talking delay in seconds>><br><<{0}talk close:command(close):Toggle sending messages when players get close>> | <<{1}random:command(random):Toggle random talking>> | <<{2}speech bubbles:command(speech bubbles):Toggle showing text as holograms instead of messages>> | <<{3}realistic:command(realistic looking):Toggle requiring line of sight before speaking>>
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
citizens.editors.text.text-list-header=Current text:
@ -349,13 +344,13 @@ citizens.editors.waypoints.wander.editing-regions-stop=Exited the region editor.
citizens.editors.waypoints.wander.worldguard-region-not-found=WorldGuard region not found.
citizens.editors.waypoints.wander.worldguard-region-set=WorldGuard region set to [[{0}]].
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range. Type [[regions]] to enter the region editor.<br>Type [[delay <ticks>]] to delay the NPC between wanders. Type [[worldguardregion <regionId>]] to restrict movement to a specific WorldGuard region.
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br><<x range:suggest(xrange ):Set the x range in blocks>> | <<y range:suggest(yrange ):Set the y range in blocks>> | <<delay:suggest(delay ):Ticks to wait in between wanders>><br><<Enter the region editor:command(regions)>> | <<Restrict wandering to WorldGuard regions:suggest(worldguardregion )>>
citizens.editors.waypoints.wander.end=Exited the wander waypoint editor.
citizens.editors.waypoints.wander.delay-set=Delay between wanders set to [[{0}]] ticks.
citizens.editors.waypoints.wander.invalid-delay=Invalid delay specified.
citizens.editors.waypoints.wander.added-region=[[Added]] wanderable region at ({0}) ([[{1}]]).
citizens.editors.waypoints.wander.removed-region=[[Removed]] wanderable region at ({0}) ([[{1}]] remaining).
citizens.editors.waypoints.wander.editing-regions=Now editing regions!<br> [[Left click]] to add a new wanderable region using the xrange/yrange box centred at that block.<br> [[Right click]] an existing marker to remove that region.<br> Type [[regions]] to stop or simply exit the editor. Regions should be overlapping with each other.
citizens.editors.waypoints.wander.editing-regions=Now editing regions!<br> [[Left click]] to add a new wanderable region using the xrange/yrange box centred at that block.<br> [[Right click]] an existing marker to remove that region.<br> Type [[regions]] to stop or simply exit the editor. Regions should be overlap or touch each other.
citizens.editors.waypoints.guided.end=Exited the guided waypoint editor.
citizens.editors.waypoints.guided.begin=<b>Entered the guided waypoint editor! The NPC will randomly walk to a [[destination]] waypoint following the nearest [[guide]] point. For example, try putting guide points on a road and destinations inside houses!<br> [[Left click]] to add a guide waypoint and [[right click]] to remove an existing waypoint.<br> [[Sneak]] while left clicking to add a destination waypoint.<br> Type [[toggle path]] to toggle showing entities at waypoints.<br> Type [[clear]] to clear all waypoints.
citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint which the NPC will follow on the way to their destination.

View File

@ -1,61 +0,0 @@
package net.citizensnpcs.nms.v1_16_R3.util;
import net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC;
import net.minecraft.server.v1_16_R3.EntityInsentient;
import net.minecraft.server.v1_16_R3.MathHelper;
public class PlayerBodyControl {
private final EntityHumanNPC a;
private int b;
private float c;
public PlayerBodyControl(EntityHumanNPC var0) {
this.a = var0;
}
public void a() {
if (f()) {
this.a.aA = this.a.yaw;
c();
this.c = this.a.aC;
this.b = 0;
return;
}
if (e())
if (Math.abs(this.a.aC - this.c) > 15.0F) {
this.b = 0;
this.c = this.a.aC;
b();
} else {
this.b++;
if (this.b > 10)
d();
}
}
private void b() {
this.a.aA = MathHelper.b(this.a.aA, this.a.aC, 10);
this.a.yaw = this.a.aA;
}
private void c() {
this.a.aC = MathHelper.b(this.a.aC, this.a.aA, 10);
}
private void d() {
int var0 = this.b - 10;
float var1 = MathHelper.a(var0 / 10.0F, 0.0F, 1.0F);
float var2 = 40 * (1.0F - var1);
this.a.aA = MathHelper.b(this.a.aA, this.a.aC, var2);
}
private boolean e() {
return (this.a.getPassengers().isEmpty() || !(this.a.getPassengers().get(0) instanceof EntityInsentient));
}
private boolean f() {
double var0 = this.a.locX() - this.a.lastX;
double var2 = this.a.locZ() - this.a.lastZ;
return (var0 * var0 + var2 * var2 > 2.500000277905201E-7D);
}
}

View File

@ -1,60 +0,0 @@
package net.citizensnpcs.nms.v1_17_R1.util;
import net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Mob;
public class PlayerBodyControl {
private int headStableTime;
private float lastStableYHeadRot;
private final EntityHumanNPC mob;
public PlayerBodyControl(EntityHumanNPC var0) {
this.mob = var0;
}
public void a() {
if (isMoving()) {
this.mob.yBodyRot = this.mob.getYRot();
rotateHeadIfNecessary();
this.lastStableYHeadRot = this.mob.yHeadRot;
this.headStableTime = 0;
return;
}
if (e())
if (Math.abs(this.mob.yHeadRot - this.lastStableYHeadRot) > 15.0F) {
this.lastStableYHeadRot = 0;
this.lastStableYHeadRot = this.mob.yHeadRot;
rotateBodyIfNecessary();
} else {
if (++this.lastStableYHeadRot > 10) {
rotateHeadTowardsFront();
}
}
}
private boolean e() {
return !(this.mob.getFirstPassenger() instanceof Mob);
}
private boolean isMoving() {
double var0 = this.mob.getX() - this.mob.xo;
double var2 = this.mob.getZ() - this.mob.zo;
return (var0 * var0 + var2 * var2 > 2.500000277905201E-7D);
}
private void rotateBodyIfNecessary() {
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, 40);
}
private void rotateHeadIfNecessary() {
this.mob.yHeadRot = Mth.rotateIfNecessary(this.mob.yHeadRot, this.mob.yBodyRot, 40);
}
private void rotateHeadTowardsFront() {
int var0 = this.headStableTime - 10;
float var1 = Mth.clamp(var0 / 10.0F, 0.0F, 1.0F);
float var2 = 40 * (1.0F - var1);
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, var2);
}
}

View File

@ -1,60 +0,0 @@
package net.citizensnpcs.nms.v1_18_R2.util;
import net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Mob;
public class PlayerBodyControl {
private int headStableTime;
private float lastStableYHeadRot;
private final EntityHumanNPC mob;
public PlayerBodyControl(EntityHumanNPC var0) {
this.mob = var0;
}
public void a() {
if (isMoving()) {
this.mob.yBodyRot = this.mob.getYRot();
rotateHeadIfNecessary();
this.lastStableYHeadRot = this.mob.yHeadRot;
this.headStableTime = 0;
return;
}
if (e())
if (Math.abs(this.mob.yHeadRot - this.lastStableYHeadRot) > 15.0F) {
this.lastStableYHeadRot = 0;
this.lastStableYHeadRot = this.mob.yHeadRot;
rotateBodyIfNecessary();
} else {
if (++this.lastStableYHeadRot > 10) {
rotateHeadTowardsFront();
}
}
}
private boolean e() {
return !(this.mob.getFirstPassenger() instanceof Mob);
}
private boolean isMoving() {
double var0 = this.mob.getX() - this.mob.xo;
double var2 = this.mob.getZ() - this.mob.zo;
return (var0 * var0 + var2 * var2 > 2.500000277905201E-7D);
}
private void rotateBodyIfNecessary() {
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, 40);
}
private void rotateHeadIfNecessary() {
this.mob.yHeadRot = Mth.rotateIfNecessary(this.mob.yHeadRot, this.mob.yBodyRot, 40);
}
private void rotateHeadTowardsFront() {
int var0 = this.headStableTime - 10;
float var1 = Mth.clamp(var0 / 10.0F, 0.0F, 1.0F);
float var2 = 40 * (1.0F - var1);
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, var2);
}
}

View File

@ -1,60 +0,0 @@
package net.citizensnpcs.nms.v1_19_R1.util;
import net.citizensnpcs.nms.v1_19_R1.entity.EntityHumanNPC;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Mob;
public class PlayerBodyControl {
private int headStableTime;
private float lastStableYHeadRot;
private final EntityHumanNPC mob;
public PlayerBodyControl(EntityHumanNPC var0) {
this.mob = var0;
}
public void a() {
if (isMoving()) {
this.mob.yBodyRot = this.mob.getYRot();
rotateHeadIfNecessary();
this.lastStableYHeadRot = this.mob.yHeadRot;
this.headStableTime = 0;
return;
}
if (e())
if (Math.abs(this.mob.yHeadRot - this.lastStableYHeadRot) > 15.0F) {
this.lastStableYHeadRot = 0;
this.lastStableYHeadRot = this.mob.yHeadRot;
rotateBodyIfNecessary();
} else {
if (++this.lastStableYHeadRot > 10) {
rotateHeadTowardsFront();
}
}
}
private boolean e() {
return !(this.mob.getFirstPassenger() instanceof Mob);
}
private boolean isMoving() {
double var0 = this.mob.getX() - this.mob.xo;
double var2 = this.mob.getZ() - this.mob.zo;
return (var0 * var0 + var2 * var2 > 2.500000277905201E-7D);
}
private void rotateBodyIfNecessary() {
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, 40);
}
private void rotateHeadIfNecessary() {
this.mob.yHeadRot = Mth.rotateIfNecessary(this.mob.yHeadRot, this.mob.yBodyRot, 40);
}
private void rotateHeadTowardsFront() {
int var0 = this.headStableTime - 10;
float var1 = Mth.clamp(var0 / 10.0F, 0.0F, 1.0F);
float var2 = 40 * (1.0F - var1);
this.mob.yBodyRot = Mth.rotateIfNecessary(this.mob.yBodyRot, this.mob.yHeadRot, var2);
}
}