Advertisement
The_red_Freak

EntityTypes

Mar 2nd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package me.the_red_freak.zombietest.entities;
  2.  
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.lang.reflect.Method;
  5.  
  6. import org.bukkit.Location;
  7. import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
  8.  
  9. import net.minecraft.server.v1_11_R1.Entity;
  10. import net.minecraft.server.v1_11_R1.EntityInsentient;
  11. import net.minecraft.server.v1_11_R1.WorldServer;
  12.  
  13. public enum EntityTypes {
  14.     // NAME("Entity name", Entity ID, yourcustomclass.class);
  15.     CZombie("CZombie", 54, Zombie.class); // You can
  16.                                             // add as
  17.                                             // many as
  18.     // you want.
  19.  
  20.     private EntityTypes(String name, int id, Class<? extends EntityInsentient> custom) {
  21.         // addToMaps(custom, name, id);
  22.         try {
  23.             Method f = net.minecraft.server.v1_11_R1.EntityTypes.class.getDeclaredMethod("a", Integer.class,
  24.                     String.class, Class.class, String.class);
  25.             f.setAccessible(true);
  26.             f.invoke(id, name, custom, name);
  27.  
  28.         } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
  29.                 | InvocationTargetException e) {
  30.             e.printStackTrace();
  31.         }
  32.  
  33.     }
  34.  
  35.     /**
  36.      * That one here is outdated!
  37.      */
  38.     // private static void addToMaps(Class clazz, String name, int id) {
  39.     // ((Map) Util.getPrivateField("c",
  40.     // net.minecraft.server.v1_11_R1.EntityTypes.class, null)).put(name, clazz);
  41.     // ((Map) Util.getPrivateField("d",
  42.     // net.minecraft.server.v1_11_R1.EntityTypes.class, null)).put(clazz, name);
  43.     // ((Map) Util.getPrivateField("f",
  44.     // net.minecraft.server.v1_11_R1.EntityTypes.class, null)).put(clazz,
  45.     // Integer.valueOf(id));
  46.     // }
  47.  
  48.     /**
  49.      * So i tried to set up my own one
  50.      *
  51.      * @see EntityTypes#EntityTypes(String, int, Class)
  52.      */
  53.  
  54.     public static void spawnEntity(Entity entity, Location loc) {
  55.         WorldServer s = ((CraftWorld) loc.getWorld()).getHandle();
  56.  
  57.         s.addEntity(entity);
  58.         entity.setPosition(loc.getX(), loc.getY(), loc.getZ());
  59.  
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement