New LootTable interaction system and event.

Modders can now modify and reference internal elements of a loot table by name.
Editing can ONLY be done in the event and any external editing will cause a exception to be thrown.
See this gist for more information: https://gist.github.com/LexManos/77c983d67b9ad27010428478b66d50fd
This commit is contained in:
LexManos committed 2016-05-09 14:15:59 -07:00
1 parent babd54bb87
commit aaa146c10d
14 files changed
+627

No files matched your search

@@ -0,0 +1,42 @@
package net.minecraftforge.debug;
import net.minecraft.init.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootEntryItem;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.functions.LootFunction;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid=LootTablesDebug.MODID)
public class LootTablesDebug {
public static final String MODID = "loot_table_debug";
private static final ResourceLocation CUSTOM_LOOT = LootTableList.register(new ResourceLocation(MODID, "custom_loot"));
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(this);
}
@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"
LootPool main = event.getTable().getPool("main"); //Note: This CAN NPE if another mod removes things
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");
}
}