Skip to content

Commit

Permalink
Fix Jubilance tooltip not shown on the first output in the list (#5)
Browse files Browse the repository at this point in the history
* Fix description bug

* Extract common part
  • Loading branch information
kuba6000 authored Oct 16, 2022
1 parent e60bba6 commit 939dcfc
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public BaseProduceRecipeHandler(ISpeciesRoot root) {

public class CachedProduceRecipe extends CachedRecipe {
private LabeledPositionedStack producer;
private ArrayList<LabeledPositionedStack> products;
private final ArrayList<LabeledPositionedStack> products;

public CachedProduceRecipe(IAlleleSpecies species) {
ItemStack producerStack = GeneticsUtils.stackFromSpecies(species, GeneticsUtils.RecipePosition.Producer);
Expand All @@ -55,7 +55,7 @@ public CachedProduceRecipe(IAlleleSpecies species) {
producer = new LabeledPositionedStack(producerStack, 22, 19, species.getName(), 13);
}

products = new ArrayList<LabeledPositionedStack>();
products = new ArrayList<>();

int i = 0;
for (Entry<ItemStack, Float> product : Utils.mergeStacks(GeneticsUtils.getProduceFromSpecies(species))
Expand All @@ -64,15 +64,16 @@ public CachedProduceRecipe(IAlleleSpecies species) {
products.add(new LabeledPositionedStack(product.getKey(), 96 + 22 * i++, 8, label, 10));
}

String jubilance = null;
if (species instanceof IAlleleBeeSpeciesCustom) {
IJubilanceProvider provider = ((IAlleleBeeSpeciesCustom) species).getJubilanceProvider();
if (provider != null) jubilance = provider.getDescription();
}

i = 0;
for (Entry<ItemStack, Float> product : Utils.mergeStacks(GeneticsUtils.getSpecialtyFromSpecies(species))
.entrySet()) {
String label = String.format("%.1f%%", product.getValue() * 100F);
String jubilance = null;
if (species instanceof IAlleleBeeSpeciesCustom) {
IJubilanceProvider provider = ((IAlleleBeeSpeciesCustom) species).getJubilanceProvider();
if (provider != null) jubilance = provider.getDescription();
}
if (jubilance != null)
products.add(new LabeledPositionedStack(
product.getKey(), 96 + 22 * i++, 36, label, 10, EnumChatFormatting.GRAY + jubilance));
Expand Down Expand Up @@ -110,6 +111,10 @@ public PositionedStack getResult() {
return null;
}
}

public ArrayList<LabeledPositionedStack> getProducts() {
return products;
}
}

@Override
Expand All @@ -134,11 +139,8 @@ public void loadCraftingRecipes(String outputId, Object... results) {
@Override
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe) {
CachedProduceRecipe crecipe = (CachedProduceRecipe) this.arecipes.get(recipe);
for (PositionedStack positionedStack : crecipe.getOtherStacks()) {
if (stack == positionedStack.item) {
currenttip.addAll(((LabeledPositionedStack) positionedStack).getTooltip());
}
}
for (LabeledPositionedStack positionedStack : crecipe.getProducts())
if (stack == positionedStack.item) currenttip.addAll(positionedStack.getTooltip());
return currenttip;
}

Expand Down

0 comments on commit 939dcfc

Please sign in to comment.