Skip to content

Instantly share code, notes, and snippets.

@Darkhax
Last active October 15, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darkhax/4eff8d721a3e7f0b6861a430e8d7eab8 to your computer and use it in GitHub Desktop.
Save Darkhax/4eff8d721a3e7f0b6861a430e8d7eab8 to your computer and use it in GitHub Desktop.
@Mod(modid = "lta", name = "Loot Table Analysis", version = "1.0.0.0")
public class LootTableAnalysis {
private final Logger LOGGER = LogManager.getLogger("Loot Table Analysis");
private Field pools;
private Field lootEntries;
@EventHandler
public void preInit (FMLPreInitializationEvent event) {
pools = ReflectionHelper.findField(LootTable.class, "pools");
lootEntries = ReflectionHelper.findField(LootPool.class, "lootEntries");
MinecraftForge.EVENT_BUS.register(this);
}
@SuppressWarnings("unchecked")
@SubscribeEvent
public void onTableLoad(LootTableLoadEvent event) {
LOGGER.info("## " + event.getName());
try {
final List<LootPool> thePools = ((List<LootPool>) pools.get(event.getTable()));
if (thePools.isEmpty())
LOGGER.info("No entries for this table!");
else {
LOGGER.info(SystemUtils.LINE_SEPARATOR);
LOGGER.info("|Pool|Name|Item|Weight|");
LOGGER.info("|----|----|----|------|");
}
for (LootPool pool : thePools) {
for (LootEntry entry : ((List<LootEntry>) lootEntries.get(pool))) {
if (entry instanceof LootEntryItem) {
LootEntryItem item = (LootEntryItem) entry;
LOGGER.info(String.format("|%s|%s|%s|%d|", pool.getName(), entry.getEntryName(), item.item.getRegistryName().toString(), item.weight));
}
}
}
LOGGER.info(SystemUtils.LINE_SEPARATOR);
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment