+ 版本控制测试完成,虽然有一些BUG但是可以抛弃Generator了!
+ SimpleAi 二次测试成功!
This commit is contained in:
parent
e0a1e63435
commit
517b8708ce
@ -20,7 +20,7 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
|
||||
private String prevName;
|
||||
|
||||
private AsmClassTransformer(Class<?> from, String fromVer, String toVer, ClassWriter classWriter) {
|
||||
super(Opcodes.ASM6, classWriter);
|
||||
super(Opcodes.ASM5, classWriter);
|
||||
this.writer = classWriter;
|
||||
this.from = from;
|
||||
this.fromVer = fromVer;
|
||||
@ -100,7 +100,7 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
|
||||
private class AsmMethodTransformer extends MethodVisitor {
|
||||
|
||||
AsmMethodTransformer(MethodVisitor visitor) {
|
||||
super(Opcodes.ASM6, visitor);
|
||||
super(Opcodes.ASM5, visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,7 +76,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (methods.size() + fields.size() > 0) {
|
||||
if (methods.size() + fields.size() > 0 && !TabooLib.isTabooLib(baseMainCommand.getRegisterCommand().getPlugin())) {
|
||||
TLocale.Logger.info("COMMANDS.INTERNAL.COMMAND-REGISTER", baseMainCommand.getRegisterCommand().getPlugin().getName(), baseMainCommand.getRegisterCommand().getName(), String.valueOf(methods.size() + fields.size()));
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,9 @@ public class TCommandHandler implements Listener {
|
||||
ReflectionUtils.setValue(pluginCommand, pluginCommand.getClass().getSuperclass(), true, "permission", permission);
|
||||
ReflectionUtils.setValue(pluginCommand, pluginCommand.getClass().getSuperclass(), true, "permissionMessage", permissionMessage);
|
||||
commandMap.register(command, pluginCommand);
|
||||
if (!TabooLib.isTabooLib(plugin)) {
|
||||
TLocale.Logger.info("COMMANDS.INTERNAL.COMMAND-CREATE", plugin.getName(), command);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
TLocale.Logger.info("COMMANDS.INTERNAL.COMMAND-CREATE-FAILED", plugin.getName(), command, e.getMessage());
|
||||
|
@ -0,0 +1,11 @@
|
||||
package me.skymc.taboolib.common.pathfinder;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-09-21 13:06
|
||||
*/
|
||||
public interface PathfinderCreator {
|
||||
|
||||
Object createPathfinderGoal(SimpleAi ai);
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package me.skymc.taboolib.common.pathfinder;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
/**
|
||||
@ -13,21 +14,37 @@ public abstract class PathfinderExecutor {
|
||||
|
||||
public abstract Object getNavigation(LivingEntity entity);
|
||||
|
||||
public abstract Object getPathEntity(LivingEntity entity);
|
||||
|
||||
public abstract Object getControllerJump(LivingEntity entity);
|
||||
|
||||
public abstract Object getControllerMove(LivingEntity entity);
|
||||
|
||||
public abstract Object getControllerLook(LivingEntity entity);
|
||||
|
||||
public abstract Object getGoalSelector(LivingEntity entity);
|
||||
|
||||
public abstract Object getTargetSelector(LivingEntity entity);
|
||||
|
||||
public abstract void setGoalAi(LivingEntity entity, Object ai, int priority);
|
||||
public abstract void setGoalAi(LivingEntity entity, SimpleAi ai, int priority);
|
||||
|
||||
public abstract void setTargetAi(LivingEntity entity, Object ai, int priority);
|
||||
public abstract void setTargetAi(LivingEntity entity, SimpleAi ai, int priority);
|
||||
|
||||
public abstract void clearGoalAi(LivingEntity entity);
|
||||
|
||||
public abstract void clearTargetAi(LivingEntity entity);
|
||||
|
||||
public abstract Object navigationMove(LivingEntity entity, Location location);
|
||||
public abstract boolean navigationMove(LivingEntity entity, Location location);
|
||||
|
||||
public abstract Object navigationMove(LivingEntity entity, Location location, double speed);
|
||||
public abstract boolean navigationMove(LivingEntity entity, Location location, double speed);
|
||||
|
||||
public abstract boolean navigationReach(LivingEntity entity);
|
||||
|
||||
public abstract void controllerLookAt(LivingEntity entity, Location target);
|
||||
|
||||
public abstract void controllerLookAt(LivingEntity entity, Entity target);
|
||||
|
||||
public abstract void controllerJumpReady(LivingEntity entity);
|
||||
|
||||
public abstract boolean controllerJumpCurrent(LivingEntity entity);
|
||||
}
|
||||
|
@ -1,24 +1,30 @@
|
||||
package me.skymc.taboolib.common.pathfinder;
|
||||
|
||||
import com.ilummc.tlib.util.asm.AsmClassLoader;
|
||||
import me.skymc.taboolib.common.pathfinder.generate.PathfinderExecutorGenerator;
|
||||
import me.skymc.taboolib.common.pathfinder.generate.PathfinderGoalGenerator;
|
||||
import me.skymc.taboolib.common.versioncontrol.SimpleVersionControl;
|
||||
import me.skymc.taboolib.object.Instantiable;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-09-19 20:31
|
||||
*/
|
||||
@Instantiable("SimpleAISelector")
|
||||
@Instantiable("SimpleAiSelector")
|
||||
public class SimpleAiSelector {
|
||||
|
||||
private static Class<?> internalPathfinderGoal;
|
||||
private static PathfinderCreator internalPathfinderCreator;
|
||||
private static PathfinderExecutor internalPathfinderExecutor;
|
||||
|
||||
public SimpleAiSelector() {
|
||||
try {
|
||||
internalPathfinderGoal = AsmClassLoader.createNewClass("me.skymc.taboolib.common.pathfinder.internal.InternalPathfinderGoal", PathfinderGoalGenerator.generate());
|
||||
internalPathfinderExecutor = (PathfinderExecutor) AsmClassLoader.createNewClass("me.skymc.taboolib.common.pathfinder.internal.InternalPathfinderExecutor", PathfinderExecutorGenerator.generate()).newInstance();
|
||||
internalPathfinderCreator = (PathfinderCreator) SimpleVersionControl.create()
|
||||
.from("1_8_R3")
|
||||
.target("me.skymc.taboolib.common.pathfinder.internal.InternalPathfinderCreator")
|
||||
.translate()
|
||||
.newInstance();
|
||||
internalPathfinderExecutor = (PathfinderExecutor) SimpleVersionControl.create()
|
||||
.from("1_8_R3")
|
||||
.target("me.skymc.taboolib.common.pathfinder.internal.InternalPathfinderExecutor")
|
||||
.translate()
|
||||
.newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -33,4 +39,8 @@ public class SimpleAiSelector {
|
||||
public static PathfinderExecutor getExecutor() {
|
||||
return internalPathfinderExecutor;
|
||||
}
|
||||
|
||||
public static PathfinderCreator getCreator() {
|
||||
return internalPathfinderCreator;
|
||||
}
|
||||
}
|
||||
|
@ -1,487 +0,0 @@
|
||||
package me.skymc.taboolib.common.pathfinder.generate;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
/**
|
||||
* @author idea
|
||||
*/
|
||||
public class PathfinderExecutorGenerator {
|
||||
|
||||
public static byte[] generate() {
|
||||
String version = TabooLib.getVersion();
|
||||
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
FieldVisitor fv;
|
||||
MethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
|
||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", null, "me/skymc/taboolib/common/pathfinder/PathfinderExecutor", null);
|
||||
|
||||
cw.visitSource("InternalPathfinderExecutor.java", null);
|
||||
|
||||
{
|
||||
fv = cw.visitField(Opcodes.ACC_PRIVATE, "pathEntity", "Ljava/lang/reflect/Field;", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{
|
||||
fv = cw.visitField(Opcodes.ACC_PRIVATE, "pathfinderGoalSelectorSet", "Ljava/lang/reflect/Field;", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
Label l2 = new Label();
|
||||
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
|
||||
Label l3 = new Label();
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLineNumber(24, l3);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "me/skymc/taboolib/common/pathfinder/PathfinderExecutor", "<init>", "()V", false);
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(26, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitLdcInsn(Type.getType("Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;"));
|
||||
mv.visitLdcInsn("b");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;", false);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathfinderGoalSelectorSet", "Ljava/lang/reflect/Field;");
|
||||
Label l4 = new Label();
|
||||
mv.visitLabel(l4);
|
||||
mv.visitLineNumber(27, l4);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathfinderGoalSelectorSet", "Ljava/lang/reflect/Field;");
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "setAccessible", "(Z)V", false);
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(30, l1);
|
||||
Label l5 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.GOTO, l5);
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLineNumber(28, l2);
|
||||
mv.visitFrame(Opcodes.F_FULL, 1, new Object[] {"me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor"}, 1, new Object[] {"java/lang/Exception"});
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 1);
|
||||
Label l6 = new Label();
|
||||
mv.visitLabel(l6);
|
||||
mv.visitLineNumber(29, l6);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
|
||||
mv.visitLabel(l5);
|
||||
mv.visitLineNumber(31, l5);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
mv.visitLdcInsn(Type.getType("Lnet/minecraft/server/" + version + "/NavigationAbstract;"));
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getDeclaredFields", "()[Ljava/lang/reflect/Field;", false);
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 1);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitInsn(Opcodes.ARRAYLENGTH);
|
||||
mv.visitVarInsn(Opcodes.ISTORE, 2);
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
mv.visitVarInsn(Opcodes.ISTORE, 3);
|
||||
Label l7 = new Label();
|
||||
mv.visitLabel(l7);
|
||||
mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] {"[Ljava/lang/reflect/Field;", Opcodes.INTEGER, Opcodes.INTEGER}, 0, null);
|
||||
mv.visitVarInsn(Opcodes.ILOAD, 3);
|
||||
mv.visitVarInsn(Opcodes.ILOAD, 2);
|
||||
Label l8 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.IF_ICMPGE, l8);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitVarInsn(Opcodes.ILOAD, 3);
|
||||
mv.visitInsn(Opcodes.AALOAD);
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 4);
|
||||
Label l9 = new Label();
|
||||
mv.visitLabel(l9);
|
||||
mv.visitLineNumber(32, l9);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 4);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getType", "()Ljava/lang/Class;", false);
|
||||
mv.visitLdcInsn(Type.getType("Lnet/minecraft/server/" + version + "/PathEntity;"));
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
|
||||
Label l10 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, l10);
|
||||
Label l11 = new Label();
|
||||
mv.visitLabel(l11);
|
||||
mv.visitLineNumber(33, l11);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 4);
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "setAccessible", "(Z)V", false);
|
||||
Label l12 = new Label();
|
||||
mv.visitLabel(l12);
|
||||
mv.visitLineNumber(34, l12);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 4);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathEntity", "Ljava/lang/reflect/Field;");
|
||||
Label l13 = new Label();
|
||||
mv.visitLabel(l13);
|
||||
mv.visitLineNumber(35, l13);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
mv.visitLabel(l10);
|
||||
mv.visitLineNumber(31, l10);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
mv.visitIincInsn(3, 1);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, l7);
|
||||
mv.visitLabel(l8);
|
||||
mv.visitLineNumber(38, l8);
|
||||
mv.visitFrame(Opcodes.F_CHOP, 3, null, 0, null);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l14 = new Label();
|
||||
mv.visitLabel(l14);
|
||||
mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l6, l5, 1);
|
||||
mv.visitLocalVariable("field", "Ljava/lang/reflect/Field;", null, l9, l10, 4);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l3, l14, 0);
|
||||
mv.visitMaxs(3, 5);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(42, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "org/bukkit/craftbukkit/" + version + "/entity/CraftEntity");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/bukkit/craftbukkit/" + version + "/entity/CraftEntity", "getHandle", "()Lnet/minecraft/server/" + version + "/Entity;", false);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitMaxs(1, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getNavigation", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(47, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/server/" + version + "/EntityInsentient", "getNavigation", "()Lnet/minecraft/server/" + version + "/NavigationAbstract;", false);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getGoalSelector", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(52, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "goalSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getTargetSelector", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(57, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "targetSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setGoalAi", "(Lorg/bukkit/entity/LivingEntity;Ljava/lang/Object;I)V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(62, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "goalSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitVarInsn(Opcodes.ILOAD, 3);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/PathfinderGoal");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/server/" + version + "/PathfinderGoalSelector", "a", "(ILnet/minecraft/server/" + version + "/PathfinderGoal;)V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(63, l1);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l2, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l2, 1);
|
||||
mv.visitLocalVariable("ai", "Ljava/lang/Object;", null, l0, l2, 2);
|
||||
mv.visitLocalVariable("priority", "I", null, l0, l2, 3);
|
||||
mv.visitMaxs(3, 4);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setTargetAi", "(Lorg/bukkit/entity/LivingEntity;Ljava/lang/Object;I)V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(67, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "targetSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitVarInsn(Opcodes.ILOAD, 3);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/PathfinderGoal");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/server/" + version + "/PathfinderGoalSelector", "a", "(ILnet/minecraft/server/" + version + "/PathfinderGoal;)V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(68, l1);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l2, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l2, 1);
|
||||
mv.visitLocalVariable("ai", "Ljava/lang/Object;", null, l0, l2, 2);
|
||||
mv.visitLocalVariable("priority", "I", null, l0, l2, 3);
|
||||
mv.visitMaxs(3, 4);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "clearGoalAi", "(Lorg/bukkit/entity/LivingEntity;)V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
Label l2 = new Label();
|
||||
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(73, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathfinderGoalSelectorSet", "Ljava/lang/reflect/Field;");
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "goalSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Set");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Set", "clear", "()V", true);
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(76, l1);
|
||||
Label l3 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.GOTO, l3);
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLineNumber(74, l2);
|
||||
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Exception"});
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 2);
|
||||
Label l4 = new Label();
|
||||
mv.visitLabel(l4);
|
||||
mv.visitLineNumber(75, l4);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLineNumber(77, l3);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l5 = new Label();
|
||||
mv.visitLabel(l5);
|
||||
mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l4, l3, 2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l5, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l5, 1);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "clearTargetAi", "(Lorg/bukkit/entity/LivingEntity;)V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
Label l2 = new Label();
|
||||
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(82, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathfinderGoalSelectorSet", "Ljava/lang/reflect/Field;");
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getEntityInsentient", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/EntityInsentient");
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/server/" + version + "/EntityInsentient", "targetSelector", "Lnet/minecraft/server/" + version + "/PathfinderGoalSelector;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Set");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Set", "clear", "()V", true);
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(85, l1);
|
||||
Label l3 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.GOTO, l3);
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLineNumber(83, l2);
|
||||
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Exception"});
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 2);
|
||||
Label l4 = new Label();
|
||||
mv.visitLabel(l4);
|
||||
mv.visitLineNumber(84, l4);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLineNumber(86, l3);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l5 = new Label();
|
||||
mv.visitLabel(l5);
|
||||
mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l4, l3, 2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l5, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l5, 1);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "navigationMove", "(Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/Location;)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(90, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitFieldInsn(Opcodes.GETSTATIC, "org/bukkit/attribute/Attribute", "GENERIC_MOVEMENT_SPEED", "Lorg/bukkit/attribute/Attribute;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/bukkit/entity/LivingEntity", "getAttribute", "(Lorg/bukkit/attribute/Attribute;)Lorg/bukkit/attribute/AttributeInstance;", true);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/bukkit/attribute/AttributeInstance", "getValue", "()D", true);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "navigationMove", "(Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/Location;D)Ljava/lang/Object;", false);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitLocalVariable("location", "Lorg/bukkit/Location;", null, l0, l1, 2);
|
||||
mv.visitMaxs(5, 3);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "navigationMove", "(Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/Location;D)Ljava/lang/Object;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(95, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getNavigation", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/Navigation");
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/bukkit/Location", "getX", "()D", false);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/bukkit/Location", "getY", "()D", false);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/bukkit/Location", "getZ", "()D", false);
|
||||
mv.visitVarInsn(Opcodes.DLOAD, 3);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/server/" + version + "/Navigation", "a", "(DDDD)Z", false);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l1, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l1, 1);
|
||||
mv.visitLocalVariable("location", "Lorg/bukkit/Location;", null, l0, l1, 2);
|
||||
mv.visitLocalVariable("speed", "D", null, l0, l1, 3);
|
||||
mv.visitMaxs(9, 5);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "navigationReach", "(Lorg/bukkit/entity/LivingEntity;)Z", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(100, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getPathEntity", "(Lorg/bukkit/entity/LivingEntity;)Lnet/minecraft/server/" + version + "/PathEntity;", false);
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 2);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(101, l1);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
Label l2 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.IFNULL, l2);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/server/" + version + "/PathEntity", "b", "()Z", false);
|
||||
Label l3 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, l3);
|
||||
mv.visitLabel(l2);
|
||||
mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] {"net/minecraft/server/" + version + "/PathEntity"}, 0, null);
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
Label l4 = new Label();
|
||||
mv.visitJumpInsn(Opcodes.GOTO, l4);
|
||||
mv.visitLabel(l3);
|
||||
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
mv.visitLabel(l4);
|
||||
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {Opcodes.INTEGER});
|
||||
mv.visitInsn(Opcodes.IRETURN);
|
||||
Label l5 = new Label();
|
||||
mv.visitLabel(l5);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l5, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l5, 1);
|
||||
mv.visitLocalVariable("pathEntity", "Lnet/minecraft/server/" + version + "/PathEntity;", null, l1, l5, 2);
|
||||
mv.visitMaxs(2, 3);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PRIVATE, "getPathEntity", "(Lorg/bukkit/entity/LivingEntity;)Lnet/minecraft/server/" + version + "/PathEntity;", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
Label l1 = new Label();
|
||||
Label l2 = new Label();
|
||||
mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(106, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "pathEntity", "Ljava/lang/reflect/Field;");
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor", "getNavigation", "(Lorg/bukkit/entity/LivingEntity;)Ljava/lang/Object;", false);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, "net/minecraft/server/" + version + "/PathEntity");
|
||||
mv.visitLabel(l1);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLineNumber(107, l2);
|
||||
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Exception"});
|
||||
mv.visitVarInsn(Opcodes.ASTORE, 2);
|
||||
Label l3 = new Label();
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLineNumber(108, l3);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
|
||||
Label l4 = new Label();
|
||||
mv.visitLabel(l4);
|
||||
mv.visitLineNumber(110, l4);
|
||||
mv.visitInsn(Opcodes.ACONST_NULL);
|
||||
mv.visitInsn(Opcodes.ARETURN);
|
||||
Label l5 = new Label();
|
||||
mv.visitLabel(l5);
|
||||
mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l3, l4, 2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderExecutor;", null, l0, l5, 0);
|
||||
mv.visitLocalVariable("entity", "Lorg/bukkit/entity/LivingEntity;", null, l0, l5, 1);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
package me.skymc.taboolib.common.pathfinder.generate;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
/**
|
||||
* @author idea
|
||||
*/
|
||||
public class PathfinderGoalGenerator {
|
||||
|
||||
public static byte[] generate() {
|
||||
String version = TabooLib.getVersion();
|
||||
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
FieldVisitor fv;
|
||||
MethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
|
||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", null, "net/minecraft/server/" + version + "/PathfinderGoal", null);
|
||||
|
||||
cw.visitSource("InternalPathfinderGoal.java", null);
|
||||
|
||||
{
|
||||
fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lme/skymc/taboolib/common/pathfinder/SimpleAi;)V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(15, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "net/minecraft/server/" + version + "/PathfinderGoal", "<init>", "()V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(16, l1);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLineNumber(17, l2);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l3 = new Label();
|
||||
mv.visitLabel(l3);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l3, 0);
|
||||
mv.visitLocalVariable("simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;", null, l0, l3, 1);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "a", "()Z", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(21, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "shouldExecute", "()Z", false);
|
||||
mv.visitInsn(Opcodes.IRETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l1, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "b", "()Z", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(26, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "continueExecute", "()Z", false);
|
||||
mv.visitInsn(Opcodes.IRETURN);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l1, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "c", "()V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(31, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "startTask", "()V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(32, l1);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "d", "()V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(36, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "resetTask", "()V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(37, l1);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "e", "()V", null, null);
|
||||
mv.visitCode();
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
mv.visitLineNumber(41, l0);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "updateTask", "()V", false);
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitLineNumber(42, l1);
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
Label l2 = new Label();
|
||||
mv.visitLabel(l2);
|
||||
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package me.skymc.taboolib.common.pathfinder.internal;
|
||||
|
||||
import me.skymc.taboolib.common.pathfinder.PathfinderCreator;
|
||||
import me.skymc.taboolib.common.pathfinder.SimpleAi;
|
||||
|
||||
/**
|
||||
@ -8,12 +9,20 @@ import me.skymc.taboolib.common.pathfinder.SimpleAi;
|
||||
* @Author sky
|
||||
* @Since 2018-09-19 22:31
|
||||
*/
|
||||
public class InternalPathfinderGoal extends net.minecraft.server.v1_12_R1.PathfinderGoal {
|
||||
public class InternalPathfinderCreator extends net.minecraft.server.v1_8_R3.PathfinderGoal implements PathfinderCreator {
|
||||
|
||||
private final SimpleAi simpleAI;
|
||||
private SimpleAi simpleAI;
|
||||
|
||||
public InternalPathfinderGoal(SimpleAi simpleAI) {
|
||||
this.simpleAI = simpleAI;
|
||||
public InternalPathfinderCreator() {
|
||||
}
|
||||
|
||||
public InternalPathfinderCreator(SimpleAi ai) {
|
||||
this.simpleAI = ai;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object createPathfinderGoal(SimpleAi ai) {
|
||||
return new InternalPathfinderCreator(ai);
|
||||
}
|
||||
|
||||
@Override
|
@ -1,10 +1,14 @@
|
||||
package me.skymc.taboolib.common.pathfinder.internal;
|
||||
|
||||
import me.skymc.taboolib.common.pathfinder.PathfinderExecutor;
|
||||
import me.skymc.taboolib.common.pathfinder.SimpleAi;
|
||||
import me.skymc.taboolib.common.pathfinder.SimpleAiSelector;
|
||||
import me.skymc.taboolib.nms.NMSUtils;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -20,21 +24,29 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
|
||||
private Field pathEntity;
|
||||
private Field pathfinderGoalSelectorSet;
|
||||
private Field controllerJumpCurrent;
|
||||
|
||||
public InternalPathfinderExecutor() {
|
||||
try {
|
||||
pathfinderGoalSelectorSet = PathfinderGoalSelector.class.getDeclaredField("b");
|
||||
pathfinderGoalSelectorSet = NMSUtils.getNMSClass("PathfinderGoalSelector").getDeclaredField("b");
|
||||
pathfinderGoalSelectorSet.setAccessible(true);
|
||||
controllerJumpCurrent = NMSUtils.getNMSClass("ControllerJump").getDeclaredField("a");
|
||||
controllerJumpCurrent.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Field field : NavigationAbstract.class.getDeclaredFields()) {
|
||||
if (field.getType().equals(PathEntity.class)) {
|
||||
try {
|
||||
Class<?> pathEntityClass = NMSUtils.getNMSClass("PathEntity");
|
||||
for (Field field : NMSUtils.getNMSClass("NavigationAbstract").getDeclaredFields()) {
|
||||
if (field.getType().equals(pathEntityClass)) {
|
||||
field.setAccessible(true);
|
||||
pathEntity = field;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,6 +59,31 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
return ((EntityInsentient) getEntityInsentient(entity)).getNavigation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPathEntity(LivingEntity entity) {
|
||||
try {
|
||||
return pathEntity.get(getNavigation(entity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getControllerJump(LivingEntity entity) {
|
||||
return ((EntityInsentient) getEntityInsentient(entity)).getControllerJump();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getControllerMove(LivingEntity entity) {
|
||||
return ((EntityInsentient) getEntityInsentient(entity)).getControllerMove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getControllerLook(LivingEntity entity) {
|
||||
return ((EntityInsentient) getEntityInsentient(entity)).getControllerLook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGoalSelector(LivingEntity entity) {
|
||||
return ((EntityInsentient) getEntityInsentient(entity)).goalSelector;
|
||||
@ -58,13 +95,13 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGoalAi(LivingEntity entity, Object ai, int priority) {
|
||||
((EntityInsentient) getEntityInsentient(entity)).goalSelector.a(priority, (PathfinderGoal) ai);
|
||||
public void setGoalAi(LivingEntity entity, SimpleAi ai, int priority) {
|
||||
((EntityInsentient) getEntityInsentient(entity)).goalSelector.a(priority, (PathfinderGoal) SimpleAiSelector.getCreator().createPathfinderGoal(ai));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTargetAi(LivingEntity entity, Object ai, int priority) {
|
||||
((EntityInsentient) getEntityInsentient(entity)).targetSelector.a(priority, (PathfinderGoal) ai);
|
||||
public void setTargetAi(LivingEntity entity, SimpleAi ai, int priority) {
|
||||
((EntityInsentient) getEntityInsentient(entity)).targetSelector.a(priority, (PathfinderGoal) SimpleAiSelector.getCreator().createPathfinderGoal(ai));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,27 +123,42 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object navigationMove(LivingEntity entity, Location location) {
|
||||
public boolean navigationMove(LivingEntity entity, Location location) {
|
||||
return navigationMove(entity, location, entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getBaseValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object navigationMove(LivingEntity entity, Location location, double speed) {
|
||||
public boolean navigationMove(LivingEntity entity, Location location, double speed) {
|
||||
return ((Navigation) getNavigation(entity)).a(location.getX(), location.getY(), location.getZ(), speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean navigationReach(LivingEntity entity) {
|
||||
PathEntity pathEntity = getPathEntity(entity);
|
||||
return pathEntity == null || pathEntity.b();
|
||||
Object pathEntity = getPathEntity(entity);
|
||||
return pathEntity == null || ((PathEntity) pathEntity).b();
|
||||
}
|
||||
|
||||
private PathEntity getPathEntity(LivingEntity entity) {
|
||||
try {
|
||||
return (PathEntity) pathEntity.get(getNavigation(entity));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@Override
|
||||
public void controllerLookAt(LivingEntity entity, Location target) {
|
||||
((ControllerLook) getControllerLook(entity)).a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void controllerLookAt(LivingEntity entity, Entity target) {
|
||||
((ControllerLook) getControllerLook(entity)).a((net.minecraft.server.v1_8_R3.Entity) target, 10, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void controllerJumpReady(LivingEntity entity) {
|
||||
((ControllerJump) getControllerJump(entity)).a();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean controllerJumpCurrent(LivingEntity entity) {
|
||||
try {
|
||||
return controllerJumpCurrent.getBoolean(getControllerJump(entity));
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.skymc.taboolib.common.playercontanier;
|
||||
package me.skymc.taboolib.common.playercontainer;
|
||||
|
||||
/**
|
||||
* @author sky
|
@ -1,4 +1,4 @@
|
||||
package me.skymc.taboolib.common.playercontanier;
|
||||
package me.skymc.taboolib.common.playercontainer;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
||||
package me.skymc.taboolib.common.playercontanier;
|
||||
package me.skymc.taboolib.common.playercontainer;
|
||||
|
||||
import com.ilummc.tlib.logger.TLogger;
|
||||
import me.skymc.taboolib.TabooLib;
|
@ -18,7 +18,7 @@ public class SimpleClassVisitor extends ClassVisitor {
|
||||
private final SimpleVersionControl simpleVersionControl;
|
||||
|
||||
public SimpleClassVisitor(SimpleVersionControl simpleVersionControl, ClassVisitor classVisitor) {
|
||||
super(Opcodes.ASM6, classVisitor);
|
||||
super(Opcodes.ASM5, classVisitor);
|
||||
this.simpleVersionControl = simpleVersionControl;
|
||||
}
|
||||
|
||||
@ -27,6 +27,11 @@ public class SimpleClassVisitor extends ClassVisitor {
|
||||
super.visit(version, access, name, signature, translate(superName), translate(interfaces));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(String name, String outerName, String innerName, int access) {
|
||||
super.visitInnerClass(name, translate(outerName), translate(innerName), access);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
||||
return super.visitField(access, name, translate(descriptor), translate(signature), value);
|
||||
|
@ -17,7 +17,7 @@ public class SimpleMethodVisitor extends MethodVisitor {
|
||||
private final SimpleVersionControl simpleVersionControl;
|
||||
|
||||
public SimpleMethodVisitor(SimpleVersionControl simpleVersionControl, MethodVisitor methodVisitor) {
|
||||
super(Opcodes.ASM6, methodVisitor);
|
||||
super(Opcodes.ASM5, methodVisitor);
|
||||
this.simpleVersionControl = simpleVersionControl;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
package me.skymc.taboolib.common.versioncontrol;
|
||||
|
||||
import com.ilummc.tlib.util.asm.AsmClassLoader;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
@ -19,16 +22,17 @@ public class SimpleVersionControl {
|
||||
private String target;
|
||||
private String from;
|
||||
private String to;
|
||||
private Plugin plugin;
|
||||
|
||||
SimpleVersionControl() {
|
||||
}
|
||||
|
||||
public static SimpleVersionControl create() {
|
||||
return new SimpleVersionControl().to(TabooLib.getVersion());
|
||||
return new SimpleVersionControl().to(TabooLib.getVersion()).plugin(Main.getInst());
|
||||
}
|
||||
|
||||
public static SimpleVersionControl create(String toVersion) {
|
||||
return new SimpleVersionControl().to(toVersion);
|
||||
return new SimpleVersionControl().to(toVersion).plugin(Main.getInst());
|
||||
}
|
||||
|
||||
public SimpleVersionControl target(Class<?> target) {
|
||||
@ -51,11 +55,18 @@ public class SimpleVersionControl {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleVersionControl plugin(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Class<?> translate() throws IOException {
|
||||
ClassReader classReader = new ClassReader("/" + target);
|
||||
ClassReader classReader = new ClassReader(FileUtils.getResource(plugin, target.replace(".", "/") + ".class"));
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
|
||||
classReader.accept(classVisitor, 0);
|
||||
classWriter.visitEnd();
|
||||
classVisitor.visitEnd();
|
||||
return AsmClassLoader.createNewClass(target, classWriter.toByteArray());
|
||||
}
|
||||
|
||||
|
@ -133,13 +133,9 @@ public class FileUtils {
|
||||
public static InputStream getResource(Plugin plugin, String filename) {
|
||||
try {
|
||||
URL url = plugin.getClass().getClassLoader().getResource(filename);
|
||||
if (url == null) {
|
||||
return null;
|
||||
} else {
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setUseCaches(false);
|
||||
return connection.getInputStream();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user