Skip to content

Commit

Permalink
v0.5
Browse files Browse the repository at this point in the history
 - Add (optionally) Pandora's Box
 - Add Support for Shop Pedestal Loot
  • Loading branch information
Attack8 committed Dec 10, 2024
1 parent 4e3d4a7 commit e092025
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.attackeight.the_vault_jei.jei;

import com.mojang.logging.LogUtils;
import dev.attackeight.the_vault_jei.TheVaultJEI;
import dev.attackeight.the_vault_jei.mixin.*;
import iskallia.vault.config.OmegaSoulShardConfig;
import iskallia.vault.config.ShopPedestalConfig;
import iskallia.vault.config.SoulShardConfig;
import iskallia.vault.config.entry.IntRangeEntry;
import iskallia.vault.config.entry.recipe.ConfigForgeRecipe;
Expand All @@ -19,6 +22,8 @@
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -108,6 +113,46 @@ protected static ItemStack addWeight(WeightedList.Entry<ProductEntry> productEnt
return stack;
}

protected static List<LabeledLootInfo> getShopPedestalLoot() {
List<LabeledLootInfo> lootInfo = new ArrayList<>();
List<Pair<List<Triple<ItemStack, IntRangeEntry, Double>>, Integer>> pedestalInfo;
try {
pedestalInfo = (List<Pair<List<Triple<ItemStack, IntRangeEntry, Double>>, Integer>>)
ModConfigs.SHOP_PEDESTAL.getClass().getMethod("getTrades").invoke(ModConfigs.SHOP_PEDESTAL);
} catch (Exception e) {
TheVaultJEI.LOGGER.error(e.toString());
return new ArrayList<>();
}
pedestalInfo.forEach(tierInfo -> {
List<Triple<ItemStack, IntRangeEntry, Double>> tier = tierInfo.getLeft();
LogUtils.getLogger().info("tier Length: {}", tier.size());
int minLevel = tierInfo.getRight();
AtomicInteger totalWeight = new AtomicInteger();
tier.forEach(d -> totalWeight.addAndGet(d.getRight().intValue()));
List<ItemStack> offers = new ArrayList<>();
tier.forEach(offerInfo -> {
LogUtils.getLogger().info("Item Name: {}", offerInfo.getLeft().getDisplayName());
ItemStack currentOffer = offerInfo.getLeft();
int minPrice = offerInfo.getMiddle().getMin();
int maxPrice = offerInfo.getMiddle().getMax();
double chance = (offerInfo.getRight() / totalWeight.get()) * 100;
CompoundTag nbt = currentOffer.getOrCreateTagElement("display");
ListTag list = nbt.getList("Lore", 8);
MutableComponent chanceLabel = new TextComponent("Chance: ");
chanceLabel.append(String.format("%.2f", chance));
chanceLabel.append("%");
list.add(StringTag.valueOf(Component.Serializer.toJson(chanceLabel.withStyle(ChatFormatting.YELLOW))));
MutableComponent costLabel = new TextComponent("Cost: ");
costLabel.append(minPrice + " - " + maxPrice);
list.add(StringTag.valueOf(Component.Serializer.toJson(costLabel)));
nbt.put("Lore", list);
offers.add(currentOffer);
});
lootInfo.add(new LabeledLootInfo(offers, new TextComponent("Level " + minLevel + "+ ")));
});
return lootInfo;
}

