Search in sources :

Example 1 with LootEntry

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());
        }
    }
}
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)

Example 2 with LootEntry

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;
}
Also used : ParentedLootEntry(net.minecraft.loot.ParentedLootEntry) ParentedLootEntry(net.minecraft.loot.ParentedLootEntry) LootEntry(net.minecraft.loot.LootEntry)

Aggregations

LootEntry (net.minecraft.loot.LootEntry)2 ParentedLootEntry (net.minecraft.loot.ParentedLootEntry)2 Map (java.util.Map)1 Item (net.minecraft.item.Item)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 ILootCondition (net.minecraft.loot.conditions.ILootCondition)1 ResourceLocation (net.minecraft.util.ResourceLocation)1