mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-03-12 06:44:14 +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(
|
@Command(
|
||||||
aliases = { "npc" },
|
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",
|
desc = "Toggle whether a NPC will look when a player is near",
|
||||||
modifiers = { "lookclose", "look", "rotate" },
|
modifiers = { "lookclose", "look", "rotate" },
|
||||||
min = 1,
|
min = 1,
|
||||||
|
@ -132,10 +132,6 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
|||||||
return lookingAt;
|
return lookingAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEqual(float[] array) {
|
|
||||||
return Math.abs(array[0] - array[1]) < 0.001;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInvisible(Player player) {
|
private boolean isInvisible(Player player) {
|
||||||
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
||||||
|| isPluginVanished(player) || !canSee(player);
|
|| 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();
|
: rand.doubles(randomPitchRange[0], randomPitchRange[1]).iterator().next().floatValue();
|
||||||
float yaw = isEqual(randomYawRange) ? randomYawRange[0]
|
float yaw = isEqual(randomYawRange) ? randomYawRange[0]
|
||||||
: rand.doubles(randomYawRange[0], randomYawRange[1]).iterator().next().floatValue();
|
: rand.doubles(randomYawRange[0], randomYawRange[1]).iterator().next().floatValue();
|
||||||
Util.assumePose(npc.getEntity(), yaw, pitch);
|
Util.face(npc.getEntity(), yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!enabled || !npc.isSpawned()) {
|
if (!npc.isSpawned())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (enableRandomLook) {
|
||||||
|
if (!npc.getNavigator().isNavigating() && lookingAt == null && t <= 0) {
|
||||||
|
randomLook();
|
||||||
|
t = randomLookDelay;
|
||||||
|
} else {
|
||||||
|
t--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (npc.getNavigator().isNavigating() && disableWhileNavigating()) {
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
if (npc.getNavigator().isNavigating() && disableWhileNavigating())
|
||||||
|
return;
|
||||||
|
|
||||||
npc.getEntity().getLocation(NPC_LOCATION);
|
npc.getEntity().getLocation(NPC_LOCATION);
|
||||||
if (tryInvalidateTarget()) {
|
if (tryInvalidateTarget()) {
|
||||||
findNewTarget();
|
findNewTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (npc.getNavigator().isNavigating()) {
|
if (npc.getNavigator().isNavigating()) {
|
||||||
npc.getNavigator().setPaused(lookingAt != null);
|
npc.getNavigator().setPaused(lookingAt != null);
|
||||||
} else if (lookingAt == null && enableRandomLook && t <= 0) {
|
|
||||||
randomLook();
|
|
||||||
t = randomLookDelay;
|
|
||||||
}
|
}
|
||||||
t--;
|
|
||||||
if (lookingAt == null)
|
if (lookingAt == null)
|
||||||
return;
|
return;
|
||||||
Util.faceEntity(npc.getEntity(), lookingAt);
|
Util.faceEntity(npc.getEntity(), lookingAt);
|
||||||
@ -298,6 +303,10 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
|
|||||||
return realisticLooking;
|
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 CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||||
private static final Location NPC_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);
|
private static final Location PLAYER_LOCATION = new Location(null, 0, 0, 0);
|
||||||
|
@ -76,6 +76,12 @@ public class Util {
|
|||||||
return yaw;
|
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) {
|
public static void faceEntity(Entity entity, Entity at) {
|
||||||
if (at == null || entity == null || entity.getWorld() != at.getWorld())
|
if (at == null || entity == null || entity.getWorld() != at.getWorld())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user