From 4e3d4a7e22b7fe5ffbb9da81eb72f1d14a5a298e Mon Sep 17 00:00:00 2001 From: attack8 Date: Tue, 3 Dec 2024 19:55:23 -0500 Subject: [PATCH] Add option for Pandora's Box loot table --- build.gradle | 8 -------- gradle.properties | 4 +--- .../the_vault_jei/TheVaultJEI.java | 14 ++++++------- .../the_vault_jei/jei/JEIRecipeProvider.java | 12 +++++++++++ .../the_vault_jei/jei/TheVaultJEIPlugin.java | 20 ++++++++++++++----- .../the_vault_jei/utils/ModConfig.java | 20 +++++++++++++++++++ 6 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 src/main/java/dev/attackeight/the_vault_jei/utils/ModConfig.java diff --git a/build.gradle b/build.gradle index 6e24d6d..9800e80 100644 --- a/build.gradle +++ b/build.gradle @@ -204,14 +204,6 @@ dependencies { runtimeOnly fg.deobf("curse.maven:applied-energistics-2-223794:4136407") runtimeOnly fg.deobf("curse.maven:modular-routers-250294:4984984") // runtimeOnly fg.deobf("curse.maven:attackeight-quest-addon-946682:5401585") - - compileOnly fg.deobf("curse.maven:wolds-vaults-official-mod-958799:5925360") - compileOnly fg.deobf("curse.maven:vault-hunters-api-1118899:5925356") - if (wolds_enable) { - runtimeOnly fg.deobf("curse.maven:wolds-vaults-official-mod-958799:5925360") - runtimeOnly fg.deobf("curse.maven:vault-hunters-api-1118899:5925356") - runtimeOnly fg.deobf("curse.maven:angel-ring-333396:4641783") - } } mixin { diff --git a/gradle.properties b/gradle.properties index d2d31d5..3d3865a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,6 +21,4 @@ gekolib_version = 3.0.57 jei_version = 9.7.2.281 curios_version = 5.0.9.0 arl_version = 1.7-53.110 -quark_version = 3.2-358.1 - -wolds_enable = true \ No newline at end of file +quark_version = 3.2-358.1 \ No newline at end of file diff --git a/src/main/java/dev/attackeight/the_vault_jei/TheVaultJEI.java b/src/main/java/dev/attackeight/the_vault_jei/TheVaultJEI.java index d511eb0..b5fef61 100644 --- a/src/main/java/dev/attackeight/the_vault_jei/TheVaultJEI.java +++ b/src/main/java/dev/attackeight/the_vault_jei/TheVaultJEI.java @@ -1,9 +1,11 @@ package dev.attackeight.the_vault_jei; import com.mojang.logging.LogUtils; +import dev.attackeight.the_vault_jei.utils.ModConfig; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig.Type; import org.slf4j.Logger; @Mod(TheVaultJEI.ID) @@ -12,16 +14,14 @@ public class TheVaultJEI { public static final String ID = "the_vault_jei"; // Directly reference a slf4j logger - private static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogUtils.getLogger(); - public TheVaultJEI() {} + public TheVaultJEI() { + ModLoadingContext.get().registerConfig(Type.CLIENT, ModConfig.SPEC, ID + "-client.toml"); + } public static ResourceLocation rl(String path) { return new ResourceLocation(TheVaultJEI.ID, path); } - public static boolean hasWolds() { - return ModList.get().isLoaded("woldsvaults"); - } - } diff --git a/src/main/java/dev/attackeight/the_vault_jei/jei/JEIRecipeProvider.java b/src/main/java/dev/attackeight/the_vault_jei/jei/JEIRecipeProvider.java index 24aa0ca..2a5d10e 100644 --- a/src/main/java/dev/attackeight/the_vault_jei/jei/JEIRecipeProvider.java +++ b/src/main/java/dev/attackeight/the_vault_jei/jei/JEIRecipeProvider.java @@ -18,6 +18,7 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.registries.ForgeRegistries; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -77,8 +78,19 @@ protected static List getHostileEggLoot() { return lootInfo; } + protected static List getPandorasBoxLoot() { + List lootInfo = new ArrayList<>(); + List loot = new ArrayList<>(); + int total = ModConfigs.PANDORAS_BOX.POOL.getTotalWeight(); + ModConfigs.PANDORAS_BOX.POOL.forEach(b -> loot.add(addWeight(b, total))); + lootInfo.add(new LootInfo(loot)); + return lootInfo; + } + protected static ItemStack addWeight(WeightedList.Entry productEntry, int totalWeight) { ProductEntryAccessor entry = (ProductEntryAccessor) productEntry.value; + if (!ForgeRegistries.ITEMS.containsKey(productEntry.value.getItem().getRegistryName())) + return ItemStack.EMPTY; ItemStack stack = new ItemStack(productEntry.value.getItem(), entry.getAmountMax()); CompoundTag nbt = stack.getOrCreateTagElement("display"); ListTag list = nbt.getList("Lore", 8); diff --git a/src/main/java/dev/attackeight/the_vault_jei/jei/TheVaultJEIPlugin.java b/src/main/java/dev/attackeight/the_vault_jei/jei/TheVaultJEIPlugin.java index 2e9967a..39b456a 100644 --- a/src/main/java/dev/attackeight/the_vault_jei/jei/TheVaultJEIPlugin.java +++ b/src/main/java/dev/attackeight/the_vault_jei/jei/TheVaultJEIPlugin.java @@ -4,6 +4,7 @@ import dev.attackeight.the_vault_jei.jei.category.*; import static dev.attackeight.the_vault_jei.jei.JEIRecipeProvider.*; +import dev.attackeight.the_vault_jei.utils.ModConfig; import iskallia.vault.init.ModBlocks; import iskallia.vault.init.ModItems; import iskallia.vault.integration.jei.lootinfo.LootInfo; @@ -15,12 +16,11 @@ import mezz.jei.api.registration.IRecipeCatalystRegistration; import mezz.jei.api.registration.IRecipeCategoryRegistration; import mezz.jei.api.registration.IRecipeRegistration; -import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.ModList; +import org.jetbrains.annotations.NotNull; +import org.lwjgl.system.CallbackI; import javax.annotation.ParametersAreNonnullByDefault; @@ -36,6 +36,7 @@ public class TheVaultJEIPlugin implements IModPlugin { public static final RecipeType MYSTERY_BOX = RecipeType.create("the_vault", "mystery_box", LootInfo.class); public static final RecipeType MYSTERY_EGG = RecipeType.create("the_vault", "mystery_egg", LootInfo.class); public static final RecipeType HOSTILE_EGG = RecipeType.create("the_vault", "hostile_egg", LootInfo.class); + public static final RecipeType PANDORAS_BOX = RecipeType.create("the_vault", "pandoras_box", LootInfo.class); public static final RecipeType BLACK_MARKET = RecipeType.create("the_vault", "black_market", LabeledLootInfo.class); public static final RecipeType MOD_BOX = RecipeType.create("the_vault", "mod_box", LabeledLootInfo.class); public static final RecipeType BOUNTY_REWARDS = RecipeType.create("the_vault", "bounty_rewards", LabeledLootInfo.class); @@ -56,6 +57,10 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { registration.addRecipeCatalyst(new ItemStack(ModItems.MOD_BOX), MOD_BOX); registration.addRecipeCatalyst(new ItemStack(ModBlocks.BOUNTY_BLOCK), BOUNTY_REWARDS); registration.addRecipeCatalyst(new ItemStack(ModBlocks.VAULT_ALTAR), ALTAR_INGREDIENTS); + + if (ModConfig.shouldShow()) { + registration.addRecipeCatalyst(new ItemStack(ModItems.PANDORAS_BOX), PANDORAS_BOX); + } } @Override @@ -72,6 +77,10 @@ public void registerCategories(IRecipeCategoryRegistration registration) { registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, MOD_BOX, ModItems.MOD_BOX)); registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, BOUNTY_REWARDS, ModBlocks.BOUNTY_BLOCK)); registration.addRecipeCategories(makeLabeledIngredientPoolCategory(guiHelper, ALTAR_INGREDIENTS, ModBlocks.VAULT_ALTAR)); + + if (ModConfig.shouldShow()) { + registration.addRecipeCategories(makeLootInfoCategory(guiHelper, PANDORAS_BOX, ModItems.PANDORAS_BOX)); + } } @Override @@ -87,13 +96,14 @@ public void registerRecipes(IRecipeRegistration registration) { registration.addRecipes(MOD_BOX, getModBoxLoot()); registration.addRecipes(BOUNTY_REWARDS, getBountyRewards()); registration.addRecipes(ALTAR_INGREDIENTS, getAltarIngredients()); - if (TheVaultJEI.hasWolds()) { + if (ModConfig.shouldShow()) { + registration.addRecipes(PANDORAS_BOX, getPandorasBoxLoot()); } } @Override - public ResourceLocation getPluginUid() { + public @NotNull ResourceLocation getPluginUid() { return TheVaultJEI.rl("jei_integration"); } diff --git a/src/main/java/dev/attackeight/the_vault_jei/utils/ModConfig.java b/src/main/java/dev/attackeight/the_vault_jei/utils/ModConfig.java new file mode 100644 index 0000000..0efea45 --- /dev/null +++ b/src/main/java/dev/attackeight/the_vault_jei/utils/ModConfig.java @@ -0,0 +1,20 @@ +package dev.attackeight.the_vault_jei.utils; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class ModConfig { + public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); + public static final ForgeConfigSpec SPEC; + + private static final ForgeConfigSpec.BooleanValue SHOW; + + public static boolean shouldShow() { + return SHOW.get(); + } + + static { + SHOW = BUILDER.comment("Should JEI show loot tables for items not used in the base modpack") + .define("enable_hidden", false); + SPEC = BUILDER.build(); + } +}