Fix #61
This commit is contained in:
parent
d056ce8753
commit
556a501f75
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes_v1_14_R1</artifactId>
|
||||
|
@ -41,15 +41,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.server.v1_14_R1.EntityFox;
|
|||
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_14_R1 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(EntityFox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("aZ"); // aZ = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityTypes.FOX, (EntityTypes.b<EntityFox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes_v1_15_R1</artifactId>
|
||||
|
@ -41,15 +41,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.server.v1_15_R1.EntityFox;
|
|||
import net.minecraft.server.v1_15_R1.EntityTypes;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_15_R1 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(EntityFox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("ba"); // ba = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityTypes.FOX, (EntityTypes.b<EntityFox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes_v1_16_R1</artifactId>
|
||||
|
@ -41,15 +41,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.server.v1_16_R1.EntityFox;
|
|||
import net.minecraft.server.v1_16_R1.EntityTypes;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_16_R1 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(EntityFox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("be"); // be = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityTypes.FOX, (EntityTypes.b<EntityFox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes_v1_16_R2</artifactId>
|
||||
|
@ -41,15 +41,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.server.v1_16_R2.EntityFox;
|
|||
import net.minecraft.server.v1_16_R2.EntityTypes;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_16_R2 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(EntityFox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); // bm = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); // bf = factory
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityTypes.FOX, (EntityTypes.b<EntityFox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes_v1_16_R3</artifactId>
|
||||
|
@ -41,15 +41,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.server.v1_16_R3.EntityFox;
|
|||
import net.minecraft.server.v1_16_R3.EntityTypes;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_16_R3 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(EntityFox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); // bm = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); // bf = factory
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityTypes.FOX, (EntityTypes.b<EntityFox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
@ -80,15 +80,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.world.entity.EntityType;
|
|||
import net.minecraft.world.entity.animal.Fox;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_17_1_R1 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(Fox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityType.FOX.getClass().getDeclaredField("bm"); // bm = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityType.FOX, (EntityType.EntityFactory<Fox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
@ -80,15 +80,5 @@
|
|||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,45 +4,24 @@ import net.minecraft.world.entity.EntityType;
|
|||
import net.minecraft.world.entity.animal.Fox;
|
||||
import net.seanomik.tamablefoxes.util.FieldHelper;
|
||||
import net.seanomik.tamablefoxes.util.NMSInterface;
|
||||
import net.seanomik.tamablefoxes.util.Utils;
|
||||
import net.seanomik.tamablefoxes.util.io.Config;
|
||||
import net.seanomik.tamablefoxes.util.io.LanguageConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
|
||||
// In IntelliJ, these show up as an error, but it compiles fine.
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSInterface_1_17_R1 implements NMSInterface {
|
||||
@Override
|
||||
public void registerCustomFoxEntity() {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
// This must be `EntityFox` since after being compiled, the class goes back to `EntityFox` instead of `Fox`
|
||||
ClassReader cr = new ClassReader(Fox.class.getResourceAsStream("EntityFox.class"));
|
||||
ClassNode node = new ClassNode();
|
||||
cr.accept(node, 0);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(cw);
|
||||
clazz = new ClassDefiner(ClassLoader.getSystemClassLoader()).get(node.name.replace("/", "."), cw.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try { // Replace the fox entity
|
||||
Field field = EntityType.FOX.getClass().getDeclaredField("bm"); // bm = factory
|
||||
Class<?> finalClazz = clazz;
|
||||
FieldHelper.setFieldUsingUnsafe(field, EntityType.FOX, (EntityType.EntityFactory<Fox>) EntityTamableFox::new);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes</artifactId>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes-parent</artifactId>
|
||||
<version>2.1.4-SNAPSHOT</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>tamablefoxes-util</artifactId>
|
||||
|
|
Loading…
Reference in New Issue