Skip to content

Commit

Permalink
v1.0-beta
Browse files Browse the repository at this point in the history
fixes #4
  • Loading branch information
Attack8 committed Dec 31, 2024
1 parent 8cda41b commit 4a1d9c5
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 94 deletions.
6 changes: 5 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ Small hotfix to fix Altar Ingredients and Bounty Rewards in VH u16

Vault Hunters JEI Integration v0.5
- Add (optionally) Pandora's Box
- Add Support for Shop Pedestal Loot
- Add Support for Shop Pedestal Loot

Vault Hunters JEI Integration v1.0-beta
- Backend Code Simplification & Improvements
- Allow the display of item groups in Altar Ingredients
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mapping_version=1.18.2
mod_id = the_vault_jei
mod_name=TheVaultJEI
mod_license=GNU GPLv3
mod_version=0.5
mod_version=1.0-beta
mod_group_id=dev.attackeight
mod_authors=attackeight
mod_description=Adds JEI Compatibility for Vault Hunters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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 Down Expand Up @@ -125,13 +123,11 @@ protected static List<LabeledLootInfo> getShopPedestalLoot() {
}
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();
Expand All @@ -148,7 +144,7 @@ protected static List<LabeledLootInfo> getShopPedestalLoot() {
nbt.put("Lore", list);
offers.add(currentOffer);
});
lootInfo.add(new LabeledLootInfo(offers, new TextComponent("Level " + minLevel + "+ ")));
lootInfo.add(LabeledLootInfo.of(offers, new TextComponent("Level " + minLevel + "+ "), null));
});
return lootInfo;
}
Expand Down Expand Up @@ -179,7 +175,7 @@ protected static List<LabeledLootInfo> getBlackMarketLoot() {
nbt.put("Lore", list);
shardTrades.add(currentTrade);
});
lootInfo.add(new LabeledLootInfo(shardTrades, new TextComponent("Common Slot: Level " + minLevel + "+ "), new TextComponent("Soul Trade Price: " + randomPrice)));
lootInfo.add(LabeledLootInfo.of(shardTrades, new TextComponent("Common Slot: Level " + minLevel + "+ "), new TextComponent("Soul Trade Price: " + randomPrice)));
});
Set<OmegaSoulShardConfig.Trades> omegaTradesList = ModConfigs.OMEGA_SOUL_SHARD.getTrades();
omegaTradesList.forEach(b -> {
Expand All @@ -204,7 +200,7 @@ protected static List<LabeledLootInfo> getBlackMarketLoot() {
nbt.put("Lore", list);
shardTrades.add(currentTrade);
});
lootInfo.add(new LabeledLootInfo(shardTrades, new TextComponent("Omega Slot: Level " + minLevel + "+ ")));
lootInfo.add(LabeledLootInfo.of(shardTrades, new TextComponent("Omega Slot: Level " + minLevel + "+ "), null));
});
return lootInfo;
}
Expand Down Expand Up @@ -233,7 +229,7 @@ protected static List<LabeledLootInfo> getModBoxLoot() {
nbt.put("Lore", list);
results.add(result);
});
lootInfo.add(new LabeledLootInfo(results, new TextComponent("Mod: " + mod)));
lootInfo.add(LabeledLootInfo.of(results, new TextComponent("Mod: " + mod), null));
});
return lootInfo;
}
Expand All @@ -250,7 +246,13 @@ protected static List<LabeledLootInfo> getBountyRewards() {
RewardEntryAccessor rewardEntry = (RewardEntryAccessor) rewards;
IntRangeEntry vaultExp = rewardEntry.getVaultExp();
rewardEntry.getItemPool().getPool().forEach(stack -> totalWeight.addAndGet(stack.weight));
AtomicInteger counter = new AtomicInteger();
rewardEntry.getItemPool().getPool().forEach(stack -> {
if (stack.value == null) {
TheVaultJEI.LOGGER.error("a/8: null stack of id {} in lvl {}+ {} bounty rewards with a weight of {}", counter.getAndIncrement(), minLevel, id, stack.weight);
} else {
TheVaultJEI.LOGGER.info("a/8: okay stack of id {} in lvl {}+ {} bounty rewards with a weight of {}", counter.getAndIncrement(), minLevel, id, stack.weight);
}
ItemStack result = new ItemStack(stack.value.getMatchingStack().getItem(), stack.value.getMaxCount());
double chance = ((double) stack.weight / totalWeight.get()) * 100;
CompoundTag nbt = result.getOrCreateTagElement("display");
Expand All @@ -267,7 +269,7 @@ protected static List<LabeledLootInfo> getBountyRewards() {
nbt.put("Lore", list);
results.add(result);
});
lootInfo.put(minLevel, new LabeledLootInfo(results,
lootInfo.put(minLevel, LabeledLootInfo.of(results,
new TextComponent("Reward Pool: " + id + " Level: " + minLevel + "+"),
new TextComponent("Vault Exp Reward: " + vaultExp.getMin() + "-" + vaultExp.getMax())));
});
Expand All @@ -277,35 +279,39 @@ protected static List<LabeledLootInfo> getBountyRewards() {
return toReturn;
}

protected static List<LabeledIngredientPool> getAltarIngredients() {
List<LabeledIngredientPool> toReturn = new ArrayList<>();
protected static List<LabeledLootInfo> getAltarIngredients() {
List<LabeledLootInfo> toReturn = new ArrayList<>();
AltarIngredientAccessor rewardPools = (AltarIngredientAccessor) ModConfigs.VAULT_ALTAR_INGREDIENTS;
TreeMap<Integer, List<LabeledIngredientPool>> lootInfo = new TreeMap<>();
TreeMap<Integer, List<LabeledLootInfo>> lootInfo = new TreeMap<>();
rewardPools.getLEVELS().forEach((minLevel, entry) -> {
List<LabeledIngredientPool> pool = new ArrayList<>();
List<LabeledLootInfo> pool = new ArrayList<>();
entry.forEach((slot, rewards) -> {
AtomicInteger totalWeight = new AtomicInteger();
List<ItemStack> results = new ArrayList<>();
List<List<ItemStack>> results = new ArrayList<>();
rewards.forEach(stack -> totalWeight.addAndGet(stack.weight));
rewards.forEach(stack -> {
IntRangeEntry amounts = ((IngredientAmountAccessor) stack.value).getAmount();
ItemStack result = new ItemStack(stack.value.getItems().get(0).getItem(), amounts.getMax());
double chance = ((double) stack.weight / totalWeight.get()) * 100;
CompoundTag nbt = result.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))));
if (amounts.getMin() != amounts.getMax()) {
MutableComponent countLabel = new TextComponent("Count: ");
countLabel.append(amounts.getMin() + " - " + amounts.getMax());
list.add(StringTag.valueOf(Component.Serializer.toJson(countLabel)));
List<ItemStack> stacks = new ArrayList<>();
for (ItemStack stackInGroup : stack.value.getItems()) {
ItemStack result = new ItemStack(stackInGroup.getItem(), amounts.getMax());
double chance = ((double) stack.weight / totalWeight.get()) * 100;
CompoundTag nbt = result.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))));
if (amounts.getMin() != amounts.getMax()) {
MutableComponent countLabel = new TextComponent("Count: ");
countLabel.append(amounts.getMin() + " - " + amounts.getMax());
list.add(StringTag.valueOf(Component.Serializer.toJson(countLabel)));
}
nbt.put("Lore", list);
stacks.add(result);
}
nbt.put("Lore", list);
results.add(result);
results.add(stacks);
});
pool.add(new LabeledIngredientPool(results,
pool.add(new LabeledLootInfo(results,
new TextComponent("Reward Pool: " + slot + " Level: " + minLevel + "+")));
});
lootInfo.put(minLevel, pool);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import net.minecraft.world.item.ItemStack;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

public record LabeledLootInfo(List<ItemStack> itemStackList, Component label, @Nullable Component line2) {
public record LabeledLootInfo(List<List<ItemStack>> itemStackList, Component label, @Nullable Component line2) {

public LabeledLootInfo(List<ItemStack> itemStackList, Component label, Component line2) {
public LabeledLootInfo(List<List<ItemStack>> itemStackList, Component label, Component line2) {
this.itemStackList = itemStackList;
this.label = label;
this.line2 = line2;
}

public LabeledLootInfo(List<ItemStack> itemStackList, Component label) {
public LabeledLootInfo(List<List<ItemStack>> itemStackList, Component label) {
this(itemStackList, label, null);
}

public List<ItemStack> itemStackList() {
public List<List<ItemStack>> itemStackList() {
return this.itemStackList;
}

Expand All @@ -30,4 +31,20 @@ public Component line2() {
return this.line2;
}

public List<ItemStack> getSimpleList() {
List<ItemStack> toReturn = new ArrayList<>();
for (List<ItemStack> list : itemStackList) {
toReturn.add(list.get(0));
}
return toReturn;
}

public static LabeledLootInfo of(List<ItemStack> itemStackList, Component label, @Nullable Component label2) {
List<List<ItemStack>> toUse = new ArrayList<>();
for (ItemStack stack: itemStackList) {
toUse.add(List.of(stack));
}
return new LabeledLootInfo(toUse, label, label2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.system.CallbackI;

import javax.annotation.ParametersAreNonnullByDefault;

Expand All @@ -41,7 +40,7 @@ public class TheVaultJEIPlugin implements IModPlugin {
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 static final RecipeType<LabeledLootInfo> ALTAR_INGREDIENTS = RecipeType.create("the_vault", "altar_ingredients", LabeledLootInfo.class);

public TheVaultJEIPlugin() {}

Expand Down Expand Up @@ -119,7 +118,7 @@ private LabeledLootInfoRecipeCategory makeLabeledLootInfoCategory(IGuiHelper gui
return new LabeledLootInfoRecipeCategory(guiHelper, recipeType, new ItemStack(icon), icon.asItem().getName(new ItemStack(icon)));
}

private LabeledIngredientPoolRecipeCategory makeLabeledIngredientPoolCategory(IGuiHelper guiHelper, RecipeType<LabeledIngredientPool> recipeType, ItemLike icon) {
private LabeledIngredientPoolRecipeCategory makeLabeledIngredientPoolCategory(IGuiHelper guiHelper, RecipeType<LabeledLootInfo> recipeType, ItemLike icon) {
return new LabeledIngredientPoolRecipeCategory(guiHelper, recipeType, new ItemStack(icon), icon.asItem().getName(new ItemStack(icon)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.attackeight.the_vault_jei.jei.category;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.attackeight.the_vault_jei.jei.LabeledIngredientPool;
import dev.attackeight.the_vault_jei.jei.LabeledLootInfo;
import iskallia.vault.VaultMod;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -12,73 +12,78 @@
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import net.minecraft.world.item.crafting.Ingredient;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

public class LabeledIngredientPoolRecipeCategory implements IRecipeCategory<LabeledIngredientPool> {
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class LabeledIngredientPoolRecipeCategory implements IRecipeCategory<LabeledLootInfo> {

private static final ResourceLocation TEXTURE = VaultMod.id("textures/gui/jei/loot_info.png");
private final RecipeType<LabeledIngredientPool> recipeType;
private final RecipeType<LabeledLootInfo> recipeType;
private final IDrawable background;
private final Component titleComponent;
private final IDrawable icon;

public LabeledIngredientPoolRecipeCategory(IGuiHelper guiHelper, RecipeType<LabeledIngredientPool> recipeType, ItemStack icon, Component title) {
public LabeledIngredientPoolRecipeCategory(IGuiHelper guiHelper, RecipeType<LabeledLootInfo> recipeType, ItemStack icon, Component title) {
this.recipeType = recipeType;
this.background = guiHelper.createDrawable(TEXTURE, 0, 0, 162, 108);
this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, icon);
this.titleComponent = title;
}

@Override
public @NotNull Component getTitle() {
public Component getTitle() {
return titleComponent;
}

@Override
public @NotNull IDrawable getBackground() {
public IDrawable getBackground() {
return background;
}

@Override
public @NotNull IDrawable getIcon() {
public IDrawable getIcon() {
return icon;
}

@Override
public @NotNull RecipeType<LabeledIngredientPool> getRecipeType() {
public RecipeType<LabeledLootInfo> getRecipeType() {
return recipeType;
}

@SuppressWarnings("removal")
@Override
public ResourceLocation getUid() {
return recipeType.getUid();
}

@SuppressWarnings("removal")
@Override
public Class<? extends LabeledIngredientPool> getRecipeClass() {
public Class<? extends LabeledLootInfo> getRecipeClass() {
return recipeType.getRecipeClass();
}

@ParametersAreNonnullByDefault
public void setRecipe(IRecipeLayoutBuilder builder, LabeledIngredientPool recipe, IFocusGroup focuses) {
List<ItemStack> itemList = recipe.itemStackList();

public void setRecipe(IRecipeLayoutBuilder builder, LabeledLootInfo recipe, IFocusGroup focuses) {
List<List<ItemStack>> itemList = recipe.itemStackList();
int count = itemList.size();

for(int i = 0; i < count; ++i) {
builder.addSlot(RecipeIngredientRole.INPUT, 1 + 18 * (i % 9), 1 + 18 * (i / 9)).addItemStack((ItemStack)itemList.get(i));
builder.addSlot(RecipeIngredientRole.INPUT, 1 + 18 * (i % 9), 1 + 18 * (i / 9)).addIngredients(Ingredient.of(itemList.get(i).stream()));
}

}

@Override
public void draw(LabeledIngredientPool recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) {
public void draw(LabeledLootInfo recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) {
IRecipeCategory.super.draw(recipe, recipeSlotsView, stack, mouseX, mouseY);
Minecraft minecraft = Minecraft.getInstance();
int xPos = 0;
Expand Down
Loading

0 comments on commit 4a1d9c5

Please sign in to comment.