package com.thebrokenrail.sorcerycraft.spell; import java.util.HashMap; import java.util.Map; import net.minecraft.item.ItemStack; import net.minecraft.loot.condition.LootCondition; import net.minecraft.loot.context.LootContext; import net.minecraft.loot.function.ConditionalLootFunction; import net.minecraft.loot.function.LootFunction; public class RandomSpellLootTableFunction extends ConditionalLootFunction { private RandomSpellLootTableFunction(LootCondition[] conditions) { super(conditions); } public ItemStack process(ItemStack stack, LootContext context) { Spell[] spells = SpellRegistry.getSpells(); int index = context.getRandom().nextInt(spells.length); Map spell = new HashMap<>(); spell.put(spells[index].getID(), spells[index].getLevel()); SpellTag.setSpells(stack, spell); return stack; } public static class Builder extends ConditionalLootFunction.Builder { @Override protected RandomSpellLootTableFunction.Builder getThisBuilder() { return this; } public LootFunction build() { return new RandomSpellLootTableFunction(getConditions()); } } }