Search in sources :

Example 1 with LootPool

use of net.minecraft.world.storage.loot.LootPool in project MinecraftForge by MinecraftForge.

the class LootTablesDebug method lootLoad.

@SubscribeEvent
public void lootLoad(LootTableLoadEvent event) {
    if (!event.getName().equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST))
        return;
    // Remove axes and replace with chestpeice, First vanilla entry is always called "main"
    //Note: This CAN NPE if another mod removes things
    LootPool main = event.getTable().getPool("main");
    main.removeEntry("minecraft:wooden_axe");
    main.removeEntry("minecraft:stone_axe");
    main.addEntry(new LootEntryItem(Items.DIAMOND_CHESTPLATE, 1, 0, new LootFunction[0], new LootCondition[0], MODID + ":diamond_chestplate"));
    // Get rid of all building mats. Which is pool #3, index starts at 0, but 0 is named "main"
    event.getTable().removePool("pool3");
}
Also used : LootEntryItem(net.minecraft.world.storage.loot.LootEntryItem) LootFunction(net.minecraft.world.storage.loot.functions.LootFunction) LootPool(net.minecraft.world.storage.loot.LootPool) LootCondition(net.minecraft.world.storage.loot.conditions.LootCondition) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with LootPool

use of net.minecraft.world.storage.loot.LootPool in project ImmersiveEngineering by BluSunrize.

the class EventHandler method lootLoad.

@SubscribeEvent
public void lootLoad(LootTableLoadEvent event) {
    if (event.getName().getResourceDomain().equals("minecraft"))
        for (ResourceLocation inject : lootInjections) if (event.getName().getResourcePath().equals(inject.getResourcePath())) {
            LootPool injectPool = Utils.loadBuiltinLootTable(inject).getPool("immersiveengineering_loot_inject");
            LootPool mainPool = event.getTable().getPool("main");
            if (injectPool != null && mainPool != null)
                try {
                    if (f_lootEntries == null) {
                        //field_186453_a is srg for lootEntries
                        f_lootEntries = LootPool.class.getDeclaredField(ObfuscationReflectionHelper.remapFieldNames(LootPool.class.getName(), "field_186453_a")[0]);
                        f_lootEntries.setAccessible(true);
                    }
                    if (f_lootEntries != null) {
                        List<LootEntry> entryList = (List<LootEntry>) f_lootEntries.get(injectPool);
                        for (LootEntry entry : entryList) mainPool.addEntry(entry);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }
}
Also used : LootEntry(net.minecraft.world.storage.loot.LootEntry) ResourceLocation(net.minecraft.util.ResourceLocation) LootPool(net.minecraft.world.storage.loot.LootPool) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

LootPool (net.minecraft.world.storage.loot.LootPool)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ResourceLocation (net.minecraft.util.ResourceLocation)1 LootEntry (net.minecraft.world.storage.loot.LootEntry)1 LootEntryItem (net.minecraft.world.storage.loot.LootEntryItem)1 LootCondition (net.minecraft.world.storage.loot.conditions.LootCondition)1 LootFunction (net.minecraft.world.storage.loot.functions.LootFunction)1