/** * 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; }
public static SetMetadata createSetMetadata(int meta) { return new SetMetadata(NO_CONDITIONS, new RandomValueRange(meta)); }
private @Nonnull SetMetadata setMetadata(int metaMin, int metaMax) { return new SetMetadata(NO_CONDITIONS, new RandomValueRange(metaMin, metaMax)); }
private @Nonnull SetMetadata setMetadata(int meta) { return new SetMetadata(NO_CONDITIONS, new RandomValueRange(meta)); }
/** * Creates a new loot entry that will be added to the loot pools when a world is loaded. * * @param location The loot table to add the loot to. You can use * {@link net.minecraft.world.storage.loot.LootTableList} for convenience. * @param name The name of the entry being added. This will be prefixed with {@link #modid} * . * @param pool The name of the pool to add the entry to. This pool must already exist. * @param weight The weight of the entry. * @param item The item to add. * @param meta The metadata for the loot. * @return A builder object. It can be used to fine tune the loot entry. */ public LootBuilder addLoot (ResourceLocation location, String name, String pool, int weight, Item item, int meta) { final LootBuilder loot = this.addLoot(location, name, pool, weight, item); loot.addFunction(new SetMetadata(new LootCondition[0], new RandomValueRange(meta, meta))); return loot; }