diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index cb8ab37cc..ef615215b 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -326,9 +326,6 @@ public class CitizensNPC extends AbstractNPC { if (getEntity() instanceof Player) { NMS.replaceTrackerEntry((Player) getEntity()); PlayerUpdateTask.registerPlayer(getEntity()); - if (!hasTrait(SneakTrait.class)) { - addTrait(SneakTrait.class); - } } } @@ -408,6 +405,9 @@ public class CitizensNPC extends AbstractNPC { if (isLiving && getEntity() instanceof Player) { updateUsingItemState((Player) getEntity()); + if (data().has(NPC.Metadata.SNEAKING) && !hasTrait(SneakTrait.class)) { + addTrait(SneakTrait.class); + } } if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) { diff --git a/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java b/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java index 7fd493698..d9aaf7c82 100644 --- a/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/SneakTrait.java @@ -16,7 +16,9 @@ public class SneakTrait extends Trait { } private void apply() { - NMS.setSneaking(npc.getEntity(), sneaking); + if (npc.isSpawned()) { + NMS.setSneaking(npc.getEntity(), sneaking); + } } @Override @@ -34,8 +36,6 @@ public class SneakTrait extends Trait { public void setSneaking(boolean sneak) { this.sneaking = sneak; - if (npc.isSpawned()) { - apply(); - } + apply(); } } \ No newline at end of file diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/CustomEntityRegistry.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/CustomEntityRegistry.java index 029280e92..e04113809 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/CustomEntityRegistry.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/CustomEntityRegistry.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Optional; import java.util.Random; import java.util.Set; +import java.util.function.Function; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -143,7 +144,8 @@ public class CustomEntityRegistry extends DefaultedRegistry { public CustomEntityRegistry(DefaultedRegistry> original) throws Throwable { super(original.getDefaultKey().getNamespace(), (ResourceKey>>) IREGISTRY_RESOURCE_KEY.invoke(original), - (Lifecycle) IREGISTRY_LIFECYCLE.invoke(original), null); + (Lifecycle) IREGISTRY_LIFECYCLE.invoke(original), + (Function) IREGISTRY_CUSTOM_HOLDER_PROVDER.invoke(original)); this.wrapped = original; } @@ -224,6 +226,8 @@ public class CustomEntityRegistry extends DefaultedRegistry { entityIds.put(entityClass, entityId); } + private static final MethodHandle IREGISTRY_CUSTOM_HOLDER_PROVDER = NMS.getFirstGetter(MappedRegistry.class, + Function.class); private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class); // replace regex // .*?> ([A-Z_]+).*?of\((.*?)::new.*?$ diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerNavigation.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerNavigation.java index 710553fa6..71b1a79f3 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerNavigation.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/PlayerNavigation.java @@ -147,7 +147,7 @@ public class PlayerNavigation extends PathNavigation { } return true; } - + private boolean canWalkOn(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7, double var9) { int var11 = var0 - var3 / 2;