use of net.minecraft.loot.LootEntry in project Mekanism by mekanism.
the class LootTableModifierReloadListener method onResourceManagerReload.
@Override
public void onResourceManagerReload(@Nonnull IResourceManager resourceManager) {
// Grab the current shears tag instance as we will be doing identity compares and even if we weren't
// the named wrapper for the tag won't be populated yet
ITag<Item> shearsTag = dataPackRegistries.getTags().getItems().getTag(new ResourceLocation("forge", "shears"));
LootTableManager lootTableManager = dataPackRegistries.getLootTables();
for (ResourceLocation id : lootTableManager.getIds()) {
LootTable lootTable = lootTableManager.get(id);
boolean modified = false;
// Scan all the loot tables in the upcoming/"current" loot table manager and evaluate if their pools need modifying
for (LootPool pool : LOOT_TABLE_POOLS.getValue(lootTable)) {
// 2. As the conditions to the loot pool itself
for (LootEntry entry : LOOT_POOL_ENTRIES.getValue(pool)) {
modified |= modifyEntry(entry, shearsTag);
}
for (ILootCondition condition : LOOT_POOL_CONDITIONS.getValue(pool)) {
modified |= modifyCondition(condition, shearsTag);
}
}
if (modified) {
// If we changed any of the conditions in this loot table, add a debug message stating that we did so
Mekanism.logger.debug("Modified and wrapped condition(s) in loot table '{}' to support items with the tool type of shears.", id);
}
}
// We also need to scan all loot predicate in the upcoming/"current" manager, given even though vanilla doesn't add
// any predicates by default that have to do with shears, we want to make sure we catch any that may be defined by
// a mod or data pack
LootPredicateManager predicateManager = dataPackRegistries.getPredicateManager();
for (Map.Entry<ResourceLocation, ILootCondition> entry : LOOT_PREDICATE_CONDITIONS.getValue(predicateManager).entrySet()) {
if (modifyCondition(entry.getValue(), shearsTag)) {
// If we changed any of the conditions in this loot predicate, add a debug message stating that we did so
Mekanism.logger.debug("Modified and wrapped condition for loot predicate '{}' to support items with the tool type of shears.", entry.getKey());
}
}
}
use of net.minecraft.loot.LootEntry in project Mekanism by mekanism.
the class LootTableModifierReloadListener method modifyEntry.
private static boolean modifyEntry(LootEntry entry, ITag<Item> shearsTag) {
boolean modified = false;
if (entry instanceof ParentedLootEntry) {
// If the entry is a parented loot entry, check if any of the child entries need their conditions modified
for (LootEntry child : PARENTED_LOOT_ENTRY_CHILDREN.getValue((ParentedLootEntry) entry)) {
modified |= modifyEntry(child, shearsTag);
}
}
// Check if the entry has any conditions that need modifying. This will happen for all entry types including parented ones
modified |= modifyConditions(LOOT_ENTRY_CONDITIONS.getValue(entry), shearsTag);
// in a different way but there isn't much that can be done about that
return modified;
}
Aggregations