Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static int dungeonLootAttempts = 8;
- private static ArrayList<ObjectPair<Float, String>> dungeonMobs = new ArrayList<ObjectPair<Float, String>>();
- private static ArrayList<ObjectPair<Float, DungeonLoot>> dungeonLoot = new ArrayList<ObjectPair<Float, DungeonLoot>>();
- /**
- * Set the number of item stacks that will be attempted to be added to each Dungeon chest.
- * Note: Due to random number generation, you will not always get this amount per chest.
- * @param number The maximum number of item stacks to add to a chest.
- */
- public static void setDungeonLootTries(int number)
- {
- dungeonLootAttempts = number;
- }
- /**
- * @return The max number of item stacks found in each dungeon chest.
- */
- public static int getDungeonLootTries()
- {
- return dungeonLootAttempts;
- }
- /**
- * Adds a mob to the possible list of creatures the spawner will create.
- * If the mob is already in the spawn list, the rarity will be added to the existing one,
- * causing the mob to be more common.
- *
- * @param name The name of the monster, use the same name used when registering the entity.
- * @param rarity The rarity of selecting this mob over others. Must be greater then 0.
- * Vanilla Minecraft has the following mobs:
- * Spider 1
- * Skeleton 1
- * Zombie 2
- * Meaning, Zombies are twice as common as spiders or skeletons.
- * @return The new rarity of the monster,
- */
- public static float addDungeonMob(String name, float rarity)
- {
- if (rarity <= 0)
- {
- throw new IllegalArgumentException("Rarity must be greater then zero");
- }
- for(ObjectPair<Float, String> mob : dungeonMobs)
- {
- if (name.equals(mob.getValue2()))
- {
- mob.setValue1(mob.getValue1() + rarity);
- return mob.getValue1();
- }
- }
- dungeonMobs.add(new ObjectPair<Float, String>(rarity, name));
- return rarity;
- }
- /**
- * Will completely remove a Mob from the dungeon spawn list.
- *
- * @param name The name of the mob to remove
- * @return The rarity of the removed mob, prior to being removed.
- */
- public static float removeDungeonMob(String name)
- {
- for (ObjectPair<Float, String> mob : dungeonMobs)
- {
- if (name.equals(name))
- {
- dungeonMobs.remove(mob);
- return mob.getValue1();
- }
- }
- return 0;
- }
- /**
- * Gets a random mob name from the list.
- * @param rand World generation random number generator
- * @return The mob name
- */
- public static String getRandomDungeonMob(Random rand)
- {
- float maxRarity = 0f;
- for (ObjectPair<Float, String> mob : dungeonMobs)
- {
- maxRarity += mob.getValue1();
- }
- float targetRarity = rand.nextFloat() * maxRarity;
- for (ObjectPair<Float, String> mob : dungeonMobs)
- {
- if (targetRarity < mob.getValue1())
- {
- return mob.getValue2();
- }
- targetRarity -= mob.getValue1();
- }
- return "";
- }
- /**
- * Adds a item stack to the dungeon loot list with a stack size
- * of 1.
- *
- * @param item The ItemStack to be added to the loot list
- * @param rarity The relative chance that this item will spawn, Vanilla has
- * most of its items set to 1. Like the saddle, bread, silk, wheat, etc..
- * Rarer items are set to lower values, EXA: Golden Apple 0.01
- */
- public static void addDungeonLoot(ItemStack item, float rarity)
- {
- addDungeonLoot(item, rarity, 1, 1);
- }
- /**
- * Adds a item stack, with a range of sizes, to the dungeon loot list.
- * If a stack matching the same item, and size range, is already in the list
- * the rarities will be added together making the item more common.
- *
- * @param item The ItemStack to be added to the loot list
- * @param rarity The relative chance that this item will spawn, Vanilla has
- * most of its items set to 1. Like the saddle, bread, silk, wheat, etc..
- * Rarer items are set to lower values, EXA: Golden Apple 0.01
- * @param minCount When this item does generate, the minimum number that is in the stack
- * @param maxCount When this item does generate, the maximum number that can bein the stack
- * @return The new rarity of the loot.
- */
- public static float addDungeonLoot(ItemStack item, float rarity, int minCount, int maxCount)
- {
- for (ObjectPair<Float, DungeonLoot> loot : dungeonLoot)
- {
- if (loot.getValue2().equals(item, minCount, maxCount))
- {
- loot.setValue1(loot.getValue1() + rarity);
- return loot.getValue1();
- }
- }
- dungeonLoot.add(new ObjectPair<Float, DungeonLoot>(rarity, new DungeonLoot(item, minCount, maxCount)));
- return rarity;
- }
- /**
- * Removes a item stack from the dungeon loot list, this will remove all items
- * as long as the item stack matches, it will not care about matching the stack
- * size ranges perfectly.
- *
- * @param item The item stack to remove
- * @return The total rarity of all items removed
- */
- public static float removeDungeonLoot(ItemStack item)
- {
- return removeDungeonLoot(item, -1, 0);
- }
- /**
- * Removes a item stack from the dungeon loot list. If 'minCount' parameter
- * is greater then 0, it will only remove loot items that have the same exact
- * stack size range as passed in by parameters.
- *
- * @param item The item stack to remove
- * @param minCount The minimum count for the match check, if less then 0,
- * the size check is skipped
- * @param maxCount The max count used in match check when 'minCount' is >= 0
- * @return The total rarity of all items removed
- */
- public static float removeDungeonLoot(ItemStack item, int minCount, int maxCount)
- {
- float rarity = 0;
- ArrayList<ObjectPair<Float, DungeonLoot>> lootTmp = (ArrayList<ObjectPair<Float, DungeonLoot>>)dungeonLoot.clone();
- if (minCount < 0)
- {
- for (ObjectPair<Float, DungeonLoot> loot : lootTmp)
- {
- if (loot.getValue2().equals(item))
- {
- dungeonLoot.remove(loot);
- rarity += loot.getValue1();
- }
- }
- }
- else
- {
- for (ObjectPair<Float, DungeonLoot> loot : lootTmp)
- {
- if (loot.getValue2().equals(item, minCount, maxCount))
- {
- dungeonLoot.remove(loot);
- rarity += loot.getValue1();
- }
- }
- }
- return rarity;
- }
- /**
- * Gets a random item stack to place in a dungeon chest during world generation
- * @param rand World generation random number generator
- * @return The item stack
- */
- public static ItemStack getRandomDungeonLoot(Random rand)
- {
- float maxRarity = 0f;
- for (ObjectPair<Float, DungeonLoot> loot : dungeonLoot)
- {
- maxRarity += loot.getValue1();
- }
- float targetRarity = rand.nextFloat() * maxRarity;
- for (ObjectPair<Float, DungeonLoot> loot : dungeonLoot)
- {
- if (targetRarity < loot.getValue1())
- {
- return loot.getValue2().generateStack(rand);
- }
- targetRarity -= loot.getValue1();
- }
- return null;
- }
- static
- {
- addDungeonMob("Skeleton", 1.0f);
- addDungeonMob("Zombie", 2.0f);
- addDungeonMob("Spider", 1.0f);
- addDungeonLoot(new ItemStack(Item.saddle), 1.00f );
- addDungeonLoot(new ItemStack(Item.ingotIron), 1.00f, 1, 4);
- addDungeonLoot(new ItemStack(Item.bread), 1.00f );
- addDungeonLoot(new ItemStack(Item.wheat), 1.00f, 1, 4);
- addDungeonLoot(new ItemStack(Item.gunpowder), 1.00f, 1, 4);
- addDungeonLoot(new ItemStack(Item.silk), 1.00f, 1, 4);
- addDungeonLoot(new ItemStack(Item.bucketEmpty), 1.00f );
- addDungeonLoot(new ItemStack(Item.appleGold), 0.01f );
- addDungeonLoot(new ItemStack(Item.redstone), 0.50f, 1, 4);
- addDungeonLoot(new ItemStack(Item.record13), 0.05f );
- addDungeonLoot(new ItemStack(Item.recordCat), 0.05f );
- addDungeonLoot(new ItemStack(Item.dyePowder, 1, 3), 1.00f );
- }
Advertisement
Add Comment
Please, Sign In to add comment