mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-27 09:42:37 +01:00
Make /npc rotate use arm swing to fix rotation
This commit is contained in:
parent
bdd995197a
commit
d9a4a3e5e2
@ -175,10 +175,12 @@ public class ProtocolLibListener {
|
||||
packet.getBytes().write(0, degToByte(session.getBodyYaw()));
|
||||
packet.getBytes().write(1, degToByte(session.getPitch()));
|
||||
} else if (type == Server.POSITION) {
|
||||
Set<PlayerTeleportFlag> rel = getFlagsModifier(packet).read(0);
|
||||
StructureModifier<Set<PlayerTeleportFlag>> flagsModifier = packet
|
||||
.getSets(EnumWrappers.getGenericConverter(flagsClass, PlayerTeleportFlag.class));
|
||||
Set<PlayerTeleportFlag> rel = flagsModifier.read(0);
|
||||
rel.remove(PlayerTeleportFlag.ZYAW);
|
||||
rel.remove(PlayerTeleportFlag.ZPITCH);
|
||||
getFlagsModifier(packet).write(0, rel);
|
||||
flagsModifier.write(0, rel);
|
||||
packet.getFloat().write(0, session.getBodyYaw());
|
||||
packet.getFloat().write(1, session.getPitch());
|
||||
}
|
||||
@ -189,10 +191,6 @@ public class ProtocolLibListener {
|
||||
|
||||
}
|
||||
|
||||
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier(PacketContainer handle) {
|
||||
return handle.getSets(EnumWrappers.getGenericConverter(flagsClass, PlayerTeleportFlag.class));
|
||||
}
|
||||
|
||||
private NPC getNPCFromPacket(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Entity entity = null;
|
||||
|
@ -711,7 +711,6 @@ public class NPCCommands {
|
||||
msg += " as a baby";
|
||||
npc.getOrAddTrait(Age.class).setAge(-24000);
|
||||
}
|
||||
|
||||
if (args.hasFlag('s')) {
|
||||
npc.data().set(NPC.Metadata.SILENT, true);
|
||||
}
|
||||
@ -1783,18 +1782,19 @@ public class NPCCommands {
|
||||
Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
|
||||
Messaging.send(sender, " ID: [[" + npc.getId());
|
||||
EntityType type = npc.getOrAddTrait(MobType.class).getType();
|
||||
Messaging.send(sender,
|
||||
" UUID: [[" + npc.getUniqueId() + (npc.isSpawned() && type == EntityType.PLAYER ? "(v4)" : ""));
|
||||
Messaging.send(sender, " UUID: [[" + npc.getUniqueId());
|
||||
Messaging.send(sender, " Type: [[" + type);
|
||||
if (npc.isSpawned()) {
|
||||
Location loc = npc.getEntity().getLocation();
|
||||
String format = " Spawned at [[%d, %d, %d]] in world [[%s";
|
||||
String format = " Spawned at [[%d, %d, %d, %.2f, %.2f (head %.2f)]] [[%s";
|
||||
Messaging.send(sender,
|
||||
String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName()));
|
||||
String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),
|
||||
NMS.getYaw(npc.getEntity()), loc.getPitch(), NMS.getHeadYaw(npc.getEntity()),
|
||||
loc.getWorld().getName()));
|
||||
}
|
||||
Messaging.send(sender, " Traits");
|
||||
for (Trait trait : npc.getTraits()) {
|
||||
String message = " [[- ]]" + trait.getName();
|
||||
String message = " - [[" + trait.getName();
|
||||
Messaging.send(sender, message);
|
||||
}
|
||||
}
|
||||
@ -2455,6 +2455,7 @@ public class NPCCommands {
|
||||
NMS.setBodyYaw(npc.getEntity(), yaw);
|
||||
if (npc.getEntity().getType() == EntityType.PLAYER) {
|
||||
NMS.sendPositionUpdate(npc.getEntity(), true, yaw, npc.getStoredLocation().getPitch(), null);
|
||||
PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
|
||||
}
|
||||
}
|
||||
if (pitch != null) {
|
||||
|
@ -40,7 +40,6 @@ import net.citizensnpcs.npc.ai.AStarNavigationStrategy.AStarPlanner;
|
||||
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.RotationTrait.PacketRotationSession;
|
||||
import net.citizensnpcs.trait.RotationTrait.RotationParams;
|
||||
import net.citizensnpcs.util.ChunkCoord;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
||||
@ -205,7 +204,8 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
if (localParams.lookAtFunction() != null) {
|
||||
if (session == null) {
|
||||
RotationTrait trait = npc.getOrAddTrait(RotationTrait.class);
|
||||
session = trait.createPacketSession(new RotationParams().filter(p -> true).persist(true));
|
||||
session = trait
|
||||
.createPacketSession(trait.getGlobalParameters().clone().filter(p -> true).persist(true));
|
||||
}
|
||||
session.getSession().rotateToFace(localParams.lookAtFunction().apply(this));
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.trait.RotationTrait.PacketRotationSession;
|
||||
import net.citizensnpcs.trait.RotationTrait.RotationParams;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
@ -98,14 +97,15 @@ public class LookClose extends Trait implements Toggleable {
|
||||
public void findNewTarget() {
|
||||
if (perPlayer) {
|
||||
lookingAt = null;
|
||||
List<Player> nearbyPlayers = getNearbyPlayers();
|
||||
RotationTrait rotationTrait = npc.getOrAddTrait(RotationTrait.class);
|
||||
Set<UUID> seen = Sets.newHashSet();
|
||||
for (Player player : nearbyPlayers) {
|
||||
for (Player player : getNearbyPlayers()) {
|
||||
PacketRotationSession session = sessions.get(player.getUniqueId());
|
||||
if (session == null) {
|
||||
sessions.put(player.getUniqueId(),
|
||||
session = npc.getOrAddTrait(RotationTrait.class).createPacketSession(new RotationParams()
|
||||
.headOnly(headOnly).uuidFilter(player.getUniqueId()).persist(true)));
|
||||
session = rotationTrait.createPacketSession(
|
||||
rotationTrait.getGlobalParameters().clone().linkedBody(linkedBody)
|
||||
.headOnly(headOnly).uuidFilter(player.getUniqueId()).persist(true)));
|
||||
}
|
||||
session.getSession().rotateToFace(player);
|
||||
seen.add(player.getUniqueId());
|
||||
|
Loading…
Reference in New Issue
Block a user