Advertisement
Jetp250

Minecraft - NMSUtils for Spigot

Apr 23rd, 2017
2,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.54 KB | None | 0 0
  1. import java.lang.reflect.Field;
  2. import java.util.List;
  3.  
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
  6.  
  7. import net.minecraft.server.v1_11_R1.*;
  8. import net.minecraft.server.v1_11_R1.BiomeBase.BiomeMeta;
  9. /*
  10. * An Utility class for net.minecraft.server related operations, mostly mobs and items.
  11. * NO COPYRIGHT. Use it however you feel like. You can claim it as your own, you can modify it,
  12. * you can share it, you can use it, with no permission whatsoever, I don't mind :)
  13. * @author jetp250
  14. */
  15. public final class NMSUtils {
  16.  
  17.     private static final Field META_LIST_MONSTER;
  18.     private static final Field META_LIST_CREATURE;
  19.     private static final Field META_LIST_AMBIENT;
  20.     private static final Field META_LIST_WATER_CREATURE;
  21.     /**
  22.      * a CraftBukkit server field to reduce continuous casting from
  23.      * {@link Bukkit#getServer()}.
  24.      */
  25.     public static final CraftServer SERVER;
  26.  
  27.     private static boolean accessible;
  28.  
  29.     private static boolean isAccessible() {
  30.         return accessible;
  31.     }
  32.  
  33.     private static void init() {
  34.         accessible = !(META_LIST_MONSTER == null || META_LIST_CREATURE == null || META_LIST_AMBIENT == null
  35.                 || META_LIST_WATER_CREATURE == null);
  36.     }
  37.  
  38.     /**
  39.      * Registers an Item (Not an ItemStack!) to be available for use. an ItemStack can then be created using <code>new ItemStack(item)</code>.
  40.      * @param name - The name of the item, can be anything
  41.      * @param id - The ID of the item, will be rendered depending on this
  42.      * @param item - The net.minecraft.server.version.Item itself
  43.      */
  44.     public static void registerItem(final String name, final int id, final Item item) {
  45.         final MinecraftKey key = new MinecraftKey(name);
  46.         Item.REGISTRY.a(id, key, item);
  47.     }
  48.  
  49.     /**
  50.      * Adds a random spawn for the mob with the specified arguments.
  51.      * <p>
  52.      * If you're using a custom entity class, remember to <b>register</b> it
  53.      * before using this! Otherwise it'll not be rendered by the client.
  54.      * <p>
  55.      * If {@link #isAccessible()} returns false, the process will not be
  56.      * executed.
  57.      *
  58.      * @see #registerEntity(MobType, Class, boolean)
  59.      * @param type
  60.      *            - The mob type to spawn
  61.      * @param data
  62.      *            - The spawn data (chance, amount), cannot be null!
  63.      * @param biomes
  64.      *            - The array of biomes to let the mobs spawn in, use Biome.ALL
  65.      *            for all.
  66.      */
  67.     public static void addRandomSpawn(final EntityType type, final SpawnData data, final Biome... biomes) {
  68.         if (!isAccessible() || type.isSpecial()) {
  69.             return;
  70.         }
  71.         final Field field;
  72.         if ((field = type.getMeta().getField()) == null) {
  73.             return;
  74.         }
  75.         try {
  76.             field.setAccessible(true);
  77.             for (BiomeBase base : BiomeBase.i) {
  78.                 for (Biome biome : biomes) {
  79.                     if (biome != Biome.ALL && base.getClass() != biome.getNMSClass()) {
  80.                         continue;
  81.                     }
  82.                     @SuppressWarnings("unchecked")
  83.                     final List<BiomeMeta> list = (List<BiomeMeta>) field.get(base);
  84.                     list.add(data);
  85.                     field.set(base, list);
  86.                 }
  87.             }
  88.             field.setAccessible(false);
  89.         } catch (Exception e) {
  90.             e.printStackTrace();
  91.         }
  92.     }
  93.  
  94.     /**
  95.      * Registers the custom class to be available for use.
  96.      *
  97.      * @param type
  98.      *            - The type of your mob
  99.      * @param customClass
  100.      *            - Your custom class that'll be used
  101.      * @param biomes
  102.      *            - Should your mob be set as a default in each biome? Only one
  103.      *            custom entity of this type entity can have this set as 'true'.
  104.      */
  105.     public static void registerEntity(final EntityType type, final Class<? extends Entity> customClass,
  106.             boolean biomes) {
  107.         registerEntity(type.getName(), type, customClass, biomes);
  108.     }
  109.  
  110.     /**
  111.      * Registers the custom class to be available for use.
  112.      *
  113.      * @param name
  114.      *            - The 'savegame id' of the mob.
  115.      * @param type
  116.      *            - The type of your mob
  117.      * @param customClass
  118.      *            - Your custom class that'll be used
  119.      * @param biomes
  120.      *            - Should your mob be set as a default in each biome? Only one
  121.      *            custom entity of this type entity can have this set as 'true'.
  122.      * @see #registerEntity(int, String, MobType, Class, Biome[])
  123.      * @see EntityType#getName() EntityType#getName() for the savegame id.
  124.      */
  125.     @SuppressWarnings("unchecked")
  126.     public static void registerEntity(final String name, final EntityType type,
  127.             final Class<? extends Entity> customClass, boolean biomes) {
  128.         final MinecraftKey key = new MinecraftKey(name);
  129.         EntityTypes.b.a(type.getId(), key, customClass);
  130.         if (!EntityTypes.d.contains(key)) {
  131.             EntityTypes.d.add(key);
  132.         }
  133.         if (!isAccessible() || !biomes || type.isSpecial()) {
  134.             return;
  135.         }
  136.         final Field field;
  137.         if ((field = type.getMeta().getField()) == null) {
  138.             return;
  139.         }
  140.         try {
  141.             field.setAccessible(true);
  142.             for (BiomeBase base : BiomeBase.i) {
  143.                 final List<BiomeMeta> list = (List<BiomeMeta>) field.get(base);
  144.                 for (BiomeMeta meta : list) {
  145.                     if (meta.b == type.getNMSClass()) {
  146.                         meta.b = (Class<? extends EntityInsentient>) customClass;
  147.                         break;
  148.                     }
  149.                 }
  150.             }
  151.             field.setAccessible(false);
  152.         } catch (Exception e) {
  153.             e.printStackTrace();
  154.         }
  155.     }
  156.  
  157.     /**
  158.      * Registers the custom class to be available for use.
  159.      *
  160.      * @param id
  161.      *            - The mob id. BE CAREFUL with this. Your Minecraft client
  162.      *            renders the entity based on this, and if used improperly, will
  163.      *            cause unexpected behavior!
  164.      * @param name
  165.      *            - The 'savegame id' of the mob.
  166.      * @param type
  167.      *            - The type of your mob
  168.      * @param customClass
  169.      *            - Your custom class that'll be used
  170.      * @param biomes
  171.      *            - The array of biomes to make the mob spawn in.
  172.      * @see #registerEntity(int, String, MobType, Class, Biome[])
  173.      * @see EntityType#getName() EntityType#getName() for the savegame id.
  174.      * @see EntityType#getId() EntityType#getId() for the correct mob id.
  175.      */
  176.     @SuppressWarnings("unchecked")
  177.     public static void registerEntity(final int id, final String name, final MobType type,
  178.             final Class<? extends Entity> customClass, final Biome... biomes) {
  179.         final MinecraftKey key = new MinecraftKey(name);
  180.         EntityTypes.b.a(id, key, customClass);
  181.         if (!EntityTypes.d.contains(key)) {
  182.             EntityTypes.d.add(key);
  183.         }
  184.         if (!isAccessible() || biomes.length == 0 || type.isSpecial()) {
  185.             return;
  186.         }
  187.         final Field field;
  188.         if ((field = type.getMeta().getField()) == null) {
  189.             return;
  190.         }
  191.         try {
  192.             field.setAccessible(true);
  193.             for (BiomeBase base : BiomeBase.i) {
  194.                 final List<BiomeMeta> list = (List<BiomeMeta>) field.get(base);
  195.                 for (Biome biome : biomes) {
  196.                     if (biome.getNMSClass() != base.getClass()) {
  197.                         continue;
  198.                     }
  199.                     for (BiomeMeta meta : list) {
  200.                         if (meta.b == type.getNMSClass()) {
  201.                             meta.b = (Class<? extends EntityInsentient>) customClass;
  202.                             break;
  203.                         }
  204.                     }
  205.                 }
  206.             }
  207.             field.setAccessible(false);
  208.         } catch (Exception e) {
  209.             e.printStackTrace();
  210.         }
  211.     }
  212.  
  213.     public enum MobType implements EntityType {
  214.  
  215.         ELDER_GUARDIAN(4, "elder_guardian", EntityGuardianElder.class, MobMeta.MONSTER),
  216.         WITHER_SKELETON(5, "wither_skeleton", EntitySkeletonWither.class, MobMeta.MONSTER),
  217.         STRAY(6, "stray", EntitySkeletonStray.class, MobMeta.MONSTER),
  218.         HUSK(23, "husk", EntityZombieHusk.class, MobMeta.MONSTER),
  219.         ZOMBIE_VILLAGER(27, "zombie_villager", EntityZombieVillager.class, MobMeta.MONSTER),
  220.         EVOKER(34, "evocation_illager", EntityEvoker.class, MobMeta.MONSTER),
  221.         VEX(35, "vex", EntityVex.class, MobMeta.MONSTER),
  222.         VINDICATOR(36, "vindication_illager", EntityVindicator.class, MobMeta.MONSTER),
  223.         CREEPER(50, "creeper", EntityCreeper.class, MobMeta.MONSTER),
  224.         SKELETON(51, "skeleton", EntitySkeleton.class, MobMeta.MONSTER),
  225.         SPIDER(52, "spider", EntitySpider.class, MobMeta.MONSTER),
  226.         GIANT(53, "giant", EntityGiantZombie.class, MobMeta.MONSTER),
  227.         ZOMBIE(54, "zombie", EntityZombie.class, MobMeta.MONSTER),
  228.         SLIME(55, "slime", EntitySlime.class, MobMeta.MONSTER),
  229.         GHAST(56, "ghast", EntityGhast.class, MobMeta.MONSTER),
  230.         ZOMBIE_PIGMAN(57, "zombie_pigman", EntityPigZombie.class, MobMeta.MONSTER),
  231.         ENDERMAN(58, "enderman", EntityEnderman.class, MobMeta.MONSTER),
  232.         CAVE_SPIDER(59, "cave_spider", EntityCaveSpider.class, MobMeta.MONSTER),
  233.         SILVERFISH(60, "silverfish", EntitySilverfish.class, MobMeta.MONSTER),
  234.         BLAZE(61, "blaze", EntityBlaze.class, MobMeta.MONSTER),
  235.         MAGMACUBE(62, "magma_cube", EntityMagmaCube.class, MobMeta.MONSTER),
  236.         ENDER_DRAGON(63, "ender_dragon", EntityEnderDragon.class, MobMeta.MONSTER),
  237.         WITHER(64, "wither", EntityWither.class, MobMeta.MONSTER),
  238.         WITCH(66, "witch", EntityWitch.class, MobMeta.MONSTER),
  239.         ENDERMITE(67, "endermite", EntityEndermite.class, MobMeta.MONSTER),
  240.         GUARDIAN(68, "guardian", EntityGuardian.class, MobMeta.MONSTER),
  241.         SHULKER(69, "shulker", EntityShulker.class, MobMeta.MONSTER),
  242.         SKELETON_HORSE(28, "skeleton_horse", EntityHorseSkeleton.class, MobMeta.CREATURE),
  243.         ZOMBIE_HORSE(29, "zombie_horse", EntityHorseZombie.class, MobMeta.CREATURE),
  244.         DONKEY(31, "donkey", EntityHorseDonkey.class, MobMeta.CREATURE),
  245.         MULE(32, "mule", EntityHorseMule.class, MobMeta.CREATURE),
  246.         BAT(65, "bat", EntityBat.class, MobMeta.AMBIENT),
  247.         PIG(90, "pig", EntityPig.class, MobMeta.CREATURE),
  248.         SHEEP(91, "sheep", EntitySheep.class, MobMeta.CREATURE),
  249.         COW(92, "cow", EntityCow.class, MobMeta.CREATURE),
  250.         CHICKEN(93, "chicken", EntityChicken.class, MobMeta.CREATURE),
  251.         SQUID(94, "squid", EntitySquid.class, MobMeta.WATER_CREATURE),
  252.         WOLF(95, "wolf", EntityWolf.class, MobMeta.CREATURE),
  253.         MOOSHROOM(96, "mooshroom", EntityMushroomCow.class, MobMeta.CREATURE),
  254.         SNOWMAN(97, "snowman", EntitySnowman.class, MobMeta.CREATURE),
  255.         OCELOT(98, "ocelot", EntityOcelot.class, MobMeta.CREATURE),
  256.         IRON_GOLEM(99, "villager_golem", EntityIronGolem.class, MobMeta.CREATURE),
  257.         HORSE(100, "horse", EntityHorse.class, MobMeta.CREATURE),
  258.         RABBIT(101, "rabbit", EntityRabbit.class, MobMeta.CREATURE),
  259.         POLARBEAR(102, "polar_bear", EntityPolarBear.class, MobMeta.CREATURE),
  260.         LLAMA(103, "llama", EntityLlama.class, MobMeta.CREATURE),
  261.         VILLAGER(120, "villager", EntityVillager.class, MobMeta.CREATURE);
  262.  
  263.         private final int id;
  264.         private final String name;
  265.         private final Class<? extends EntityInsentient> clazz;
  266.         private final MobMeta meta;
  267.  
  268.         private MobType(final int id, final String name, Class<? extends EntityInsentient> nmsClazz,
  269.                 final MobMeta meta) {
  270.             this.id = id;
  271.             this.name = name;
  272.             this.clazz = nmsClazz;
  273.             this.meta = meta;
  274.         }
  275.  
  276.         @Override
  277.         public MobMeta getMeta() {
  278.             return meta;
  279.         }
  280.  
  281.         @Override
  282.         public int getId() {
  283.             return id;
  284.         }
  285.  
  286.         @Override
  287.         public String getName() {
  288.             return name;
  289.         }
  290.  
  291.         @Override
  292.         public Class<? extends EntityInsentient> getNMSClass() {
  293.             return clazz;
  294.         }
  295.  
  296.         @Override
  297.         public boolean isSpecial() {
  298.             return false;
  299.         }
  300.     }
  301.  
  302.     public enum SpecialEntities implements EntityType {
  303.         DROPPED_ITEM(1, "item", EntityItem.class),
  304.         EXPERIENCE_ORB(2, "xp_orb", EntityExperienceOrb.class),
  305.         AREA_EFFECT_CLOUD(3, "area_effect_cloud", EntityAreaEffectCloud.class),
  306.         LEAD_KNOT(8, "leash_knot", EntityLeash.class),
  307.         PAINTING(9, "painting", EntityPainting.class),
  308.         ITEM_FRAME(18, "item_frame", EntityItemFrame.class),
  309.         ARMOR_STAND(30, "armor_stand", EntityArmorStand.class),
  310.         EVOCATION_FANGS(33, "evocation_fangs", EntityEvokerFangs.class),
  311.         ENDER_CRYSTAL(200, "ender_crystal", EntityEnderCrystal.class),
  312.         THROWN_EGG(7, "egg", EntityEgg.class),
  313.         ARROW(10, "arrow", EntityArrow.class),
  314.         SNOWBALL(11, "snowball", EntitySnowball.class),
  315.         FIREBALL(12, "fireball", EntityFireball.class),
  316.         SMALL_FIREBALL(13, "fireball", EntitySmallFireball.class),
  317.         ENDER_PEARL(14, "ender_pearl", EntityEnderPearl.class),
  318.         EYE_OF_ENDER(15, "eye_of_ender_signal", EntityEnderSignal.class),
  319.         POTION(16, "potion", EntityPotion.class),
  320.         EXP_BOTTLE(17, "xp_bottle", EntityThrownExpBottle.class),
  321.         WITHER_SKULL(19, "wither_skull", EntityWitherSkull.class),
  322.         FIREWORK_ROCKET(22, "fireworks_rocket", EntityFireworks.class),
  323.         SPECTRAL_ARROW(24, "spectral_arrow", EntitySpectralArrow.class),
  324.         SHULKER_BULLET(25, "shulker_bullet", EntityShulkerBullet.class),
  325.         DRAGON_FIREBALL(26, "dragon_fireball", EntityDragonFireball.class),
  326.         LLAMA_SPIT(104, "llama_spit", EntityLlamaSpit.class),
  327.         PRIMED_TNT(20, "tnt", EntityTNTPrimed.class),
  328.         FALLING_BLOCK(21, "falling_block", EntityFallingBlock.class),
  329.         COMMAND_BLOCK_MINECART(40, "commandblock_minecart", EntityMinecartCommandBlock.class),
  330.         BOAT(41, "boat", EntityBoat.class),
  331.         MINECART(42, "minecart", EntityMinecartRideable.class),
  332.         CHEST_MINECART(43, "chest_minecart", EntityMinecartChest.class),
  333.         FURNACE_MINECART(44, "furnace_minecart", EntityMinecartFurnace.class),
  334.         TNT_MINECART(45, "tnt_minecart", EntityMinecartTNT.class),
  335.         HOPPER_MINECART(46, "hopper_minecart", EntityMinecartHopper.class),
  336.         SPAWNER_MINECART(47, "spawner_minecart", EntityMinecartMobSpawner.class);
  337.  
  338.         private final int id;
  339.         private final String name;
  340.         private final Class<? extends Entity> clazz;
  341.  
  342.         private SpecialEntities(final int id, final String name, Class<? extends Entity> nmsClazz) {
  343.             this.id = id;
  344.             this.name = name;
  345.             this.clazz = nmsClazz;
  346.         }
  347.  
  348.         @Override
  349.         public int getId() {
  350.             return id;
  351.         }
  352.  
  353.         @Override
  354.         public String getName() {
  355.             return name;
  356.         }
  357.  
  358.         @Override
  359.         public Class<? extends Entity> getNMSClass() {
  360.             return clazz;
  361.         }
  362.  
  363.         @Override
  364.         public boolean isSpecial() {
  365.             return true;
  366.         }
  367.  
  368.         @Override
  369.         public MobMeta getMeta() {
  370.             return MobMeta.UNDEFINED;
  371.         }
  372.     }
  373.  
  374.     private interface EntityType {
  375.  
  376.         /**
  377.          * Returns the mob's network hexadecimal id value. Used to tell the
  378.          * client which mob should be rendered.
  379.          *
  380.          * @return The ID as an int.
  381.          */
  382.         int getId();
  383.  
  384.         /**
  385.          * Rather than returning its name, this returns the mob's
  386.          * <b>savegame-id</b>. A Custom savegame-id can be provided instead of
  387.          * this, though.
  388.          *
  389.          * @return The savegame-id String.
  390.          */
  391.         String getName();
  392.  
  393.         /**
  394.          * Returns the NMS class of this EntityType. Used when overriding the
  395.          * mob to spawn as a default in biomes.
  396.          *
  397.          * @return The NMS class your mob should be extending.
  398.          */
  399.         Class<? extends Entity> getNMSClass();
  400.  
  401.         /**
  402.          * If a mob is special (aka is part of {@link SpecialEntities} enum),
  403.          * this mob type cannot be registered as a default to the biomes.
  404.          *
  405.          * @return True if the mob cannot override default mobs in biomes.
  406.          */
  407.         boolean isSpecial();
  408.  
  409.         /**
  410.          * Returns the meta containing info about the list field in which the
  411.          * mob will be added to.
  412.          */
  413.         MobMeta getMeta();
  414.     };
  415.  
  416.     public enum Biome {
  417.  
  418.         BEACH(BiomeBeach.class),
  419.         EXTREME_HILLS(BiomeBigHills.class),
  420.         DESERT(BiomeDesert.class),
  421.         FOREST(BiomeForest.class),
  422.         FLOWER_FOREST(BiomeForestMutated.class),
  423.         HELL(BiomeHell.class),
  424.         ICE_PLAINS(BiomeIcePlains.class),
  425.         JUNGLE(BiomeJungle.class),
  426.         MESA(BiomeMesa.class),
  427.         MUSHROOM_ISLANDS(BiomeMushrooms.class),
  428.         OCEAN(BiomeOcean.class),
  429.         PLAINS(BiomePlains.class),
  430.         RIVER(BiomeRiver.class),
  431.         SAVANNA(BiomeSavanna.class),
  432.         MUTATED_SAVANNA(BiomeSavannaMutated.class),
  433.         STONE_BEACH(BiomeStoneBeach.class),
  434.         SWAMP(BiomeSwamp.class),
  435.         TAIGA(BiomeTaiga.class),
  436.         THE_END(BiomeTheEnd.class),
  437.         VOID(BiomeVoid.class),
  438.         ALL(null);
  439.  
  440.         private final Class<? extends BiomeBase> clazz;
  441.  
  442.         private Biome(final Class<? extends BiomeBase> clazz) {
  443.             this.clazz = clazz;
  444.         }
  445.  
  446.         /**
  447.          * @return the NMS class behind this Biome, in which the vanilla mob
  448.          *         will be overridden.
  449.          */
  450.         public Class<? extends BiomeBase> getNMSClass() {
  451.             return clazz;
  452.         }
  453.  
  454.     }
  455.  
  456.     public enum MobMeta {
  457.         MONSTER(META_LIST_MONSTER),
  458.         CREATURE(META_LIST_CREATURE),
  459.         WATER_CREATURE(META_LIST_WATER_CREATURE),
  460.         AMBIENT(META_LIST_AMBIENT),
  461.         UNDEFINED(null);
  462.  
  463.         private final Field field;
  464.  
  465.         private MobMeta(final Field field) {
  466.             this.field = field;
  467.         }
  468.  
  469.         /**
  470.          * @return the BiomeMeta list field of this entity.
  471.          *         <p>
  472.          *         <b>Undefined will not be accepted and returns null.</b>
  473.          *         </p>
  474.          */
  475.         public Field getField() {
  476.             return field;
  477.         }
  478.     }
  479.  
  480.     public static enum Attributes {
  481.         MAX_HEALTH("generic.maxHealth", GenericAttributes.maxHealth),
  482.         KNOCKBACK_RESISTANCE("generic.knockbackResistance", GenericAttributes.c),
  483.         MOVEMENT_SPEED("generic.movementSpeed", GenericAttributes.MOVEMENT_SPEED),
  484.         ATTACK_DAMAGE("generic.attackDamage", GenericAttributes.ATTACK_DAMAGE),
  485.         ARMOR("generic.armor", GenericAttributes.g),
  486.         ARMOR_TOUGHNESS("generic.armorToughness", GenericAttributes.h),
  487.         ATTACK_SPEED("generic.attackSpeed", GenericAttributes.f),
  488.         LUCK("generic.luck", GenericAttributes.i),
  489.         FOLLOW_RANGE("generic.followRange", GenericAttributes.FOLLOW_RANGE);
  490.  
  491.         private final String name;
  492.         private final IAttribute attribute;
  493.  
  494.         private Attributes(String nmsName, IAttribute nmsAttribute) {
  495.             this.name = nmsName;
  496.             this.attribute = nmsAttribute;
  497.         }
  498.  
  499.         /**
  500.          * Returns the NMS name of the attribute. For example,
  501.          * <code>MAX_HEALTH</code> returns <code>"generic.maxHealth"</code>, and
  502.          * so on and so forth.
  503.          *
  504.          * @return The name as a String.
  505.          */
  506.         public String getName() {
  507.             return name;
  508.         }
  509.  
  510.         /**
  511.          * @return the IAttribute value of this type, used in place of
  512.          *         <code>GenericAttributes.g</code> (for Attributes.ARMOR as an
  513.          *         example).
  514.          */
  515.         public IAttribute getValue() {
  516.             return attribute;
  517.         }
  518.     }
  519.  
  520.     public class NBTTagType {
  521.         public static final int COMPOUND = 10;
  522.         public static final int LIST = 9;
  523.         public static final int STRING = 8;
  524.         public static final int INT_ARRAY = 11;
  525.         public static final int BYTE_ARRAY = 7;
  526.         public static final int DOUBLE = 6;
  527.         public static final int FLOAT = 5;
  528.         public static final int LONG = 4;
  529.         public static final int INT = 3;
  530.         public static final int SHORT = 2;
  531.         public static final int BYTE = 1;
  532.         public static final int BOOLEAN = 1;
  533.         public static final int END = 0;
  534.     }
  535.  
  536.     public static class SpawnData extends BiomeMeta {
  537.  
  538.         private final Class<? extends EntityInsentient> customClass;
  539.  
  540.         /**
  541.          * Creates a new instance of SpawnData, and at the same time, a new
  542.          * instanceof BiomeMeta, used to add random spawns and such.
  543.          *
  544.          * @param customClass
  545.          *            - Your class to spawn
  546.          * @param spawnWeight
  547.          *            - The chance for the mob(s) to spawn.
  548.          * @param minSpawns
  549.          *            - The minimum amount of entities spawned at once.
  550.          * @param maxSpawns
  551.          *            - The maximum amount of entities spawned at once.
  552.          */
  553.         public SpawnData(Class<? extends EntityInsentient> customClass, final int spawnWeight, final int minSpawns,
  554.                 final int maxSpawns) {
  555.             super(customClass, spawnWeight, minSpawns, maxSpawns);
  556.             this.customClass = customClass;
  557.         }
  558.  
  559.         public Class<? extends EntityInsentient> getCustomClass() {
  560.             return customClass;
  561.         }
  562.     }
  563.  
  564.     static {
  565.         final Class<BiomeBase> clazz = BiomeBase.class;
  566.         Field monster = null;
  567.         Field creature = null;
  568.         Field water = null;
  569.         Field ambient = null;
  570.         try {
  571.             // These fields may vary depending on your version.
  572.             // The new names can be found under
  573.             // net.minecraft.server.<version>.BiomeBase.class
  574.             monster = clazz.getDeclaredField("u");
  575.             creature = clazz.getDeclaredField("v");
  576.             water = clazz.getDeclaredField("w");
  577.             ambient = clazz.getDeclaredField("x");
  578.         } catch (Exception e) {
  579.         }
  580.         META_LIST_MONSTER = monster;
  581.         META_LIST_CREATURE = creature;
  582.         META_LIST_WATER_CREATURE = water;
  583.         META_LIST_AMBIENT = ambient;
  584.         SERVER = (CraftServer) Bukkit.getServer();
  585.         init();
  586.     }
  587. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement