From a67866ff4241caf4d56f16ffb91e2d833968cbd9 Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 20 Aug 2018 18:27:04 +0200 Subject: [PATCH] Set armor stands as markers on Minecraft 1.8 --- .../nms/v1_8_R1/EntityNMSArmorStand.java | 6 ++++++ .../nms/v1_8_R2/EntityNMSArmorStand.java | 6 ++++++ .../nms/v1_8_R3/EntityNMSArmorStand.java | 6 ++++++ .../gmail/filoghost/holographicdisplays/util/Offsets.java | 2 +- .../filoghost/holographicdisplays/util/ReflectionUtils.java | 6 ++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java b/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java index 7de0e218..2a6a8248 100644 --- a/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java +++ b/NMS/v1_8_R1/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R1/EntityNMSArmorStand.java @@ -31,6 +31,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta setArms(false); setGravity(true); setBasePlate(true); + try { + ReflectionUtils.callPrivateMethod(EntityArmorStand.class, this, "n", new Class[]{ boolean.class }, new Object[]{ true }); // n() = setMarker() + } catch (Exception e) { + e.printStackTrace(); + // It will still work. + } this.parentPiece = parentPiece; try { ReflectionUtils.setPrivateField(EntityArmorStand.class, this, "bg", Integer.MAX_VALUE); diff --git a/NMS/v1_8_R2/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java b/NMS/v1_8_R2/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java index a01490ea..a6b6b480 100644 --- a/NMS/v1_8_R2/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java +++ b/NMS/v1_8_R2/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java @@ -31,6 +31,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta setArms(false); setGravity(true); setBasePlate(true); + try { + ReflectionUtils.callPrivateMethod(EntityArmorStand.class, this, "n", new Class[]{ boolean.class }, new Object[]{ true }); // n() = setMarker() + } catch (Exception e) { + e.printStackTrace(); + // It will still work. + } this.parentPiece = parentPiece; try { ReflectionUtils.setPrivateField(EntityArmorStand.class, this, "bi", Integer.MAX_VALUE); diff --git a/NMS/v1_8_R3/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java b/NMS/v1_8_R3/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java index c1dfe2d1..57b28461 100644 --- a/NMS/v1_8_R3/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java +++ b/NMS/v1_8_R3/src/main/java/com/gmail/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java @@ -31,6 +31,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta setArms(false); setGravity(true); setBasePlate(true); + try { + ReflectionUtils.callPrivateMethod(EntityArmorStand.class, this, "n", new Class[]{ boolean.class }, new Object[]{ true }); // n() = setMarker() + } catch (Exception e) { + e.printStackTrace(); + // It will still work. + } this.parentPiece = parentPiece; try { ReflectionUtils.setPrivateField(EntityArmorStand.class, this, "bi", Integer.MAX_VALUE); diff --git a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java index a3a780fa..21562aef 100644 --- a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java +++ b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/Offsets.java @@ -12,7 +12,7 @@ public class Offsets { WITHER_SKULL_WITH_SLIME = -0.22, // For 1.8+, a single armor stand. As with wither skulls and horses, the bottom part of the nametag should be on the surface of the block. - ARMOR_STAND_ALONE = -1.25, + ARMOR_STAND_ALONE = -0.26, // For 1.8+, an armor stand holding an item. ARMOR_STAND_WITH_ITEM = -1.48, diff --git a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/ReflectionUtils.java b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/ReflectionUtils.java index 877f9e5e..f60e4353 100644 --- a/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/ReflectionUtils.java +++ b/Utils/src/main/java/com/gmail/filoghost/holographicdisplays/util/ReflectionUtils.java @@ -29,6 +29,12 @@ public class ReflectionUtils { return field.get(handle); } + public static Object callPrivateMethod(Class clazz, Object handle, String methodName, Class[] parameterTypes, Object[] args) throws Exception { + Method method = clazz.getDeclaredMethod(methodName, parameterTypes); + method.setAccessible(true); + return method.invoke(handle, args); + } + private static Method getStackTraceElementMethod; private static Method getStackTraceDepthMethod;