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")
public class SitTrait extends Trait {
private NPC holder;
private NPC chair;
@Persist
private Location sittingAt;
@ -29,9 +29,12 @@ public class SitTrait extends Trait {
@Override
public void onDespawn() {
if (holder != null) {
holder.destroy();
holder = null;
if (chair != null) {
if (chair.getEntity() != null) {
chair.getEntity().eject();
}
chair.destroy();
chair = null;
}
}
@ -42,26 +45,28 @@ public class SitTrait extends Trait {
@Override
public void run() {
if (!npc.isSpawned() || !isSitting()) {
if (!npc.isSpawned() || !isSitting())
return;
}
if (holder == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (chair == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("SitRegistry");
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())) {
NMS.mount(holder.getEntity(), npc.getEntity());
if (chair.isSpawned() && !NMS.getPassengers(chair.getEntity()).contains(npc.getEntity())) {
NMS.mount(chair.getEntity(), npc.getEntity());
}
if (holder.getStoredLocation() != null && holder.getStoredLocation().distance(sittingAt) > 0.05) {
holder.teleport(sittingAt, TeleportCause.PLUGIN);
if (chair.getStoredLocation() != null && chair.getStoredLocation().distance(sittingAt) > 0.05) {
chair.teleport(sittingAt, TeleportCause.PLUGIN);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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