package electroblob.wizardry.registry; import electroblob.wizardry.Wizardry; import electroblob.wizardry.constants.Tier; import electroblob.wizardry.loot.RandomSpell; import electroblob.wizardry.loot.WizardSpell; import electroblob.wizardry.spell.Spell; import net.minecraft.entity.EnumCreatureType; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.loot.*; import net.minecraft.world.storage.loot.conditions.LootCondition; import net.minecraft.world.storage.loot.functions.LootFunctionManager; import net.minecraftforge.event.LootTableLoadEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.ForgeRegistries; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.function.Predicate; /** * Class responsible for registering wizardry's loot functions and loot tables. Also handles loot injection and the * standard weighting. * * @author Electroblob * @since Wizardry 1.0 */ @Mod.EventBusSubscriber public final class WizardryLoot { //public static final String FROM_SPAWNER_NBT_FLAG = "fromSpawner"; private WizardryLoot(){} // No instances! /** Called from the preInit method in the main mod class to register the custom dungeon loot. */ public static void register(){ /* Loot tables work as follows: Minecraft goes through each pool in turn. For each pool, it does a certain * number of rolls, which can either be set to always be one number or a random number from a range. Each roll, * it generates one stack of a single random entry in that pool, weighted according to the weights of the * entries. Functions allow properties of that stack (stack size, damage, nbt) to be set, and even allow it to * be replaced dynamically with a completely different item (though there's very little point in doing that as * it could be achieved just as easily with more entries, which makes me think it would be bad practice). You * can also use conditions to control whether an entry or pool is used at all, which is mostly for mob drops * under specific conditions, but one of them is simply a random chance, meaning you could use it to make a pool * that only gets rolled sometimes. All in all, this can get rather confusing, because stackable items can have * 5 stages of randomness applied to them at once: a random chance for the pool, a random number of rolls for * the pool, the weighted random chance of choosing that particular entry, a random chance for that entry, and a * random stack size, and that's before you take functions into account. * * ...oh, and entries can be entire loot tables in themselves, allowing for potentially infinite levels of * randomness. Yeah. */ // Always registers the loot tables, but only injects the additions into vanilla if the appropriate option is // enabled in the config (see WizardryEventHandler). LootFunctionManager.registerFunction(new RandomSpell.Serializer()); LootFunctionManager.registerFunction(new WizardSpell.Serializer()); LootTableList.register(new ResourceLocation(Wizardry.MODID, "chests/wizard_tower")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "chests/obelisk")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "chests/shrine")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "chests/dungeon_additions")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "chests/jungle_dispenser_additions")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/elemental_crystals")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/wizard_armour")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/arcane_tomes")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/wand_upgrades")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/uncommon_artefacts")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/rare_artefacts")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "subsets/epic_artefacts")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "entities/evil_wizard")); LootTableList.register(new ResourceLocation(Wizardry.MODID, "entities/mob_additions")); } /** * Helper method which gets a spell id according to the standard weighting. The tier is a weighted random value; the * actual spell within that tier is completely random. Will not return the id of a spell which has been disabled in * the config. This is for simple stuff like chests and drops; more complex generators like wizard trades don't use * this method. *
* For reference, the standard weighting is as follows: Novice: 60%, Apprentice: 25%, Advanced: 10%, Master: 5% * * @param random An instance of {@link Random} to use for RNG * @param filter A {@link Predicate} specifying any requirements the chosen spell must fulfil * @return A random spell id number, or -1 if no spell exists that satisfies the given filter * @deprecated Everything uses loot tables now, I may remove this as some point */ @Deprecated public static int getStandardWeightedRandomSpellId(Random random, Predicate