Skip to content

Commit

Permalink
fix npc sneak nms logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 30, 2021
1 parent ab2f027 commit 1bd6c9a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
Expand Up @@ -35,13 +35,10 @@ public void onSpawn() {
*/
public void sneak() {
new NPCTag(npc).action("sneak", null);

if (npc.getEntity().getType() != EntityType.PLAYER) {
return;
}

NMSHandler.getEntityHelper().setSneaking(npc.getEntity(), true);

sneaking = true;
}

Expand All @@ -51,9 +48,7 @@ public void sneak() {
public void stand() {
// Notated in SittingTrait
new NPCTag(npc).action("stand", null);

NMSHandler.getEntityHelper().setSneaking(npc.getEntity(), false);

sneaking = false;
}

Expand Down
Expand Up @@ -67,8 +67,6 @@ public class EntityHelperImpl extends EntityHelper {

public static final Field RECIPE_BOOK_DISCOVERED_SET = ReflectionHelper.getFields(RecipeBook.class).get(ReflectionMappingsInfo.RecipeBook_highlight);

public static final MethodHandle ENTITY_SETPOSE = ReflectionHelper.getMethodHandle(net.minecraft.world.entity.Entity.class, null, Pose.class); // Entity#setPose(Pose)

public static final MethodHandle ENTITY_ONGROUND_SETTER = ReflectionHelper.getFinalSetter(net.minecraft.world.entity.Entity.class, ReflectionMappingsInfo.Entity_onGround);

public static final EntityDataAccessor<Boolean> ENTITY_ENDERMAN_DATAWATCHER_SCREAMING = ReflectionHelper.getFieldValue(EnderMan.class, ReflectionMappingsInfo.EnderMan_DATA_CREEPY, null);
Expand All @@ -94,12 +92,7 @@ public void setSneaking(Entity player, boolean sneak) {
((Player) player).setSneaking(sneak);
}
Pose pose = sneak ? Pose.CROUCHING : Pose.STANDING;
try {
ENTITY_SETPOSE.invoke(((CraftEntity) player).getHandle(), pose);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
((CraftEntity) player).getHandle().setPose(pose);
}

@Override
Expand Down

0 comments on commit 1bd6c9a

Please sign in to comment.