+ SimpleAi 首次测试成功!

This commit is contained in:
坏黑 2018-09-20 23:22:58 +08:00
parent cefb8a12a8
commit 591a67688b
10 changed files with 717 additions and 45 deletions

View File

@ -19,7 +19,7 @@ public class AnvilContainerAPI implements Listener {
public AnvilContainerAPI() { public AnvilContainerAPI() {
try { try {
impl = AsmClassLoader.createNewClass("me.skymc.taboolib.anvil.AnvilContainer", AnvilContainerAsm.create(TabooLib.getVersion())); impl = AsmClassLoader.createNewClass("me.skymc.taboolib.anvil.AnvilContainer", AnvilContainerGenerator.generate());
Bukkit.getPluginManager().registerEvents(this, TabooLib.instance()); Bukkit.getPluginManager().registerEvents(this, TabooLib.instance());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -0,0 +1,33 @@
package me.skymc.taboolib.common.pathfinder;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
/**
* @Author sky
* @Since 2018-09-20 20:47
*/
public abstract class PathfinderExecutor {
public abstract Object getEntityInsentient(LivingEntity entity);
public abstract Object getNavigation(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 setTargetAi(LivingEntity entity, Object 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 Object navigationMove(LivingEntity entity, Location location, double speed);
public abstract boolean navigationReach(LivingEntity entity);
}

View File

@ -4,7 +4,7 @@ package me.skymc.taboolib.common.pathfinder;
* @Author sky * @Author sky
* @Since 2018-09-19 19:42 * @Since 2018-09-19 19:42
*/ */
public abstract class SimpleAI { public abstract class SimpleAi {
public abstract boolean shouldExecute(); public abstract boolean shouldExecute();

View File

@ -0,0 +1,36 @@
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.object.Instantiable;
/**
* @Author sky
* @Since 2018-09-19 20:31
*/
@Instantiable("SimpleAISelector")
public class SimpleAiSelector {
private static Class<?> internalPathfinderGoal;
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();
} catch (Exception e) {
e.printStackTrace();
}
}
// *********************************
//
// Getter and Setter
//
// *********************************
public static PathfinderExecutor getExecutor() {
return internalPathfinderExecutor;
}
}

View File

@ -0,0 +1,487 @@
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();
}
}

View File

@ -1,49 +1,51 @@
package me.skymc.taboolib.common.pathfinder.internal; package me.skymc.taboolib.common.pathfinder.generate;
import me.skymc.taboolib.TabooLib;
import org.objectweb.asm.*; import org.objectweb.asm.*;
/** /**
* @author sky * @author idea
*/ */
public class ParentPathfinderGoalAsm { public class PathfinderGoalGenerator {
public static byte[] create(String version) { public static byte[] generate() {
String version = TabooLib.getVersion();
ClassWriter cw = new ClassWriter(0); ClassWriter cw = new ClassWriter(0);
FieldVisitor fv; FieldVisitor fv;
MethodVisitor mv; MethodVisitor mv;
AnnotationVisitor av0; AnnotationVisitor av0;
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", null, "net/minecraft/server/" + version + "/PathfinderGoal", null); 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("ParentPathfinderGoal.java", 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 = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;", null, null);
fv.visitEnd(); fv.visitEnd();
} }
{ {
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lme/skymc/taboolib/common/pathfinder/SimpleAI;)V", null, null); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lme/skymc/taboolib/common/pathfinder/SimpleAi;)V", null, null);
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(13, l0); mv.visitLineNumber(15, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "net/minecraft/server/" + version + "/PathfinderGoal", "<init>", "()V", false); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "net/minecraft/server/" + version + "/PathfinderGoal", "<init>", "()V", false);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLineNumber(14, l1); mv.visitLineNumber(16, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;");
Label l2 = new Label(); Label l2 = new Label();
mv.visitLabel(l2); mv.visitLabel(l2);
mv.visitLineNumber(15, l2); mv.visitLineNumber(17, l2);
mv.visitInsn(Opcodes.RETURN); mv.visitInsn(Opcodes.RETURN);
Label l3 = new Label(); Label l3 = new Label();
mv.visitLabel(l3); mv.visitLabel(l3);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l3, 0); 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.visitLocalVariable("simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAi;", null, l0, l3, 1);
mv.visitMaxs(2, 2); mv.visitMaxs(2, 2);
mv.visitEnd(); mv.visitEnd();
} }
@ -52,14 +54,14 @@ public class ParentPathfinderGoalAsm {
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(19, l0); mv.visitLineNumber(21, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); 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.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "shouldExecute", "()Z", false);
mv.visitInsn(Opcodes.IRETURN); mv.visitInsn(Opcodes.IRETURN);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l1, 0); mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l1, 0);
mv.visitMaxs(1, 1); mv.visitMaxs(1, 1);
mv.visitEnd(); mv.visitEnd();
} }
@ -68,14 +70,14 @@ public class ParentPathfinderGoalAsm {
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(24, l0); mv.visitLineNumber(26, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); 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.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "continueExecute", "()Z", false);
mv.visitInsn(Opcodes.IRETURN); mv.visitInsn(Opcodes.IRETURN);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l1, 0); mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l1, 0);
mv.visitMaxs(1, 1); mv.visitMaxs(1, 1);
mv.visitEnd(); mv.visitEnd();
} }
@ -84,17 +86,17 @@ public class ParentPathfinderGoalAsm {
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(29, l0); mv.visitLineNumber(31, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); 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); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "startTask", "()V", false);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLineNumber(30, l1); mv.visitLineNumber(32, l1);
mv.visitInsn(Opcodes.RETURN); mv.visitInsn(Opcodes.RETURN);
Label l2 = new Label(); Label l2 = new Label();
mv.visitLabel(l2); mv.visitLabel(l2);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0); mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
mv.visitMaxs(1, 1); mv.visitMaxs(1, 1);
mv.visitEnd(); mv.visitEnd();
} }
@ -103,17 +105,17 @@ public class ParentPathfinderGoalAsm {
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(34, l0); mv.visitLineNumber(36, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); 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); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "resetTask", "()V", false);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLineNumber(35, l1); mv.visitLineNumber(37, l1);
mv.visitInsn(Opcodes.RETURN); mv.visitInsn(Opcodes.RETURN);
Label l2 = new Label(); Label l2 = new Label();
mv.visitLabel(l2); mv.visitLabel(l2);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0); mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
mv.visitMaxs(1, 1); mv.visitMaxs(1, 1);
mv.visitEnd(); mv.visitEnd();
} }
@ -122,17 +124,17 @@ public class ParentPathfinderGoalAsm {
mv.visitCode(); mv.visitCode();
Label l0 = new Label(); Label l0 = new Label();
mv.visitLabel(l0); mv.visitLabel(l0);
mv.visitLineNumber(39, l0); mv.visitLineNumber(41, l0);
mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;"); 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); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAi", "updateTask", "()V", false);
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitLineNumber(40, l1); mv.visitLineNumber(42, l1);
mv.visitInsn(Opcodes.RETURN); mv.visitInsn(Opcodes.RETURN);
Label l2 = new Label(); Label l2 = new Label();
mv.visitLabel(l2); mv.visitLabel(l2);
mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0); mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/InternalPathfinderGoal;", null, l0, l2, 0);
mv.visitMaxs(1, 1); mv.visitMaxs(1, 1);
mv.visitEnd(); mv.visitEnd();
} }

