Search in sources :

Example 1 with LootPredicateManager

use of net.minecraft.loot.LootPredicateManager 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());
        }
    }
}
Also used : LootTable(net.minecraft.loot.LootTable) Item(net.minecraft.item.Item) ParentedLootEntry(net.minecraft.loot.ParentedLootEntry) LootEntry(net.minecraft.loot.LootEntry) LootPredicateManager(net.minecraft.loot.LootPredicateManager) ResourceLocation(net.minecraft.util.ResourceLocation) LootTableManager(net.minecraft.loot.LootTableManager) LootPool(net.minecraft.loot.LootPool) ILootCondition(net.minecraft.loot.conditions.ILootCondition) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 Item (net.minecraft.item.Item)1 LootEntry (net.minecraft.loot.LootEntry)1 LootPool (net.minecraft.loot.LootPool)1 LootPredicateManager (net.minecraft.loot.LootPredicateManager)1 LootTable (net.minecraft.loot.LootTable)1 LootTableManager (net.minecraft.loot.LootTableManager)1 ParentedLootEntry (net.minecraft.loot.ParentedLootEntry)1 ILootCondition (net.minecraft.loot.conditions.ILootCondition)1 ResourceLocation (net.minecraft.util.ResourceLocation)1