This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
SorceryCraft/src/main/java/com/thebrokenrail/sorcerycraft/spell/RandomSpellLootTableFunctio...

37 lines
1.2 KiB
Java

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<String, Integer> spell = new HashMap<>();
spell.put(spells[index].getID(), spells[index].getLevel());
SpellTag.setSpells(stack, spell);
return stack;
}
public static class Builder extends ConditionalLootFunction.Builder<RandomSpellLootTableFunction.Builder> {
@Override
protected RandomSpellLootTableFunction.Builder getThisBuilder() {
return this;
}
public LootFunction build() {
return new RandomSpellLootTableFunction(getConditions());
}
}
}