Fix sneak animation

This commit is contained in:
fullwall 2023-01-01 20:44:17 +08:00
parent c706b17848
commit 36feecdc2b
8 changed files with 39 additions and 35 deletions

View File

@ -15,7 +15,7 @@ import net.citizensnpcs.util.NMS;
@TraitName("sittrait") @TraitName("sittrait")
public class SitTrait extends Trait { public class SitTrait extends Trait {
private NPC holder; private NPC chair;
@Persist @Persist
private Location sittingAt; private Location sittingAt;
@ -29,9 +29,12 @@ public class SitTrait extends Trait {
@Override @Override
public void onDespawn() { public void onDespawn() {
if (holder != null) { if (chair != null) {
holder.destroy(); if (chair.getEntity() != null) {
holder = null; chair.getEntity().eject();
}
chair.destroy();
chair = null;
} }
} }
@ -42,26 +45,28 @@ public class SitTrait extends Trait {
@Override @Override
public void run() { public void run() {
if (!npc.isSpawned() || !isSitting()) { if (!npc.isSpawned() || !isSitting())
return; return;
}
if (holder == null) { if (chair == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl"); NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("SitRegistry");
if (registry == null) { if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore()); registry = CitizensAPI.createNamedNPCRegistry("SitRegistry", new MemoryNPCDataStore());
}
chair = registry.createNPC(EntityType.ARMOR_STAND, "");
chair.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntity(npc);
if (!chair.spawn(sittingAt)) {
chair = null;
return;
} }
holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntity(npc);
holder.spawn(sittingAt);
} }
if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) { if (chair.isSpawned() && !NMS.getPassengers(chair.getEntity()).contains(npc.getEntity())) {
NMS.mount(holder.getEntity(), npc.getEntity()); NMS.mount(chair.getEntity(), npc.getEntity());
} }
if (holder.getStoredLocation() != null && holder.getStoredLocation().distance(sittingAt) > 0.05) { if (chair.getStoredLocation() != null && chair.getStoredLocation().distance(sittingAt) > 0.05) {
holder.teleport(sittingAt, TeleportCause.PLUGIN); chair.teleport(sittingAt, TeleportCause.PLUGIN);
} }
} }

View File

@ -898,7 +898,7 @@ public class NMSImpl implements NMSBridge {
if (!removeFromPlayerList) { if (!removeFromPlayerList) {
return; return;
} }
Entity entity1 = entity.getVehicle(); Entity entity1 = entity.bB();
if (entity1 != null) { if (entity1 != null) {
if ((entity1.dead) || (!entity1.w(entity))) { if ((entity1.dead) || (!entity1.w(entity))) {
entity.stopRiding(); entity.stopRiding();
@ -906,7 +906,7 @@ public class NMSImpl implements NMSBridge {
} else { } else {
if (!entity.dead) { if (!entity.dead) {
try { try {
entity.world.entityJoinedWorld(entity, true); entity.world.g(entity);
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player"); CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");

View File

@ -956,7 +956,7 @@ public class NMSImpl implements NMSBridge {
if (!removeFromPlayerList) { if (!removeFromPlayerList) {
return; return;
} }
Entity entity1 = entity.getVehicle(); Entity entity1 = entity.bB();
if (entity1 != null) { if (entity1 != null) {
if ((entity1.dead) || (!entity1.w(entity))) { if ((entity1.dead) || (!entity1.w(entity))) {
entity.stopRiding(); entity.stopRiding();

View File

@ -472,13 +472,8 @@ public class NMSImpl implements NMSBridge {
public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) { public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
Entity handle = NMSImpl.getHandle(entity); Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null) if (handle == null || handle.passengers == null)
return Lists.newArrayList(); return Collections.emptyList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() { return Lists.transform(handle.passengers, input -> input.getBukkitEntity());
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
} }
@Override @Override
@ -966,7 +961,7 @@ public class NMSImpl implements NMSBridge {
if (!removeFromPlayerList) { if (!removeFromPlayerList) {
return; return;
} }
Entity entity1 = entity.getVehicle(); Entity entity1 = entity.bJ();
if (entity1 != null) { if (entity1 != null) {
if ((entity1.dead) || (!entity1.w(entity))) { if ((entity1.dead) || (!entity1.w(entity))) {
entity.stopRiding(); entity.stopRiding();

View File

@ -8,6 +8,7 @@ import com.google.common.collect.Maps;
import net.citizensnpcs.util.PlayerAnimation; import net.citizensnpcs.util.PlayerAnimation;
import net.minecraft.server.v1_16_R3.EntityPlayer; import net.minecraft.server.v1_16_R3.EntityPlayer;
import net.minecraft.server.v1_16_R3.EntityPose;
import net.minecraft.server.v1_16_R3.EnumHand; import net.minecraft.server.v1_16_R3.EnumHand;
import net.minecraft.server.v1_16_R3.Packet; import net.minecraft.server.v1_16_R3.Packet;
import net.minecraft.server.v1_16_R3.PacketPlayOutAnimation; import net.minecraft.server.v1_16_R3.PacketPlayOutAnimation;
@ -22,7 +23,7 @@ public class PlayerAnimationImpl {
} }
switch (animation) { switch (animation) {
case SNEAK: case SNEAK:
player.getBukkitEntity().setSneaking(true); player.setPose(EntityPose.CROUCHING);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
radius); radius);
break; break;
@ -43,7 +44,7 @@ public class PlayerAnimationImpl {
radius); radius);
break; break;
case STOP_SNEAKING: case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false); player.setPose(EntityPose.STANDING);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player,
radius); radius);
break; break;

View File

@ -12,6 +12,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Pose;
public class PlayerAnimationImpl { public class PlayerAnimationImpl {
public static void play(PlayerAnimation animation, Player bplayer, int radius) { public static void play(PlayerAnimation animation, Player bplayer, int radius) {
@ -22,7 +23,7 @@ public class PlayerAnimationImpl {
} }
switch (animation) { switch (animation) {
case SNEAK: case SNEAK:
player.getBukkitEntity().setSneaking(true); player.setPose(Pose.CROUCHING);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
player, radius); player, radius);
break; break;
@ -43,7 +44,7 @@ public class PlayerAnimationImpl {
player, radius); player, radius);
break; break;
case STOP_SNEAKING: case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false); player.setPose(Pose.STANDING);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
player, radius); player, radius);
break; break;

View File

@ -12,6 +12,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Pose;
public class PlayerAnimationImpl { public class PlayerAnimationImpl {
public static void play(PlayerAnimation animation, Player bplayer, int radius) { public static void play(PlayerAnimation animation, Player bplayer, int radius) {
@ -22,7 +23,7 @@ public class PlayerAnimationImpl {
} }
switch (animation) { switch (animation) {
case SNEAK: case SNEAK:
player.getBukkitEntity().setSneaking(true); player.setPose(Pose.CROUCHING);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
player, radius); player, radius);
break; break;
@ -43,7 +44,7 @@ public class PlayerAnimationImpl {
player, radius); player, radius);
break; break;
case STOP_SNEAKING: case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false); player.setPose(Pose.STANDING);
sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true), sendPacketNearby(new ClientboundSetEntityDataPacket(player.getId(), player.getEntityData(), true),
player, radius); player, radius);
break; break;

View File

@ -12,6 +12,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Pose;
public class PlayerAnimationImpl { public class PlayerAnimationImpl {
public static void play(PlayerAnimation animation, Player bplayer, int radius) { public static void play(PlayerAnimation animation, Player bplayer, int radius) {
@ -22,7 +23,7 @@ public class PlayerAnimationImpl {
} }
switch (animation) { switch (animation) {
case SNEAK: case SNEAK:
player.getBukkitEntity().setSneaking(true); player.setPose(Pose.CROUCHING);
sendEntityData(radius, player); sendEntityData(radius, player);
break; break;
case START_ELYTRA: case START_ELYTRA:
@ -40,7 +41,7 @@ public class PlayerAnimationImpl {
sendEntityData(radius, player); sendEntityData(radius, player);
break; break;
case STOP_SNEAKING: case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false); player.setPose(Pose.STANDING);
sendEntityData(radius, player); sendEntityData(radius, player);
break; break;
case STOP_USE_ITEM: case STOP_USE_ITEM: