Skip to content

Commit

Permalink
Fixing vector on useentity
Browse files Browse the repository at this point in the history
  • Loading branch information
funkemunky committed Feb 25, 2022
1 parent 5a900b6 commit b178126
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit b178126

Please sign in to comment.