@SubscribeEvent public static void onLootTableLoad(LootTableLoadEvent event) { ResourceLocation tableName = event.getName(); LootPool pool = null; int bandage = 0, plaster = 0, morphine = 0; if (tableName.equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST)) { pool = event.getTable().getPool("main"); bandage = 8; plaster = 16; morphine = 4; } else if (tableName.equals(LootTableList.CHESTS_STRONGHOLD_CORRIDOR) || tableName.equals(LootTableList.CHESTS_STRONGHOLD_CROSSING) || tableName.equals(LootTableList.CHESTS_ABANDONED_MINESHAFT)) { pool = event.getTable().getPool("main"); bandage = 20; plaster = 24; morphine = 8; } if (pool != null) { pool.addEntry(new LootEntryItem(FirstAidItems.BANDAGE, bandage, 0, new SetCount[]{new SetCount(new LootCondition[0], new RandomValueRange(1, 3))}, new LootCondition[0], FirstAid.MODID + "bandage")); pool.addEntry(new LootEntryItem(FirstAidItems.PLASTER, plaster, 0, new SetCount[]{new SetCount(new LootCondition[0], new RandomValueRange(1, 5))}, new LootCondition[0], FirstAid.MODID + "plaster")); pool.addEntry(new LootEntryItem(FirstAidItems.MORPHINE, morphine, 0, new SetCount[]{new SetCount(new LootCondition[0], new RandomValueRange(1, 2))}, new LootCondition[0], FirstAid.MODID + "morphine")); } }
@SubscribeEvent public void onLootTablesLoaded(LootTableLoadEvent event) { if ((event.getName().equals(LootTableList.CHESTS_ABANDONED_MINESHAFT)) || (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) || (event.getName().equals(LootTableList.CHESTS_DESERT_PYRAMID)) || (event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE)) || (event.getName().equals(LootTableList.CHESTS_STRONGHOLD_LIBRARY)) || (event.getName().equals(LootTableList.CHESTS_END_CITY_TREASURE))) { LootPool mainPool = event.getTable().getPool("main"); if (mainPool != null) { if (event.getName().equals(LootTableList.CHESTS_ABANDONED_MINESHAFT) || event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE) || event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) { mainPool.addEntry(new LootEntryItem(ModItems.FRIENDER_PEARL, 10, 0, new LootFunction[] {}, new LootCondition[0], ModGlobals.MODID + ":friender_pearl_loot")); } } } }
private static void replaceCookedWithCharred(LootPool targetPool, Item targetItem, ItemStack replacementStack, int minCount, int maxCount) { List<LootFunction> charredFunctions = Lists.newArrayList(); if(replacementStack.getItemDamage() != 0) charredFunctions.add(LootUtil.createSetMetadata(replacementStack.getItemDamage())); if(replacementStack.getTagCompound() != null) charredFunctions.add(LootUtil.createSetNBT(replacementStack.getTagCompound())); charredFunctions.add(LootUtil.createCountFunction(minCount, maxCount)); charredFunctions.add(LootUtil.createLootingFunc(0, 1)); LootCondition notOnFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(false)}, EntityTarget.THIS); LootCondition onFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(true)}, EntityTarget.THIS); targetPool.removeEntry(targetItem.getRegistryName().toString()); targetPool.addEntry(new LootEntryItem(targetItem, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {notOnFire}, targetItem.getRegistryName().toString())); targetPool.addEntry(new LootEntryItem(replacementStack.getItem(), 1, 1, charredFunctions.toArray(new LootFunction[charredFunctions.size()]), new LootCondition[] {onFire}, ModMain.MODID + ":charred_+" + targetItem.getRegistryName().getResourcePath().toString())); }
private void removeSmeltFunction(LootPool pool, Item targetItem, Item replacement, int minCount, int maxCount) { LootCondition notOnFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(false)}, EntityTarget.THIS); LootCondition onFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(true)}, EntityTarget.THIS); pool.removeEntry(targetItem.getRegistryName().toString()); pool.addEntry(new LootEntryItem(targetItem, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {notOnFire}, targetItem.getRegistryName().toString())); pool.addEntry(new LootEntryItem(replacement, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {onFire}, replacement.getRegistryName().toString())); }
/** * Converts a LootTable to a list of possible drops, only looks for Item and metadata. * @param table the loot table to get items from * @return a LinkedList of the stacks in the loot table */ public static List<ItemStack> tableToItemStacks(LootTable table){ List<ItemStack> stacks = new LinkedList<>(); for(LootPool p:getPools(table)){ for(LootEntry entry:getEntries(p)){ if(entry instanceof LootEntryItem){ LootEntryItem ei = (LootEntryItem)entry; Item item = getItem(ei); LootFunction[] functs = getFunctions(ei); boolean metaSet = false; for(LootFunction func:functs){ if(func instanceof SetMetadata){ metaSet=true; RandomValueRange range = (RandomValueRange)ReflectionHelper.getPrivateValue(SetMetadata.class, (SetMetadata)func, "metaRange","field_186573_b"); int meta = MathHelper.floor(range.getMin()); stacks.add(new ItemStack(item,1,meta)); } } if(!metaSet)stacks.add(new ItemStack(item)); } /* won't bother with this case for now else if(entry instanceof LootEntryTable){ //restart with that table ResourceLocation location = (ResourceLocation) ReflectionHelper.getPrivateValue(LootEntryTable.class, (LootEntryTable)entry, "table","field_186371_a"); } */ } } return stacks; }
@SubscribeEvent public static void onLootTableLoad(LootTableLoadEvent e) { final ResourceLocation rl = e.getName(); if (rl.equals(LootTableList.CHESTS_VILLAGE_BLACKSMITH) || rl.equals(LootTableList.CHESTS_ABANDONED_MINESHAFT) || rl.equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) { final LootTable lt = e.getTable(); LootPool lp = lt.getPool("pool0"); if (lp == null) lp = lt.getPool("main"); if (lp != null) { lp.addEntry(new LootEntryItem(MCFluxResources.UPCHIP, 20, 0, new LootFunction[0], new LootCondition[0], "mcflux:loot/upchip")); } } }
@SubscribeEvent public void onLootTablesLoaded (LootTableLoadEvent event) { // Checks to see if the loot table being loaded is the basic dungeon chest. if (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) { // Gets pool2 from the loot table. This pool is where common loot like zombie flesh // bones and string goes. final LootPool pool2 = event.getTable().getPool("pool2"); // Makes sure the pool has not been deleted. if (pool2 != null) { // Adds cookies to the loot pool. Has a weight of 10 and spawns in stacks of 1 // to 5. pool2.addEntry(new LootEntryItem(Items.COOKIE, 10, 0, new LootFunction[] { new SetCount(new LootCondition[0], new RandomValueRange(1, 5)) }, new LootCondition[0], "tutorial:cookie")); // Adds Lime Green Dye to the loot pool. Has a weight of 10. pool2.addEntry(new LootEntryItem(Items.DYE, 10, 0, new LootFunction[] { new SetDamage(new LootCondition[0], new RandomValueRange(10, 10)) }, new LootCondition[0], "tutorial:dyes")); } } // Checks to see if the loot table being loaded is for the mob we are looking for if (event.getName().equals(LootTableList.ENTITIES_PIG)) { // Gets main from the loot table. This pool is where the basic drops like porkchop are. final LootPool main = event.getTable().getPool("main"); // Makes sure that the main pool actually exists. It can be deleted by other mods. if (main != null) { // Adds a carrot to the pool. Carrots will now drop just as often as pork chops. main.addEntry(new LootEntryItem(Items.CARROT, 1, 0, new LootFunction[0], new LootCondition[0], "tutorial:carrot")); // Adds an apple to the loot pool. This entry is only used if the pig was killed by a player. main.addEntry(new LootEntryItem(Items.APPLE, 1, 0, new LootFunction[0], new LootCondition[] { new KilledByPlayer(false)}, "tutorial:player")); } } }
@SubscribeEvent public void onLootTableLoad (LootTableLoadEvent event) { if (allowDungeonLoot && event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE)) { final LootPool main = event.getTable().getPool("main"); if (main != null) { main.addEntry(new LootEntryItem(itemRing, weight, 0, new LootFunction[] { new SetDamage(new LootCondition[0], new RandomValueRange(0, ItemRing.varients.length - 1)) }, new LootCondition[0], "darkutils:nether_rings")); } } }
@SubscribeEvent public void onLootTableLoad (LootTableLoadEvent event) { final LootTable table = event.getTable(); if (skeletonDropDust && event.getName().equals(LootTableList.ENTITIES_WITHER_SKELETON)) { final LootPool pool1 = table.getPool("pool1"); if (pool1 != null) { pool1.addEntry(new LootEntryItem(itemMaterial, dustDropWeight, 0, new LootFunction[0], new LootCondition[0], DarkUtils.MOD_ID + ":wither_dust")); } } }
private @Nonnull LootEntry createLootEntry(@Nonnull Item item, int meta, int minStackSize, int maxStackSize, float chance) { LootCondition[] chanceCond = new LootCondition[] { new RandomChance(chance) }; final ResourceLocation registryName = NullHelper.notnull(item.getRegistryName(), "found unregistered item"); if (item.isDamageable()) { return new LootEntryItem(item, 1, 1, new LootFunction[] { setCount(minStackSize, maxStackSize), setDamage(item, meta), setEnergy() }, chanceCond, registryName.toString() + ":" + meta); } else { return new LootEntryItem(item, 1, 1, new LootFunction[] { setCount(minStackSize, maxStackSize), setMetadata(meta) }, chanceCond, registryName.toString() + ":" + meta); } }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent e) { Worldgen.addLoot(e.getTable(), e.getName()); if (BBConfig.moreBones) { if(e.getName().equals(LootTableList.ENTITIES_SKELETON)) { LootPool pool1 = e.getTable().getPool("pool1"); pool1.removeEntry("minecraft:bone"); pool1.addEntry(new LootEntryItem(Items.BONE, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, LootUtil.NO_CONDITIONS, Items.BONE.getRegistryName().toString())); } } if (BBConfig.flamingAnimalsDropCharredMeat) { if(e.getName().equals(LootTableList.ENTITIES_COW)) { replaceCookedWithCharred(e.getTable().getPool("pool1"), Items.BEEF, new ItemStack(RegisterItems.charredMeat, 1, ItemCharredMeat.META_MEAT), 1, 3); } else if(e.getName().equals(LootTableList.ENTITIES_PIG)) { replaceCookedWithCharred(e.getTable().getPool("main"), Items.PORKCHOP, new ItemStack(RegisterItems.charredMeat, 1, ItemCharredMeat.META_MEAT), 1, 3); } else if(e.getName().equals(LootTableList.ENTITIES_CHICKEN)) { replaceCookedWithCharred(e.getTable().getPool("pool1"), Items.CHICKEN, new ItemStack(RegisterItems.charredMeat, 1, ItemCharredMeat.META_CHICKEN), 1, 1); } else if(e.getName().equals(LootTableList.ENTITIES_SHEEP)) { replaceCookedWithCharred(e.getTable().getPool("main"), Items.MUTTON, new ItemStack(RegisterItems.charredMeat, 1, ItemCharredMeat.META_MUTTON), 1, 2); } else if(e.getName().equals(LootTableList.ENTITIES_RABBIT)) { replaceCookedWithCharred(e.getTable().getPool("pool1"), Items.RABBIT, new ItemStack(RegisterItems.charredMeat, 1, ItemCharredMeat.META_RABBIT), 0, 1); } } else { if(e.getName().equals(LootTableList.ENTITIES_COW)) { removeSmeltFunction(e.getTable().getPool("pool1"), Items.BEEF, Items.COOKED_BEEF, 1, 3); } else if(e.getName().equals(LootTableList.ENTITIES_PIG)) { removeSmeltFunction(e.getTable().getPool("main"), Items.PORKCHOP, Items.COOKED_PORKCHOP, 1, 3); } else if(e.getName().equals(LootTableList.ENTITIES_CHICKEN)) { removeSmeltFunction(e.getTable().getPool("pool1"), Items.CHICKEN, Items.COOKED_CHICKEN, 1, 1); } else if(e.getName().equals(LootTableList.ENTITIES_SHEEP)) { removeSmeltFunction(e.getTable().getPool("main"), Items.MUTTON, Items.COOKED_MUTTON, 1, 2); } else if(e.getName().equals(LootTableList.ENTITIES_RABBIT)) { removeSmeltFunction(e.getTable().getPool("pool1"), Items.RABBIT, Items.COOKED_RABBIT, 0, 1); } } if(e.getName().equals(LootTableList.ENTITIES_SPIDER) || e.getName().equals(LootTableList.ENTITIES_CAVE_SPIDER)) { if (!BBConfig.spidersDropString) { e.getTable().getPool("main").removeEntry("minecraft:string"); } e.getTable().getPool("main").addEntry(new LootEntryItem(RegisterItems.silk, 1, 1, new LootFunction[] {LootUtil.createCountFunction(2, 4), LootUtil.createLootingFunc(0, 1)}, LootUtil.NO_CONDITIONS, RegisterItems.silk.getRegistryName().toString())); } }
public static void addItemToTable(LootTable table, String poolName, Item item, int weight, int quality, LootFunction[] functions, LootCondition[] conditions) { table.getPool("main").addEntry(new LootEntryItem(item, weight, quality, functions, conditions, item.getRegistryName().toString())); }
public static Item getItem(LootEntryItem lootEntry) { return ReflectionHelper.getPrivateValue(LootEntryItem.class, lootEntry, "item", "field_186368_a"); }
public static LootFunction[] getFunctions(LootEntryItem lootEntry) { return ReflectionHelper.getPrivateValue(LootEntryItem.class, lootEntry, "functions", "field_186369_b"); }
public static LootEntryItem createLootEntryItem(Item item, int weight, int quality) { return createLootEntryItem(item, weight, quality, new LootFunction[]{}); }
public static LootEntryItem createLootEntryItem(Item item, int weight, int quality, LootFunction[] lootFunctions, LootCondition... lootConditions) { return new LootEntryItem(item, weight, quality, lootFunctions, lootConditions, CrystalMod.prefix(item.getUnlocalizedName())); }
private static void addLoot(LootPool pool, Item item, int weight) { pool.addEntry(new LootEntryItem(item, weight, 0, new LootFunction[0], new LootCondition[0], Reference.MOD_ID + item.getUnlocalizedName())); }
private void addLoot(LootPool main, Item item, int rando) { if (item != null) {//shortcut fix bc of new module config system that can delete items main.addEntry(new LootEntryItem(item, rando, 0, new LootFunction[0], new LootCondition[0], Const.MODRES + item.getUnlocalizedName())); } }
private @Nonnull LootEntry createLootEntry(@Nonnull ItemStack stack, int minStackSize, int maxStackSize, float chance) { LootCondition[] chanceCond = new LootCondition[] { new RandomChance(chance) }; final ResourceLocation registryName = NullHelper.notnull(stack.getItem().getRegistryName(), "found unregistered item"); return new LootEntryItem(stack.getItem(), 1, 1, new LootFunction[] { setCount(minStackSize, maxStackSize), setMetadata(stack.getMetadata()) }, chanceCond, registryName.toString() + ":" + stack.getMetadata()); }
private @Nonnull LootEntry createDarkSteelLootEntry(@Nonnull Item item, int meta, int minStackSize, int maxStackSize, float chance) { LootCondition[] chanceCond = new LootCondition[] { new RandomChance(chance) }; final ResourceLocation registryName = NullHelper.notnull(item.getRegistryName(), "found unregistered item"); return new LootEntryItem(item, 1, 1, new LootFunction[] { setCount(minStackSize, maxStackSize), setDamage(item, meta), setUpgrades(), setEnergy() }, chanceCond, registryName.toString() + ":" + meta); }
private @Nonnull LootEntry createLootCapacitor(float chance) { capCount++; return new LootEntryItem(itemBasicCapacitor.getItemNN(), 1, 1, new LootFunction[] { ls, setMetadata(3, 4) }, new LootCondition[] { new RandomChance(chance) }, itemBasicCapacitor.getUnlocalisedName() + capCount); }
/** * Builds the LootEntryItem so it can be used with vanilla MC. * * @return The LootEntryItem that was built. */ public LootEntryItem build () { return new LootEntryItem(this.item, this.weight, this.quality, this.functions.toArray(new LootFunction[0]), this.conditions.toArray(new LootCondition[0]), this.name); }