From b178126966d5d5cb3d308d5db58a7413947353e3 Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 25 Feb 2022 13:53:11 -0500 Subject: [PATCH] Fixing vector on useentity --- .../api/reflections/Reflections.java | 9 ++++++++- .../packet/in/WrappedInUseEntityPacket.java | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/reflections/Reflections.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/reflections/Reflections.java index 98a198fe..bc6e22cf 100644 --- a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/reflections/Reflections.java +++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/reflections/Reflections.java @@ -11,6 +11,7 @@ import cc.funkemunky.api.reflections.types.WrappedClass; import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion; +import cc.funkemunky.api.tinyprotocol.reflection.Reflection; import cc.funkemunky.api.utils.ClassScanner; import cc.funkemunky.api.utils.objects.QuadFunction; import cc.funkemunky.api.utils.objects.TriFunction; @@ -24,6 +25,7 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Method; +import java.util.Collections; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; @@ -41,7 +43,12 @@ public class Reflections { craftBukkitString = "org.bukkit.craftbukkit." + version + "."; netMinecraftServerString = "net.minecraft.server." + version + "."; - classNames = ClassScanner.scanFile2(null, Main.class); + try { + classNames = ClassScanner.scanFile2(null, + Class.forName("org.bukkit.craftbukkit.Main")); + } catch(ClassNotFoundException e) { + classNames = Collections.emptySet(); + } } public static boolean classExists(String name) { diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/packet/in/WrappedInUseEntityPacket.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/packet/in/WrappedInUseEntityPacket.java index bf615720..9508e85c 100644 --- a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/packet/in/WrappedInUseEntityPacket.java +++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/tinyprotocol/packet/in/WrappedInUseEntityPacket.java @@ -32,7 +32,7 @@ public class WrappedInUseEntityPacket extends NMSObject { private int id; private EnumEntityUseAction action; private Entity entity; - private Vec3D vec = new Vec3D(-1,-1,-1); + private Vec3D vec; private WrappedEnumHand enumHand = WrappedEnumHand.MAIN_HAND; private boolean sneaking; @@ -52,14 +52,8 @@ public void process(Player player, ProtocolVersion version) { Enum fieldAct = fetch(fieldAction); action = fieldAct == null ? EnumEntityUseAction.INTERACT_AT : EnumEntityUseAction.valueOf(fieldAct.name()); - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { - Object vec = fetch(fieldVec); - if(vec != null) - this.vec = new Vec3D(vec); - - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_9)) { - enumHand = WrappedEnumHand.getFromVanilla(fetch(fieldHand)); - } + if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_9)) { + enumHand = WrappedEnumHand.getFromVanilla(fetch(fieldHand)); } } else { //1.17 specific code Object actionField = fetch(fieldAction); @@ -79,6 +73,13 @@ public void process(Player player, ProtocolVersion version) { if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_16)) { sneaking = fetch(fieldSneaking); } else sneaking = player.isSneaking(); + + if(action == EnumEntityUseAction.INTERACT_AT) { + Object vec = fetch(fieldVec); + if(vec != null) { + this.vec = new Vec3D(vec); + } + } } @Override