List<ItemStack> stacks = world.getLootTableManager().getLootTableFromLocation(lootTable).generateLootForPools(rand, new LootContext.Builder((WorldServer) world).build()); if (stacks.isEmpty()) return;
private static void createPoolIfNotExists(LootTable lootTable, String poolId) { if (poolId.equals(VANILLA_LOOT_POOL_ID) || lootTable.getPool(poolId) != null) return; lootTable.addPool(new LootPool(new LootEntry[] {}, new LootCondition[] {}, new RandomValueRange(1), new RandomValueRange(0), poolId)); }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { ResourceLocation res = event.getName(); if(tablesToEdit.contains(res)) { if(customPools.containsKey(res)) customPools.get(res); event.getTable().getPool("main").addEntry(new LootEntryItem(Items.FILLED_MAP, rarity, quality, new LootFunction[] { new SetAsTreasureFunction() }, new LootCondition[0], "quark:treasure_map")); } }
@SubscribeEvent public void lootLoad(LootTableLoadEvent evt) { String prefix = "minecraft:chests/"; String name = evt.getName().toString(); if (name.startsWith(prefix)) { String file = name.substring(name.indexOf(prefix) + prefix.length()); switch (file) { case "abandoned_mineshaft": case "desert_pyramid": case "jungle_temple": case "simple_dungeon": case "spawn_bonus_chest": case "stronghold_corridor": case "village_blacksmith": evt.getTable().addPool(getInjectPool(file)); break; default: break; } } }
@SuppressWarnings("unchecked") public static void handleTable(LootTable table, ResourceLocation name) { boolean frozen = false; if (table.isFrozen()) {// Some mods like to replace the loot tables which ends up with the loot table table.addPool(Loot.pool("gracilaria").rolls(1, 1).chance(0.1F).entry(gracilaria).build()); } else if (name == LootTableList.CHESTS_VILLAGE_BLACKSMITH || name == LootTableList.CHESTS_NETHER_BRIDGE || name == LootTableList.CHESTS_SIMPLE_DUNGEON || name == LootTableList.CHESTS_STRONGHOLD_CORRIDOR table.addPool(Loot.pool("fossils").rolls(1, 2).entries(plantFossil, twig, amber, skull).build()); table.addPool(Loot.pool("records").rolls(0, 2).entries(records).build()); LootEntry amber = Loot.entry(ItemHandler.AMBER).data(0, 1).count(0, 3).build(); LootEntry wool = Loot.entry(Blocks.WOOL).data(0, 15).count(0, 64).build(); table.addPool(Loot.pool("items").rolls(5, 6).entries(amber, wool).build()); } else if (name.getResourcePath().equals(Loot.VISITOR_LABORATORY.getResourcePath())) { LootEntry softTissue = Loot.entry(ItemHandler.SOFT_TISSUE).count(0, 3).function(DINOSAUR_DATA).build(); LootEntry amber = Loot.entry(ItemHandler.AMBER).data(0, 1).count(0, 5).build(); LootEntry dna = Loot.entry(ItemHandler.DNA).function(DINOSAUR_DATA).function(RANDOM_DNA).build(); table.addPool(Loot.pool("items").rolls(3, 4).entries(dna, softTissue, plantSoftTissue, amber).build()); } else if (name.getResourcePath().equals(Loot.VISITOR_DINING_HALL.getResourcePath())) { LootEntry amber = Loot.entry(ItemHandler.AMBER).weight(2).count(0, 1).data(0, 1).build(); LootEntry actionFigure = Loot.entry(ItemHandler.DISPLAY_BLOCK_ITEM).function(DINOSAUR_DATA).weight(1) .build(); table.addPool(Loot.pool("items").rolls(8, 11).entries(amber, tooth, actionFigure).build()); } else if (name.getResourcePath().equals(Loot.VISITOR_KITCHEN.getResourcePath())) { LootEntry waterBottle = Loot.entry(Items.POTIONITEM).count(0, 1).function(POTION_DATA).build();
if (table.isFrozen()) { throw new RuntimeException("Some other mod (a list of suspects is printed in the log file) put a frozen loot table into the load event for loot table '" + evt.getName() + "'. This is a bug in that other mod. Ender IO is the victim here. Don't blame the victim!"); table.addPool(lp);
public void fillWithLoot(@Nullable EntityPlayer player) { if (this.lootTable != null && this.world != null && this.world.getLootTableManager() != null) { LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable); this.lootTable = null; Random random; if (this.lootTableSeed == 0L) { random = new Random(); } else { random = new Random(this.lootTableSeed); } LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world); if (player != null) { lootcontext$builder.withLuck(player.getLuck()).withPlayer(player); // Forge: add player to LootContext } loottable.fillInventory(this, random, lootcontext$builder.build()); } }
@SubscribeEvent public void onLootLoading(LootTableLoadEvent event) { if (event.getName().toString().equals("minecraft:gameplay/fishing")) { LootPool pool = event.getTable().getPool("main"); if (pool != null) { for (String name : LOOT_TABLES) { LootEntry entry = pool.getEntry("minecraft:" + name); if (entry != null) { pool.addEntry(getEntry(MODID + "_" + name.replace(FISHING, ""), name, getVanillaQuality(entry), getVanillaWeight(entry))); } } } } }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { if(SPAGHETTI_LOCATIONS.contains(event.getName().toString())) { event.getTable().addPool(pool); } } }
@Override public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) { if (world.isRemote || System.getProperty("INDEV") == null || !player.isCreative()) { return EnumActionResult.PASS; } TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) te; chest.clear(); LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world); lootcontext$builder.withLuck(player.getLuck()); LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_SIMPLE_DUNGEON); // LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_IGLOO_CHEST); loottable.fillInventory(chest, world.rand, lootcontext$builder.build()); return EnumActionResult.PASS; } else { IBlockState blockState = world.getBlockState(pos); int meta = blockState.getBlock().getMetaFromState(blockState); player.sendMessage(new TextComponentString(blockState + " (" + meta + ")")); } return EnumActionResult.PASS; }
public static void fillInventory(LootTable table, IItemHandlerModifiable inventory, Random rand, LootContext context){ List<ItemStack> list = table.generateLootForPools(rand, context); List<Integer> list1 = getEmptySlotsRandomized(inventory, rand); shuffleItems(list, list1.size(), rand); for(ItemStack itemstack : list){ if(itemstack.isEmpty()){ inventory.setStackInSlot(list1.remove(list1.size()-1), ItemStack.EMPTY); } else{ inventory.setStackInSlot(list1.remove(list1.size()-1), itemstack); } } }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { LootPool main = event.getTable().getPool(LOOTPOOLNAME); if (main == null) { //create my own. EX: mobs that have no drops (bats) also have empty loot table, so i have to inject an entry in the table before I fill it event.getTable().addPool(new LootPool(new LootEntry[0], new LootCondition[0], new RandomValueRange(1F, 2F), new RandomValueRange(1F, 1F), LOOTPOOLNAME)); main = event.getTable().getPool(LOOTPOOLNAME); if (main == null) { ModCyclic.logger.error("could not insert Loot Pool for table :" + event.getName().toString()); return; } } if (enableChestLoot) { onLootChestTableLoad(main, event); } }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { LootFunction[] funcs = new LootFunction[] { new SetMetadata(new LootCondition[0], new RandomValueRange(0, enableRainbowRuneChests ? 16 : 15)) }; if(event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) event.getTable().getPool("main").addEntry(new LootEntryItem(rune, dungeonWeight, itemQuality, funcs, new LootCondition[0], "quark:rune")); else if(event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE)) event.getTable().getPool("main").addEntry(new LootEntryItem(rune, netherFortressWeight, itemQuality, funcs, new LootCondition[0], "quark:rune")); else if(event.getName().equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) event.getTable().getPool("main").addEntry(new LootEntryItem(rune, jungleTempleWeight, itemQuality, funcs, new LootCondition[0], "quark:rune")); else if(event.getName().equals(LootTableList.CHESTS_DESERT_PYRAMID)) event.getTable().getPool("main").addEntry(new LootEntryItem(rune, desertTempleWeight, itemQuality, funcs, new LootCondition[0], "quark:rune")); }
@SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { // wither skellies drop necrotic bones if(event.getName().equals(LootTableList.ENTITIES_WITHER_SKELETON)) { LootCondition[] lootConditions = new LootCondition[0]; LootEntry entry = new LootEntryItem(TinkerCommons.matNecroticBone.getItem(), 1, 0, new LootFunction[]{new SetMetadata(lootConditions, new RandomValueRange(TinkerCommons.matNecroticBone.getMetadata()))}, lootConditions, "necrotic_bone"); event.getTable().addPool(new LootPool(new LootEntry[]{entry}, new LootCondition[]{ new KilledByPlayer(false), new RandomChanceWithLooting(0.07f, 0.05f) }, new RandomValueRange(1), new RandomValueRange(0), "necrotic_bone")); } }
public static ItemStack getStack(World world, EntityPlayer player, ResourceLocation lootTable) { long lootTableSeed = world.rand.nextLong(); LootTable loottable = world.getLootTableManager().getLootTableFromLocation(lootTable); Random random; if (lootTableSeed == 0L) { random = new Random(); } else { random = new Random(lootTableSeed); } LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer)world); if (player != null) { lootcontext$builder.withLuck(player.getLuck()); } loottable.fillInventory(INVENTORY, random, lootcontext$builder.build()); ItemStack result = INVENTORY.getStackInSlot(0); if (result != null) result = result.copy(); INVENTORY.setInventorySlotContents(0, null); return result; } }
/** * Return some random loot of a defined lootTable. * * @param lootTable the lootTable. * @return the ItemStack of the loot. */ private ItemStack getLootForLootTable(final ResourceLocation lootTable) { final LootContext.Builder lootContextBuilder = new LootContext.Builder((WorldServer) CompatibilityUtils.getWorld(this)); return CompatibilityUtils.getWorld(this).getLootTableManager() .getLootTableFromLocation(lootTable) .generateLootForPools(this.rand, lootContextBuilder.build()).stream().findFirst().orElse(null); }
@SubscribeEvent public void lootLoad(LootTableLoadEvent event) { if (!event.getName().getNamespace().equals("minecraft") && !event.getName().equals(Constants.VILLAGE_NATURALIST_LOOT_KEY)) { return; } Set<String> lootPoolNames = ModuleManager.getLootPoolNames(); for (String lootTableFile : ModuleManager.getLootTableFiles()) { ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, event.getName().getPath() + "/" + lootTableFile); URL url = EventHandlerCore.class.getResource("/assets/" + resourceLocation.getNamespace() + "/loot_tables/" + resourceLocation.getPath() + ".json"); if (url != null) { LootTable forestryChestAdditions = event.getLootTableManager().getLootTableFromLocation(resourceLocation); if (forestryChestAdditions != LootTable.EMPTY_LOOT_TABLE) { for (String poolName : lootPoolNames) { LootPool pool = forestryChestAdditions.getPool(poolName); if (pool != null) { event.getTable().addPool(pool); } } } } } }
@SubscribeEvent public void onChestGenerated(LootTableLoadEvent event) { if (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) { final LootPool pool1 = event.getTable().getPool("pool1"); if (pool1 != null) { pool1.addEntry(new LootEntryItem(ModItems.manuscript, 10, 5, new LootFunction[0], new LootCondition[0], "iceandfire:manuscript")); } } }
@SubscribeEvent public void loadLootTable( LootTableLoadEvent event ) { if( event.getName() == LootTableList.CHESTS_ABANDONED_MINESHAFT ) { // TODO 1.9.4 aftermath - All these loot quality, pools and stuff. Figure it out and balance it. final IMaterials materials = AEApi.instance().definitions().materials(); materials.certusQuartzCrystal().maybeStack( 1 ).ifPresent( is -> { event.getTable() .addPool( new LootPool( new LootEntry[] { new LootEntryItem( is.getItem(), 2, 3, new LootFunction[] { new SetMetadata( null, new RandomValueRange( is.getItemDamage() ) ) }, new LootCondition[] { new RandomChance( 1 ) }, "AE2 Crystal_" + is.getItemDamage() ) }, new LootCondition[0], new RandomValueRange( 1, 4 ), new RandomValueRange( 0, 2 ), "AE2 Crystals" ) ); } ); materials.certusQuartzDust().maybeStack( 1 ).ifPresent( is -> { event.getTable() .addPool( new LootPool( new LootEntryItem[] { new LootEntryItem( is.getItem(), 2, 3, new LootFunction[] { new SetMetadata( null, new RandomValueRange( is.getItemDamage() ) ) }, new LootCondition[] { new RandomChance( 1 ) }, "AE2 Dust_" + is.getItemDamage() ) }, new LootCondition[0], new RandomValueRange( 1, 4 ), new RandomValueRange( 0, 2 ), "AE2 DUSTS" ) ); } ); } }
@Override public void safeUpdate() { Pair<Chunk, Integer> pair = randSourceBlock(); int src = pair.getRight(); if (getSteamShare() > src) { decrSteam(src); if (world.rand.nextInt((int) (300.0F / src)) == 0 && !world.isRemote) { Chunk loc = pair.getLeft(); LootContext lootContext = new LootContext.Builder((WorldServer) world).build(); List<ItemStack> fishes = world.getLootTableManager().getLootTableFromLocation( LootTableList.GAMEPLAY_FISHING_FISH).generateLootForPools(world.rand, lootContext); ItemStack output = fishes.get(world.rand.nextInt(fishes.size())); ItemStack smeltingResult = FurnaceRecipes.instance().getSmeltingResult(output); if (smeltingResult != null) { output = smeltingResult; } dropItem(output, loc.x + 0.5F, pos.getY() + 1.0F, loc.z + 0.5F); } } super.safeUpdate(); }