mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-27 17:52:03 +01:00
Add /npc lookclose --headonly
This commit is contained in:
parent
83040ed525
commit
b38a66dbfb
@ -1361,8 +1361,8 @@ public class NPCCommands {
|
||||
@Flag({ "randomlook", "rlook" }) Boolean randomlook, @Flag("range") Double range,
|
||||
@Flag("randomlookdelay") Integer randomLookDelay, @Flag("randomyawrange") String randomYaw,
|
||||
@Flag("randompitchrange") String randomPitch, @Flag("randomswitchtargets") Boolean randomSwitchTargets,
|
||||
@Flag("disablewhennavigating") Boolean disableWhenNavigating, @Flag("perplayer") Boolean perPlayer,
|
||||
@Flag("targetnpcs") Boolean targetNPCs) throws CommandException {
|
||||
@Flag("headonly") Boolean headonly, @Flag("disablewhennavigating") Boolean disableWhenNavigating,
|
||||
@Flag("perplayer") Boolean perPlayer, @Flag("targetnpcs") Boolean targetNPCs) throws CommandException {
|
||||
boolean toggle = true;
|
||||
LookClose trait = npc.getOrAddTrait(LookClose.class);
|
||||
if (randomlook != null) {
|
||||
@ -1377,6 +1377,11 @@ public class NPCCommands {
|
||||
npc.getName());
|
||||
toggle = false;
|
||||
}
|
||||
if (headonly != null) {
|
||||
trait.setHeadOnly(headonly);
|
||||
Messaging.sendTr(sender, headonly ? Messages.HEADONLY_SET : Messages.HEADONLY_UNSET, npc.getName());
|
||||
toggle = false;
|
||||
}
|
||||
if (randomSwitchTargets != null) {
|
||||
trait.setRandomlySwitchTargets(randomSwitchTargets);
|
||||
Messaging.sendTr(sender, randomSwitchTargets ? Messages.LOOKCLOSE_RANDOM_TARGET_SWITCH_ENABLED
|
||||
|
@ -43,6 +43,8 @@ public class LookClose extends Trait implements Toggleable {
|
||||
private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
|
||||
@Persist
|
||||
private boolean enableRandomLook = Setting.DEFAULT_RANDOM_LOOK_CLOSE.asBoolean();
|
||||
@Persist("headonly")
|
||||
private boolean headOnly;
|
||||
private Player lookingAt;
|
||||
@Persist("perplayer")
|
||||
private boolean perPlayer;
|
||||
@ -97,8 +99,9 @@ public class LookClose extends Trait implements Toggleable {
|
||||
for (Player player : nearbyPlayers) {
|
||||
PacketRotationSession session = sessions.get(player.getUniqueId());
|
||||
if (session == null) {
|
||||
sessions.put(player.getUniqueId(), session = npc.getOrAddTrait(RotationTrait.class)
|
||||
.createPacketSession(new RotationParams().uuidFilter(player.getUniqueId()).persist(true)));
|
||||
sessions.put(player.getUniqueId(),
|
||||
session = npc.getOrAddTrait(RotationTrait.class).createPacketSession(new RotationParams()
|
||||
.headOnly(headOnly).uuidFilter(player.getUniqueId()).persist(true)));
|
||||
}
|
||||
session.getSession().rotateToFace(player);
|
||||
seen.add(player.getUniqueId());
|
||||
@ -196,6 +199,10 @@ public class LookClose extends Trait implements Toggleable {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public boolean isHeadOnly() {
|
||||
return headOnly;
|
||||
}
|
||||
|
||||
private boolean isInvisible(Player player) {
|
||||
return player.getGameMode() == GameMode.SPECTATOR || player.hasPotionEffect(PotionEffectType.INVISIBILITY)
|
||||
|| isPluginVanished(player) || !canSee(player);
|
||||
@ -280,7 +287,9 @@ public class LookClose extends Trait implements Toggleable {
|
||||
if (lookingAt == null)
|
||||
return;
|
||||
|
||||
Util.faceEntity(npc.getEntity(), lookingAt);
|
||||
RotationTrait rot = npc.getOrAddTrait(RotationTrait.class);
|
||||
rot.getGlobalParameters().headOnly(headOnly);
|
||||
rot.getPhysicalSession().rotateToFace(lookingAt);
|
||||
|
||||
if (npc.getEntity().getType().name().equals("SHULKER")) {
|
||||
boolean wasSilent = npc.getEntity().isSilent();
|
||||
@ -300,6 +309,10 @@ public class LookClose extends Trait implements Toggleable {
|
||||
disableWhileNavigating = set;
|
||||
}
|
||||
|
||||
public void setHeadOnly(boolean headOnly) {
|
||||
this.headOnly = headOnly;
|
||||
}
|
||||
|
||||
public void setPerPlayer(boolean perPlayer) {
|
||||
this.perPlayer = perPlayer;
|
||||
}
|
||||
|
@ -318,6 +318,13 @@ public class RotationTrait extends Trait {
|
||||
return target + clamp(diff, -maxRotPerTick, maxRotPerTick);
|
||||
}
|
||||
|
||||
/*
|
||||
* public Vector3 SuperSmoothVector3Lerp( Vector3 pastPosition, Vector3 pastTargetPosition, Vector3 targetPosition, float time, float speed ){
|
||||
Vector3 f = pastPosition - pastTargetPosition + (targetPosition - pastTargetPosition) / (speed * time);
|
||||
return targetPosition - (targetPosition - pastTargetPosition) / (speed*time) + f * Mathf.Exp(-speed*time);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
if (headOnly) {
|
||||
@ -353,13 +360,6 @@ public class RotationTrait extends Trait {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* public Vector3 SuperSmoothVector3Lerp( Vector3 pastPosition, Vector3 pastTargetPosition, Vector3 targetPosition, float time, float speed ){
|
||||
Vector3 f = pastPosition - pastTargetPosition + (targetPosition - pastTargetPosition) / (speed * time);
|
||||
return targetPosition - (targetPosition - pastTargetPosition) / (speed*time) + f * Mathf.Exp(-speed*time);
|
||||
}
|
||||
*/
|
||||
|
||||
public RotationParams uuidFilter(List<UUID> uuids) {
|
||||
this.uuidFilter = uuids;
|
||||
return this;
|
||||
@ -456,12 +456,12 @@ public class RotationTrait extends Trait {
|
||||
: Util.clamp(params.rotateHeadYawTowards(t, rot.headYaw, getTargetYaw()));
|
||||
|
||||
if (!params.headOnly) {
|
||||
float d = Util.clamp(rot.headYaw - 35);
|
||||
float d = Util.clamp(rot.headYaw - 20);
|
||||
if (d > rot.bodyYaw) {
|
||||
rot.bodyYaw = d;
|
||||
}
|
||||
if (d != rot.bodyYaw) {
|
||||
d = Util.clamp(rot.headYaw + 35);
|
||||
d = Util.clamp(rot.headYaw + 20);
|
||||
if (d < rot.bodyYaw) {
|
||||
rot.bodyYaw = d;
|
||||
}
|
||||
|
@ -89,9 +89,8 @@ public class ScoreboardTrait extends Trait {
|
||||
return;
|
||||
Team team = Util.getDummyScoreboard().getTeam(teamName);
|
||||
npc.data().remove(NPC.Metadata.SCOREBOARD_FAKE_TEAM_NAME);
|
||||
if (team == null)
|
||||
if (team == null || !team.hasEntry(name))
|
||||
return;
|
||||
if (team.hasEntry(name)) {
|
||||
if (team.getSize() == 1) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
metadata.remove(player.getUniqueId(), team.getName());
|
||||
@ -102,7 +101,6 @@ public class ScoreboardTrait extends Trait {
|
||||
team.removeEntry(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove() {
|
||||
|
@ -141,6 +141,8 @@ public class Messages {
|
||||
public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken";
|
||||
public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin";
|
||||
public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end";
|
||||
public static final String HEADONLY_SET = "citizens.commands.npc.lookclose.headonly-set";
|
||||
public static final String HEADONLY_UNSET = "citizens.commands.npc.lookclose.headonly-unset";
|
||||
public static final String HOLOGRAM_CLEARED = "citizens.commands.npc.hologram.cleared";
|
||||
public static final String HOLOGRAM_DESCRIBE_HEADER = "citizens.commands.npc.hologram.text-describe-header";
|
||||
public static final String HOLOGRAM_DIRECTION_SET = "citizens.commands.npc.hologram.direction-set";
|
||||
|
@ -141,6 +141,8 @@ citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
|
||||
citizens.commands.npc.llama.strength-set=Llama strength set to [[{0}]].
|
||||
citizens.commands.npc.llama.color-set=Llama color set to [[{0}]].
|
||||
citizens.commands.npc.llama.invalid-color=Invalid llama color given. Valid colors are: [[{0}]].
|
||||
citizens.commands.npc.lookclose.headonly-set=[[{0}]] will now only rotate using its head.
|
||||
citizens.commands.npc.lookclose.headonly-unset=[[{0}]] will now rotate its body.
|
||||
citizens.commands.npc.lookclose.range-set=[[{0}]]''s lookclose range set to [[{1}]] blocks.
|
||||
citizens.commands.npc.lookclose.rl-set=[[{0}]] will no longer look through blocks at players.
|
||||
citizens.commands.npc.lookclose.rl-unset=[[{0}]] will now always look at players, even through blocks.
|
||||
|
Loading…
Reference in New Issue
Block a user