Have the elements of spectral dust in the receptacles affect the element weighting for the resulting spell book

This commit is contained in:
Electroblob77
2020-09-21 16:43:51 +01:00
parent 93d2100546
commit 2c95793293
10 changed files with 293 additions and 24 deletions
@@ -1,6 +1,7 @@
package electroblob.wizardry.registry;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.loot.RandomSpell;
import electroblob.wizardry.loot.WizardSpell;
import net.minecraft.entity.EnumCreatureType;
@@ -28,7 +29,9 @@ public final class WizardryLoot {
//public static final String FROM_SPAWNER_NBT_FLAG = "fromSpawner";
public static final ResourceLocation RUINED_SPELL_BOOK_LOOT_TABLE = new ResourceLocation(Wizardry.MODID, "gameplay/imbuement_altar/ruined_spell_book");
public static final ResourceLocation[] RUINED_SPELL_BOOK_LOOT_TABLES = Arrays.stream(Element.values()).map(e ->
new ResourceLocation(Wizardry.MODID, "gameplay/imbuement_altar/ruined_spell_book_" + e.getName()))
.toArray(ResourceLocation[]::new);
private WizardryLoot(){} // No instances!
@@ -71,7 +74,7 @@ public final class WizardryLoot {
LootTableList.register(new ResourceLocation(Wizardry.MODID, "entities/mob_additions"));
LootTableList.register(new ResourceLocation(Wizardry.MODID, "gameplay/fishing/junk_additions"));
LootTableList.register(new ResourceLocation(Wizardry.MODID, "gameplay/fishing/treasure_additions"));
LootTableList.register(RUINED_SPELL_BOOK_LOOT_TABLE);
for(ResourceLocation location : RUINED_SPELL_BOOK_LOOT_TABLES) LootTableList.register(location);
}
@@ -259,7 +259,14 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
if(fullLootGen){
LootTable table = world.getLootTableManager().getLootTableFromLocation(WizardryLoot.RUINED_SPELL_BOOK_LOOT_TABLE);
// Pick a random element out of the receptacles and use its loot table
// This is an elegant way of having the dust elements affect the spell outcome without hardcoding
// any actual numbers, thus allowing packmakers as much control as possible over the weighting
// The probabilities are a little complicated but work out quite nicely at 57% chance with 4 of the
// same element of spectral dust
Element element = receptacleElements[world.rand.nextInt(receptacleElements.length)];
LootTable table = world.getLootTableManager().getLootTableFromLocation(
WizardryLoot.RUINED_SPELL_BOOK_LOOT_TABLES[element.ordinal() - 1]);
LootContext context = new LootContext.Builder((WorldServer)world).withPlayer(lastUser)
.withLuck(lastUser == null ? 0 : lastUser.getLuck()).build();