View File

@ -0,0 +1,112 @@
package me.skymc.taboolib.common.pathfinder.internal;
import me.skymc.taboolib.common.pathfinder.PathfinderExecutor;
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.LivingEntity;
import java.lang.reflect.Field;
import java.util.Set;
/**
* 该类仅用作生成 ASM 代码无任何意义
*
* @Author sky
* @Since 2018-09-20 20:57
*/
public class InternalPathfinderExecutor extends PathfinderExecutor {
private Field pathEntity;
private Field pathfinderGoalSelectorSet;
public InternalPathfinderExecutor() {
try {
pathfinderGoalSelectorSet = PathfinderGoalSelector.class.getDeclaredField("b");
pathfinderGoalSelectorSet.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
for (Field field : NavigationAbstract.class.getDeclaredFields()) {
if (field.getType().equals(PathEntity.class)) {
field.setAccessible(true);
pathEntity = field;
return;
}
}
}
@Override
public Object getEntityInsentient(LivingEntity entity) {
return ((CraftEntity) entity).getHandle();
}
@Override
public Object getNavigation(LivingEntity entity) {
return ((EntityInsentient) getEntityInsentient(entity)).getNavigation();
}
@Override
public Object getGoalSelector(LivingEntity entity) {
return ((EntityInsentient) getEntityInsentient(entity)).goalSelector;
}
@Override
public Object getTargetSelector(LivingEntity entity) {
return ((EntityInsentient) getEntityInsentient(entity)).targetSelector;
}
@Override
public void setGoalAi(LivingEntity entity, Object ai, int priority) {
((EntityInsentient) getEntityInsentient(entity)).goalSelector.a(priority, (PathfinderGoal) ai);
}
@Override
public void setTargetAi(LivingEntity entity, Object ai, int priority) {
((EntityInsentient) getEntityInsentient(entity)).targetSelector.a(priority, (PathfinderGoal) ai);
}
@Override
public void clearGoalAi(LivingEntity entity) {
try {
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void clearTargetAi(LivingEntity entity) {
try {
((Set) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public Object 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) {
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();
}
private PathEntity getPathEntity(LivingEntity entity) {
try {
return (PathEntity) pathEntity.get(getNavigation(entity));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -1,16 +1,18 @@
package me.skymc.taboolib.common.pathfinder.internal; package me.skymc.taboolib.common.pathfinder.internal;
import me.skymc.taboolib.common.pathfinder.SimpleAI; import me.skymc.taboolib.common.pathfinder.SimpleAi;
/** /**
* 该类仅用作生成 ASM 代码无任何意义
*
* @Author sky * @Author sky
* @Since 2018-09-19 22:31 * @Since 2018-09-19 22:31
*/ */
public class ParentPathfinderGoal extends net.minecraft.server.v1_12_R1.PathfinderGoal { public class InternalPathfinderGoal extends net.minecraft.server.v1_12_R1.PathfinderGoal {
private final SimpleAI simpleAI; private final SimpleAi simpleAI;
public ParentPathfinderGoal(SimpleAI simpleAI) { public InternalPathfinderGoal(SimpleAi simpleAI) {
this.simpleAI = simpleAI; this.simpleAI = simpleAI;
} }

View File

@ -8,7 +8,7 @@ import org.objectweb.asm.Opcodes;
import java.util.stream.IntStream; import java.util.stream.IntStream;
/** /**
* 我不信 ClassNotFound 的邪自己写了一个发现还是一样 * 我不信 ClassNotFoundException 的邪自己写了一个发现还是一样
* *
* @Author sky * @Author sky
* @Since 2018-09-19 21:17 * @Since 2018-09-19 21:17

View File

@ -52,7 +52,7 @@ public class SimpleVersionControl {
} }
public Class<?> translate() throws IOException { public Class<?> translate() throws IOException {
ClassReader classReader = new ClassReader(target); ClassReader classReader = new ClassReader("/" + target);
ClassWriter classWriter = new ClassWriter(0); ClassWriter classWriter = new ClassWriter(0);
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter); ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
classReader.accept(classVisitor, 0); classReader.accept(classVisitor, 0);