Skip to content

Commit

Permalink
fix npc sneak, fixes #1999
Browse files Browse the repository at this point in the history
this was broken by a Spigot issue I think, and so has been workaround'd by NMS
  • Loading branch information
mcmonkey4eva committed Oct 22, 2019
1 parent da1999a commit 183c447
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Expand Up @@ -22,6 +22,10 @@

public abstract class EntityHelper {

public void setSneaking(Player player, boolean sneak) {
player.setSneaking(sneak);
}

public abstract double getDamageTo(LivingEntity attacker, Entity target);

public abstract String getRawHoverText(Entity entity);
Expand Down
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.npc.traits;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.DenizenAPI;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void sneak() {
return;
}

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

sneaking = true;
}
Expand All @@ -52,7 +53,7 @@ public void stand() {
// Notated in SittingTrait
DenizenAPI.getDenizenNPC(npc).action("stand", null);

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

sneaking = false;
}
Expand Down
Expand Up @@ -35,6 +35,25 @@

public class EntityHelperImpl extends EntityHelper {

public static final Field RECIPE_BOOK_DISCOVERED_SET = ReflectionHelper.getFields(RecipeBook.class).get("a");

public static final MethodHandle ENTITY_HOVER_TEXT_GETTER = ReflectionHelper.getMethodHandle(net.minecraft.server.v1_14_R1.Entity.class, "bK");

public static final MethodHandle ENTITY_SETPOSE = ReflectionHelper.getMethodHandle(net.minecraft.server.v1_14_R1.Entity.class, "setPose", EntityPose.class);

@Override
public void setSneaking(Player player, boolean sneak) {
player.setSneaking(sneak);
EntityPose pose = sneak ? EntityPose.SNEAKING : EntityPose.STANDING;
try {
ENTITY_SETPOSE.invoke(((CraftPlayer) player).getHandle(), pose);
}
catch (Throwable ex) {
Debug.echoError(ex);
}

}

@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
EnumMonsterType monsterType;
Expand All @@ -51,10 +70,6 @@ public double getDamageTo(LivingEntity attacker, Entity target) {
return damage;
}

public static final Field RECIPE_BOOK_DISCOVERED_SET = ReflectionHelper.getFields(RecipeBook.class).get("a");

public static final MethodHandle ENTITY_HOVER_TEXT_GETTER = ReflectionHelper.getMethodHandle(net.minecraft.server.v1_14_R1.Entity.class, "bK");

@Override
public String getRawHoverText(Entity entity) {
try {
Expand Down

0 comments on commit 183c447

Please sign in to comment.