Java Code Examples for net.minecraft.world.storage.loot.LootTable#generateLootForPools()
The following examples show how to use
net.minecraft.world.storage.loot.LootTable#generateLootForPools() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackpackDataItems.java From WearableBackpacks with MIT License | 6 votes |
public static void generateLoot(ItemStackHandler items, String tableStr, long seed, World world, EntityPlayer player) { Random rnd = new Random(seed); double maxFullness = (0.6 + rnd.nextDouble() * 0.2); int maxOccupiedSlots = (int)Math.ceil(items.getSlots() * maxFullness); LootTableManager manager = world.getLootTableManager(); LootTable table = manager.getLootTableFromLocation(new ResourceLocation(tableStr)); LootContext context = new LootContext(((player != null) ? player.getLuck() : 0), (WorldServer)world, manager, player, null, null); List<ItemStack> loot = table.generateLootForPools(rnd, context); Collections.shuffle(loot); List<Integer> randomizedSlots = new ArrayList<Integer>(items.getSlots()); for (int i = 0; i < items.getSlots(); i++) randomizedSlots.add(i); Collections.shuffle(randomizedSlots); for (int i = 0; (i < maxOccupiedSlots) && (i < loot.size()); i++) { ItemStack stack = loot.get(i); int slot = randomizedSlots.get(i); items.setStackInSlot(slot, stack); } }
Example 2
Source File: MetaTileEntityLockedSafe.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void generateChestContents() { ResourceLocation lootTableLocation = new ResourceLocation(GTValues.MODID, "chests/abandoned_safe_" + unlockComponentTier); WorldServer worldServer = (WorldServer) getWorld(); LootTable lootTable = worldServer.getLootTableManager().getLootTableFromLocation(lootTableLocation); LootContext lootContext = new LootContext.Builder(worldServer).build(); Random random = new Random(); List<ItemStack> loots = lootTable.generateLootForPools(random, lootContext); LootTableHelper.fillInventory(safeLootInventory, random, loots); }