protected static List<LabeledLootInfo> getBlackMarketLoot() {
List<LabeledLootInfo> lootInfo = new ArrayList<>();
Set<SoulShardConfig.Trades> tradesList = ModConfigs.SOUL_SHARD.getTrades();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class TheVaultJEIPlugin implements IModPlugin {
public static final RecipeType<LabeledLootInfo> BLACK_MARKET = RecipeType.create("the_vault", "black_market", LabeledLootInfo.class);
public static final RecipeType<LabeledLootInfo> MOD_BOX = RecipeType.create("the_vault", "mod_box", LabeledLootInfo.class);
public static final RecipeType<LabeledLootInfo> BOUNTY_REWARDS = RecipeType.create("the_vault", "bounty_rewards", LabeledLootInfo.class);
public static final RecipeType<LabeledLootInfo> SHOP_PEDESTAL = RecipeType.create("the_vault", "shop_pedestal", LabeledLootInfo.class);
public static final RecipeType<LabeledIngredientPool> ALTAR_INGREDIENTS = RecipeType.create("the_vault", "altar_ingredients", LabeledIngredientPool.class);

public TheVaultJEIPlugin() {}
Expand All @@ -56,6 +57,7 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(new ItemStack(ModBlocks.BLACK_MARKET), BLACK_MARKET);
registration.addRecipeCatalyst(new ItemStack(ModItems.MOD_BOX), MOD_BOX);
registration.addRecipeCatalyst(new ItemStack(ModBlocks.BOUNTY_BLOCK), BOUNTY_REWARDS);
registration.addRecipeCatalyst(new ItemStack(ModBlocks.SHOP_PEDESTAL), SHOP_PEDESTAL);
registration.addRecipeCatalyst(new ItemStack(ModBlocks.VAULT_ALTAR), ALTAR_INGREDIENTS);

if (ModConfig.shouldShow()) {
Expand All @@ -76,6 +78,7 @@ public void registerCategories(IRecipeCategoryRegistration registration) {
registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, BLACK_MARKET, ModBlocks.BLACK_MARKET));
registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, MOD_BOX, ModItems.MOD_BOX));
registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, BOUNTY_REWARDS, ModBlocks.BOUNTY_BLOCK));
registration.addRecipeCategories(makeLabeledLootInfoCategory(guiHelper, SHOP_PEDESTAL, ModBlocks.SHOP_PEDESTAL));
registration.addRecipeCategories(makeLabeledIngredientPoolCategory(guiHelper, ALTAR_INGREDIENTS, ModBlocks.VAULT_ALTAR));

if (ModConfig.shouldShow()) {
Expand All @@ -95,6 +98,7 @@ public void registerRecipes(IRecipeRegistration registration) {
registration.addRecipes(BLACK_MARKET, getBlackMarketLoot());
registration.addRecipes(MOD_BOX, getModBoxLoot());
registration.addRecipes(BOUNTY_REWARDS, getBountyRewards());
registration.addRecipes(SHOP_PEDESTAL, getShopPedestalLoot());
registration.addRecipes(ALTAR_INGREDIENTS, getAltarIngredients());

if (ModConfig.shouldShow()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.attackeight.the_vault_jei.mixin;

import dev.attackeight.the_vault_jei.TheVaultJEI;
import iskallia.vault.config.ShopPedestalConfig;
import iskallia.vault.config.entry.IntRangeEntry;
import iskallia.vault.config.entry.LevelEntryList;
import iskallia.vault.core.util.WeightedList;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import java.util.ArrayList;
import java.util.List;

@Mixin(value = ShopPedestalConfig.class, remap = false)
public class ShopPedestalConfigMixin {

@Shadow public LevelEntryList<LevelEntryList.ILevelEntry> LEVELS;

@Shadow @Final public static ShopPedestalConfig.ShopOffer EMPTY;

@Unique
public List<Pair<List<Triple<ItemStack, IntRangeEntry, Double>>, Integer>> getTrades() {
List<Pair<List<Triple<ItemStack, IntRangeEntry, Double>>, Integer>> toReturn = new ArrayList<>();
this.LEVELS.forEach(k -> {
int level = k.getLevel();
List<WeightedList> entries = new ArrayList<>(); // These are all WeightedList<ShopEntry>
this.LEVELS.getForLevel(level).map((tier) -> {
try {
return tier.getClass().getDeclaredField("TRADE_POOL").get(tier);
} catch (Exception e) {
TheVaultJEI.LOGGER.error(e.toString());
return EMPTY;
}
}).ifPresent(x -> entries.add((WeightedList) x));
entries.forEach(entry -> {
List<Triple<ItemStack, IntRangeEntry, Double>> offers = new ArrayList<>();
entry.forEach((offer, weight) -> {
try {
TheVaultJEI.LOGGER.info("Should be Entry: {}", offer.getClass());
offers.add(new ImmutableTriple<>(
(ItemStack) offer.getClass().getDeclaredField("OFFER").get(offer),
new IntRangeEntry(
(int) offer.getClass().getDeclaredField("MIN_COST").get(offer),
(int) offer.getClass().getDeclaredField("MAX_COST").get(offer)
),
(Double) weight
));
} catch (Exception e) {
TheVaultJEI.LOGGER.error(e.toString());
}
});
toReturn.add(new ImmutablePair<>(offers, level));
});
});
return toReturn;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/the_vault_jei.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"IntegrationJEIMixin",
"ProductEntryAccessor",
"RewardEntryAccessor",
"RewardPoolAccessor"
"RewardPoolAccessor",
"ShopPedestalConfigMixin"
],
"client": [],
"injectors": {
Expand Down

0 comments on commit e092025

Please sign in to comment.