mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-12 13:44:07 +01:00
Work towards lookclose rotation speed changing
This commit is contained in:
parent
733064c18d
commit
f358f6fb2e
@ -1147,7 +1147,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "lookclose --range [range] (-r[ealistic looking]) --(random|r)look [true|false] --(random|r)pitchrange [min,max] --(random|r)yawrange [min,max]",
|
||||
usage = "lookclose --range [range] -r[ealistic looking] --(random|r)look [true|false] --(random|r)pitchrange [min,max] --(random|r)yawrange [min,max]",
|
||||
desc = "Toggle whether a NPC will look when a player is near",
|
||||
modifiers = { "lookclose", "look", "rotate" },
|
||||
min = 1,
|
||||
|
@ -132,10 +132,6 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
return lookingAt;
|
||||
}
|
||||
|
||||
private boolean isEqual(float[] array) {
|
||||
return Math.abs(array[0] - array[1]) < 0.001;
|
||||
}
|
||||
|
||||
private boolean isInvisible(Player player) {
|
||||
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
||||
|| isPluginVanished(player) || !canSee(player);
|
||||
@ -189,28 +185,37 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
: rand.doubles(randomPitchRange[0], randomPitchRange[1]).iterator().next().floatValue();
|
||||
float yaw = isEqual(randomYawRange) ? randomYawRange[0]
|
||||
: rand.doubles(randomYawRange[0], randomYawRange[1]).iterator().next().floatValue();
|
||||
Util.assumePose(npc.getEntity(), yaw, pitch);
|
||||
Util.face(npc.getEntity(), yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!enabled || !npc.isSpawned()) {
|
||||
if (!npc.isSpawned())
|
||||
return;
|
||||
|
||||
if (enableRandomLook) {
|
||||
if (!npc.getNavigator().isNavigating() && lookingAt == null && t <= 0) {
|
||||
randomLook();
|
||||
t = randomLookDelay;
|
||||
} else {
|
||||
t--;
|
||||
}
|
||||
if (npc.getNavigator().isNavigating() && disableWhileNavigating()) {
|
||||
}
|
||||
if (!enabled)
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc.getNavigator().isNavigating() && disableWhileNavigating())
|
||||
return;
|
||||
|
||||
npc.getEntity().getLocation(NPC_LOCATION);
|
||||
if (tryInvalidateTarget()) {
|
||||
findNewTarget();
|
||||
}
|
||||
|
||||
if (npc.getNavigator().isNavigating()) {
|
||||
npc.getNavigator().setPaused(lookingAt != null);
|
||||
} else if (lookingAt == null && enableRandomLook && t <= 0) {
|
||||
randomLook();
|
||||
t = randomLookDelay;
|
||||
}
|
||||
t--;
|
||||
|
||||
if (lookingAt == null)
|
||||
return;
|
||||
Util.faceEntity(npc.getEntity(), lookingAt);
|
||||
@ -298,6 +303,10 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
||||
return realisticLooking;
|
||||
}
|
||||
|
||||
private static boolean isEqual(float[] array) {
|
||||
return Math.abs(array[0] - array[1]) < 0.001;
|
||||
}
|
||||
|
||||
private static final Location CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static final Location NPC_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static final Location PLAYER_LOCATION = new Location(null, 0, 0, 0);
|
||||
|
@ -76,6 +76,12 @@ public class Util {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public static void face(Entity entity, float yaw, float pitch) {
|
||||
Vector vector = new Vector(Math.cos(yaw) * Math.cos(pitch), Math.sin(pitch), Math.sin(yaw) * Math.cos(pitch))
|
||||
.normalize();
|
||||
faceLocation(entity, entity.getLocation(AT_LOCATION).clone().add(vector));
|
||||
}
|
||||
|
||||
public static void faceEntity(Entity entity, Entity at) {
|
||||
if (at == null || entity == null || entity.getWorld() != at.getWorld())
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user