Skip to content

Commit

Permalink
remove addStochasticTooltip bulk version (#1421)
Browse files Browse the repository at this point in the history
* compat: rei: add new addStochasticTooltip overload

* compat: rei: DeployingCategory using new addStochasticTooltip overload

compat: rei: DeployingCategory using new addStochasticTooltip overload

* compat: rei: PolishingCategory using new addStochasticTooltip overload

* compat: rei: BasinCategory using new addStochasticTooltip overload

Update BasinCategory.java

* compat: rei: ItemApplicationCategory using new addStochasticTooltip overload

* compat: rei: CreateRecipeCategory removes unused addStochasticTooltip overloads
  • Loading branch information
ypf791 authored Apr 7, 2024
1 parent 9e3e686 commit 85b5bef
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.simibubi.create.content.processing.basin.BasinRecipe;
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock.HeatLevel;
import com.simibubi.create.content.processing.recipe.HeatCondition;
import com.simibubi.create.content.processing.recipe.ProcessingOutput;
import com.simibubi.create.foundation.fluid.FluidIngredient;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.item.ItemHelper;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void addWidgets(CreateDisplay<BasinRecipe> display, List<Widget> widgets,
BasinRecipe recipe = display.getRecipe();
NonNullList<FluidIngredient> fluidIngredients = recipe.getFluidIngredients();
List<Pair<Ingredient, MutableInt>> ingredients = ItemHelper.condenseIngredients(recipe.getIngredients());
List<ItemStack> itemOutputs = recipe.getRollableResultsAsItemStacks();
List<ProcessingOutput> itemOutputs = recipe.getRollableResults();
NonNullList<FluidStack> fluidOutputs = recipe.getFluidResults();

int size = ingredients.size() + fluidIngredients.size();
Expand Down Expand Up @@ -77,21 +78,20 @@ public void addWidgets(CreateDisplay<BasinRecipe> display, List<Widget> widgets,
widgets.add(fluidSlot);
}

int outSize = fluidOutputs.size() + recipe.getRollableResults()
.size();
int outSize = fluidOutputs.size() + itemOutputs.size();
int outputIndex = 0;

if (!itemOutputs.isEmpty())
addStochasticTooltip(widgets, recipe.getRollableResults(), i);

for (; outputIndex < outSize; outputIndex++) {
int xPosition = 141 - (outSize % 2 != 0 && outputIndex == outSize - 1 ? 0 : outputIndex % 2 == 0 ? 10 : -9);
int yPosition = -19 * (outputIndex / 2) + 50 + yOffset;

if (itemOutputs.size() > outputIndex) {
widgets.add(basicSlot(origin.x + xPosition + 1, origin.y + yPosition + yOffset + 1)
ProcessingOutput result = itemOutputs.get(outputIndex);
Slot outputSlot = basicSlot(origin.x + xPosition + 1, origin.y + yPosition + yOffset + 1)
.markOutput()
.entries(EntryIngredients.of(itemOutputs.get(outputIndex))));
.entries(EntryIngredients.of(result.getStack()));
widgets.add(outputSlot);
addStochasticTooltip(outputSlot, result);
i++;
} else {
Slot fluidSlot = basicSlot(origin.x + xPosition + 1, origin.y + yPosition + 1 + yOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,16 @@ public static AllGuiTextures getRenderedSlot(Recipe<?> recipe, int index) {
return AllGuiTextures.JEI_CHANCE_SLOT;
}

public static void addStochasticTooltip(List<Widget> itemStacks, List<ProcessingOutput> results) {
addStochasticTooltip(itemStacks, results, 1);
}

public static void addStochasticTooltip(List<Widget> itemStacks, List<ProcessingOutput> results,
int startIndex) {
itemStacks.stream().filter(widget -> widget instanceof Slot).forEach(widget -> {
Slot slot = (Slot) widget;

int slotIndex = itemStacks.indexOf(widget);

ClientEntryStacks.setTooltipProcessor(slot.getCurrentEntry(), (entryStack, tooltip) -> {
int outputIndex = slotIndex - startIndex;
if (slotIndex < startIndex || outputIndex >= results.size())
return tooltip;
ProcessingOutput output = results.get(outputIndex);
float chance = output.getChance();
if (chance != 1)
tooltip.add(Lang.translateDirect("recipe.processing.chance", chance < 0.01 ? "<1" : (int) (chance * 100))
.withStyle(ChatFormatting.GOLD));
return tooltip;
});
public static void addStochasticTooltip(Slot slot, ProcessingOutput output) {
ClientEntryStacks.setTooltipProcessor(slot.getCurrentEntry(), (entryStack, tooltip) -> {
float chance = output.getChance();
if (chance != 1)
tooltip.add(Lang.translateDirect("recipe.processing.chance", chance < 0.01 ? "<1" : (int) (chance * 100))
.withStyle(ChatFormatting.GOLD));
return tooltip;
});
}

public static void addStochasticTooltip(ProcessingOutput output, Tooltip tooltip) {
float chance = output.getChance();
if (chance != 1)
tooltip.add(Lang.translateDirect("recipe.processing.chance", chance < 0.01 ? "<1" : (int) (chance * 100))
.withStyle(ChatFormatting.GOLD));
}

public static Slot basicSlot(int x, int y) {
return Widgets.createSlot(point(x, y)).disableBackground();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public void addWidgets(CreateDisplay<DeployerApplicationRecipe> display, List<Wi
ingredients.add(basicSlot(origin.getX() + 51, origin.getY() + 5)
.markInput()
.entries(EntryIngredients.ofIngredient(recipe.getRequiredHeldItem())));
Slot output = basicSlot(origin.getX() + 132, origin.getY() + 51)
.markOutput()
.entries(EntryIngredients.of(recipe.getResultItem()));
ingredients.add(output);
addStochasticTooltip(ingredients, recipe.getRollableResults(), 2);
recipe.getRollableResults().stream().limit(1).forEach(result -> {
Slot outputSlot = basicSlot(origin.getX() + 132, origin.getY() + 51)
.markOutput()
.entries(EntryIngredients.of(result.getStack()));
ingredients.add(outputSlot);
addStochasticTooltip(outputSlot, result);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ public void addWidgets(CreateDisplay<ItemApplicationRecipe> display, List<Widget
});
ingredients.add(slot);

Slot outputSlot = basicSlot(132, 38, origin)
.markOutput()
.entries(display.getOutputEntries().get(0));
ClientEntryStacks.setTooltipProcessor(outputSlot.getCurrentEntry(), (entryStack, tooltip) -> {
addStochasticTooltip(display.getRecipe().getRollableResults()
.get(0), tooltip);
return tooltip;
display.getRecipe().getRollableResults().stream().limit(1).forEach(result -> {
Slot outputSlot = basicSlot(132, 38, origin)
.markOutput()
.entries(EntryIngredients.of(result.getStack()));
ingredients.add(outputSlot);
addStochasticTooltip(outputSlot, result);
});
ingredients.add(outputSlot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import io.github.fabricators_of_create.porting_lib.util.NBTSerializer;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import net.minecraft.core.NonNullList;
Expand All @@ -30,16 +31,16 @@ public PolishingCategory(Info<SandPaperPolishingRecipe> info) {

@Override
public void addWidgets(CreateDisplay<SandPaperPolishingRecipe> display, List<Widget> ingredients, Point origin) {
List<ProcessingOutput> results = display.getRecipe().getRollableResults();

ingredients.add(basicSlot(origin.x + 27, origin.y + 29)
.markInput()
.entries(display.getInputEntries().get(0)));
ingredients.add(basicSlot(origin.x + 132, origin.y + 29)
.markOutput()
.entries(EntryIngredients.of(results.get(0).getStack())));

addStochasticTooltip(ingredients, results);
display.getRecipe().getRollableResults().stream().limit(1).forEach(result -> {
Slot outputSlot = basicSlot(origin.x + 132, origin.y + 29)
.markOutput()
.entries(EntryIngredients.of(result.getStack()));
ingredients.add(outputSlot);
addStochasticTooltip(outputSlot, result);
});
}

@Override
Expand Down

0 comments on commit 85b5bef

Please sign in to comment.