diff --git a/Common/src/main/java/at/petrak/hexcasting/api/misc/ScrollQuantity.java b/Common/src/main/java/at/petrak/hexcasting/api/misc/ScrollQuantity.java new file mode 100644 index 00000000..31ec39f9 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/api/misc/ScrollQuantity.java @@ -0,0 +1,24 @@ +package at.petrak.hexcasting.api.misc; + +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import static at.petrak.hexcasting.api.HexAPI.modLoc; + +public enum ScrollQuantity { + NONE(null), + FEW(modLoc("inject/scroll_loot_few")), + SOME(modLoc("inject/scroll_loot_some")), + MANY(modLoc("inject/scroll_loot_many")); + + private final ResourceLocation pool; + + ScrollQuantity(ResourceLocation pool) { + this.pool = pool; + } + + @Nullable + public ResourceLocation getPool() { + return pool; + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java index d1b59ecb..6ff9e67b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexConfig.java @@ -2,10 +2,13 @@ package at.petrak.hexcasting.api.mod; import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.misc.ManaConstants; +import at.petrak.hexcasting.api.misc.ScrollQuantity; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tiers; +import java.util.List; + public class HexConfig { public interface CommonConfigAccess { @@ -46,9 +49,14 @@ public class HexConfig { boolean doVillagersTakeOffenseAtMindMurder(); + ScrollQuantity scrollsForLootTable(ResourceLocation lootTable); + int DEFAULT_MAX_RECURSE_DEPTH = 64; int DEFAULT_MAX_SPELL_CIRCLE_LENGTH = 1024; int DEFAULT_OP_BREAK_HARVEST_LEVEL = 3; + List DEFAULT_FEW_SCROLL_TABLES = List.of("minecraft:chests/jungle_temple", "minecraft:chests/simple_dungeon", "minecraft:chests/village/village_cartographer"); + List DEFAULT_SOME_SCROLL_TABLES = List.of("minecraft:chests/bastion_treasure", "minecraft:chests/shipwreck_map"); + List DEFAULT_MANY_SCROLL_TABLES = List.of("minecraft:chests/stronghold_library"); // We can't have default values for the break harvest level or if default Tier opBreakHarvestLevel() { @@ -63,6 +71,15 @@ public class HexConfig { } } + // Simple extensions for resource location configs + public static boolean anyMatch(List keys, ResourceLocation key) { + return keys.stream().map(ResourceLocation::new).anyMatch(key::equals); + } + + public static boolean noneMatch(List keys, ResourceLocation key) { + return keys.stream().map(ResourceLocation::new).noneMatch(key::equals); + } + // oh man this is aesthetically pleasing private static CommonConfigAccess common = null; private static ClientConfigAccess client = null; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/loot/HexLootHandler.java b/Common/src/main/java/at/petrak/hexcasting/common/loot/HexLootHandler.java index 0b1abf6b..493448b0 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/loot/HexLootHandler.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/loot/HexLootHandler.java @@ -1,5 +1,7 @@ package at.petrak.hexcasting.common.loot; +import at.petrak.hexcasting.api.misc.ScrollQuantity; +import at.petrak.hexcasting.api.mod.HexConfig; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.storage.loot.LootPool; @@ -21,20 +23,12 @@ public class HexLootHandler { Consumer addPool) { if (id.equals(Blocks.AMETHYST_CLUSTER.getLootTable())) { addPool.accept(getInjectPool(TABLE_INJECT_AMETHYST_CLUSTER)); - } else if ( - id.equals(new ResourceLocation("minecraft:chests/jungle_temple")) - || id.equals(new ResourceLocation("minecraft:chests/simple_dungeon")) - || id.equals(new ResourceLocation("minecraft:chests/village/village_cartographer")) - ) { - addPool.accept(getInjectPool(modLoc("inject/scroll_loot_few"))); - } else if ( - id.equals(new ResourceLocation("minecraft:chests/bastion_treasure")) - || id.equals(new ResourceLocation("minecraft:chests/shipwreck_map")) - ) { - addPool.accept(getInjectPool(modLoc("inject/scroll_loot_some"))); - } else if (id.equals(new ResourceLocation("minecraft:chests/stronghold_library")) - ) { - addPool.accept(getInjectPool(modLoc("inject/scroll_loot_many"))); + } else { + ScrollQuantity scrolls = HexConfig.server().scrollsForLootTable(id); + ResourceLocation injection = scrolls.getPool(); + if (injection != null) { + addPool.accept(getInjectPool(injection)); + } } } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java index ddc8f3e5..4775ad2f 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexConfig.java @@ -1,6 +1,7 @@ package at.petrak.hexcasting.fabric; import at.petrak.hexcasting.api.HexAPI; +import at.petrak.hexcasting.api.misc.ScrollQuantity; import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.xplat.IXplatAbstractions; import io.github.fablabsmc.fablabs.api.fiber.v1.builder.ConfigTreeBuilder; @@ -16,6 +17,9 @@ import java.io.*; import java.nio.file.*; import java.util.List; +import static at.petrak.hexcasting.api.mod.HexConfig.anyMatch; +import static at.petrak.hexcasting.api.mod.HexConfig.noneMatch; + // https://github.com/VazkiiMods/Botania/blob/1.18.x/Fabric/src/main/java/vazkii/botania/fabric/FiberBotaniaConfig.java public class FabricHexConfig { private static final Common COMMON = new Common(); @@ -161,6 +165,12 @@ public class FabricHexConfig { ConfigTypes.makeList(ConfigTypes.STRING)); private final PropertyMirror villagersOffendedByMindMurder = PropertyMirror.create( ConfigTypes.BOOLEAN); + private final PropertyMirror> fewScrollTables = PropertyMirror.create( + ConfigTypes.makeList(ConfigTypes.STRING)); + private final PropertyMirror> someScrollTables = PropertyMirror.create( + ConfigTypes.makeList(ConfigTypes.STRING)); + private final PropertyMirror> manyScrollTables = PropertyMirror.create( + ConfigTypes.makeList(ConfigTypes.STRING)); public ConfigTree configure(ConfigTreeBuilder bob) { bob.fork("Spells") @@ -190,7 +200,21 @@ public class FabricHexConfig { .beginValue("villagersOffendedByMindMurder", ConfigTypes.BOOLEAN, true) .withComment("Should villagers take offense when you flay the mind of their fellow villagers?") - .finishValue(villagersOffendedByMindMurder::mirror); + .finishValue(villagersOffendedByMindMurder::mirror) + + .fork("Scrolls in Loot") + .beginValue("fewScrollTables", ConfigTypes.makeList(ConfigTypes.STRING), DEFAULT_FEW_SCROLL_TABLES) + .withComment("Which loot tables should a small number of Ancient Scrolls be injected into?") + .finishValue(fewScrollTables::mirror) + + .beginValue("someScrollTables", ConfigTypes.makeList(ConfigTypes.STRING), DEFAULT_SOME_SCROLL_TABLES) + .withComment("Which loot tables should a decent number of Ancient Scrolls be injected into?") + .finishValue(someScrollTables::mirror) + + .beginValue("manyScrollTables", ConfigTypes.makeList(ConfigTypes.STRING), DEFAULT_MANY_SCROLL_TABLES) + .withComment("Which loot tables should a huge number of Ancient Scrolls be injected into?") + .finishValue(manyScrollTables::mirror) + .finishBranch(); return bob.build(); } @@ -212,17 +236,28 @@ public class FabricHexConfig { @Override public boolean isActionAllowed(ResourceLocation actionID) { - return !actionDenyList.getValue().contains(actionID.toString()); + return noneMatch(actionDenyList.getValue(), actionID); } @Override public boolean isActionAllowedInCircles(ResourceLocation actionID) { - return !circleActionDenyList.getValue().contains(actionID.toString()); + return noneMatch(circleActionDenyList.getValue(), actionID); } @Override public boolean doVillagersTakeOffenseAtMindMurder() { return villagersOffendedByMindMurder.getValue(); } + + @Override + public ScrollQuantity scrollsForLootTable(ResourceLocation lootTable) { + if (anyMatch(fewScrollTables.getValue(), lootTable)) + return ScrollQuantity.FEW; + else if (anyMatch(someScrollTables.getValue(), lootTable)) + return ScrollQuantity.SOME; + else if (anyMatch(manyScrollTables.getValue(), lootTable)) + return ScrollQuantity.MANY; + return ScrollQuantity.NONE; + } } } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java index b5568683..646cecd4 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java @@ -1,11 +1,15 @@ package at.petrak.hexcasting.forge; +import at.petrak.hexcasting.api.misc.ScrollQuantity; import at.petrak.hexcasting.api.mod.HexConfig; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.ForgeConfigSpec; import java.util.List; +import static at.petrak.hexcasting.api.mod.HexConfig.anyMatch; +import static at.petrak.hexcasting.api.mod.HexConfig.noneMatch; + public class ForgeHexConfig implements HexConfig.CommonConfigAccess { private static ForgeConfigSpec.IntValue dustManaAmount; private static ForgeConfigSpec.IntValue shardManaAmount; @@ -81,6 +85,9 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess { private static ForgeConfigSpec.BooleanValue villagersOffendedByMindMurder; + private static ForgeConfigSpec.ConfigValue> fewScrollTables; + private static ForgeConfigSpec.ConfigValue> someScrollTables; + private static ForgeConfigSpec.ConfigValue> manyScrollTables; public Server(ForgeConfigSpec.Builder builder) { builder.push("Spells"); @@ -110,6 +117,21 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess { villagersOffendedByMindMurder = builder.comment( "Should villagers take offense when you flay the mind of their fellow villagers?") .define("villagersOffendedByMindMurder", true); + + builder.push("Scrolls in Loot"); + + fewScrollTables = builder.comment( + "Which loot tables should a small number of Ancient Scrolls be injected into?") + .defineList("fewScrollTables", DEFAULT_FEW_SCROLL_TABLES, + obj -> obj instanceof String s && ResourceLocation.isValidResourceLocation(s)); + someScrollTables = builder.comment( + "Which loot tables should a decent number of Ancient Scrolls be injected into?") + .defineList("someScrollTables", DEFAULT_SOME_SCROLL_TABLES, + obj -> obj instanceof String s && ResourceLocation.isValidResourceLocation(s)); + manyScrollTables = builder.comment( + "Which loot tables should a huge number of Ancient Scrolls be injected into?") + .defineList("manyScrollTables", DEFAULT_MANY_SCROLL_TABLES, + obj -> obj instanceof String s && ResourceLocation.isValidResourceLocation(s)); } @Override @@ -129,17 +151,28 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess { @Override public boolean isActionAllowed(ResourceLocation actionID) { - return !actionDenyList.get().contains(actionID.toString()); + return noneMatch(actionDenyList.get(), actionID); } @Override public boolean isActionAllowedInCircles(ResourceLocation actionID) { - return !circleActionDenyList.get().contains(actionID.toString()); + return noneMatch(circleActionDenyList.get(), actionID); } @Override public boolean doVillagersTakeOffenseAtMindMurder() { return villagersOffendedByMindMurder.get(); } + + @Override + public ScrollQuantity scrollsForLootTable(ResourceLocation lootTable) { + if (anyMatch(fewScrollTables.get(), lootTable)) + return ScrollQuantity.FEW; + else if (anyMatch(someScrollTables.get(), lootTable)) + return ScrollQuantity.SOME; + else if (anyMatch(manyScrollTables.get(), lootTable)) + return ScrollQuantity.MANY; + return ScrollQuantity.NONE; + } } }