Search in sources :

Example 1 with AlternativeLootItemCondition

use of net.minecraft.world.level.storage.loot.predicates.AlternativeLootItemCondition in project MinecraftForge by MinecraftForge.

the class ForgeLootTableProvider method findAndReplaceInLootPool.

private boolean findAndReplaceInLootPool(LootPool lootPool, Item from, ToolAction toolAction) {
    LootPoolEntryContainer[] lootEntries = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" + "3_");
    LootItemCondition[] lootConditions = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" + "4_");
    boolean found = false;
    if (lootEntries == null) {
        throw new IllegalStateException(LootPool.class.getName() + " is missing field f_7902" + "3_");
    }
    for (LootPoolEntryContainer lootEntry : lootEntries) {
        if (findAndReplaceInLootEntry(lootEntry, from, toolAction)) {
            found = true;
        }
        if (lootEntry instanceof CompositeEntryBase) {
            if (findAndReplaceInParentedLootEntry((CompositeEntryBase) lootEntry, from, toolAction)) {
                found = true;
            }
        }
    }
    if (lootConditions == null) {
        throw new IllegalStateException(LootPool.class.getName() + " is missing field f_7902" + "4_");
    }
    for (int i = 0; i < lootConditions.length; i++) {
        LootItemCondition lootCondition = lootConditions[i];
        if (lootCondition instanceof MatchTool && checkMatchTool((MatchTool) lootCondition, from)) {
            lootConditions[i] = CanToolPerformAction.canToolPerformAction(toolAction).build();
            found = true;
        } else if (lootCondition instanceof InvertedLootItemCondition) {
            LootItemCondition invLootCondition = ObfuscationReflectionHelper.getPrivateValue(InvertedLootItemCondition.class, (InvertedLootItemCondition) lootCondition, "f_8168" + "1_");
            if (invLootCondition instanceof MatchTool && checkMatchTool((MatchTool) invLootCondition, from)) {
                lootConditions[i] = InvertedLootItemCondition.invert(CanToolPerformAction.canToolPerformAction(toolAction)).build();
                found = true;
            } else if (invLootCondition instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) invLootCondition, from, toolAction)) {
                found = true;
            }
        }
    }
    return found;
}
Also used : InvertedLootItemCondition(net.minecraft.world.level.storage.loot.predicates.InvertedLootItemCondition) InvertedLootItemCondition(net.minecraft.world.level.storage.loot.predicates.InvertedLootItemCondition) AlternativeLootItemCondition(net.minecraft.world.level.storage.loot.predicates.AlternativeLootItemCondition) LootItemCondition(net.minecraft.world.level.storage.loot.predicates.LootItemCondition) MatchTool(net.minecraft.world.level.storage.loot.predicates.MatchTool) CompositeEntryBase(net.minecraft.world.level.storage.loot.entries.CompositeEntryBase) AlternativeLootItemCondition(net.minecraft.world.level.storage.loot.predicates.AlternativeLootItemCondition) LootPoolEntryContainer(net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer) LootPool(net.minecraft.world.level.storage.loot.LootPool)

Aggregations

LootPool (net.minecraft.world.level.storage.loot.LootPool)1 CompositeEntryBase (net.minecraft.world.level.storage.loot.entries.CompositeEntryBase)1 LootPoolEntryContainer (net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer)1 AlternativeLootItemCondition (net.minecraft.world.level.storage.loot.predicates.AlternativeLootItemCondition)1 InvertedLootItemCondition (net.minecraft.world.level.storage.loot.predicates.InvertedLootItemCondition)1 LootItemCondition (net.minecraft.world.level.storage.loot.predicates.LootItemCondition)1 MatchTool (net.minecraft.world.level.storage.loot.predicates.MatchTool)1