Skip to content

Commit

Permalink
Add conversion chance to Orechid recipe displays
Browse files Browse the repository at this point in the history
- Applies to Orechid, Orechid Ignem, and Marimorphosis. For the latter it also shows biome-specific chance, if different from base chance.
- Implemented for JEI (XPlat), REI (Fabric), and EMI (Fabric), ensuring the displays look similar across mods and supporting REI's dark theme.
  • Loading branch information
TheRealWormbo authored and williewillus committed May 29, 2023
1 parent 9711bd0 commit 39fc60a
Show file tree
Hide file tree
Showing 18 changed files with 451 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import vazkii.botania.common.block.BotaniaBlocks;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.crafting.BotaniaRecipeTypes;
import vazkii.botania.common.crafting.MarimorphosisRecipe;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.equipment.tool.terrasteel.TerraShattererItem;
import vazkii.botania.common.item.lens.LensItem;
Expand Down Expand Up @@ -200,8 +201,8 @@ public void register(EmiRegistry registry) {
registry.addRecipe(new OrechidEmiRecipe(ORECHID_IGNEM, recipe, flower));
}
flower = EmiStack.of(BotaniaFlowerBlocks.marimorphosis);
for (OrechidRecipe recipe : registry.getRecipeManager().getAllRecipesFor(BotaniaRecipeTypes.MARIMORPHOSIS_TYPE)) {
registry.addRecipe(new OrechidEmiRecipe(MARIMORPHOSIS, recipe, flower));
for (MarimorphosisRecipe recipe : registry.getRecipeManager().getAllRecipesFor(BotaniaRecipeTypes.MARIMORPHOSIS_TYPE)) {
registry.addRecipe(new MarimorphosisEmiRecipe(recipe, flower));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package vazkii.botania.fabric.integration.emi;

import dev.emi.emi.api.stack.EmiIngredient;

import net.minecraft.network.chat.Component;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.client.integration.shared.OrechidUIHelper;
import vazkii.botania.common.crafting.MarimorphosisRecipe;

import java.util.stream.Stream;

public class MarimorphosisEmiRecipe extends OrechidEmiRecipe {
public MarimorphosisEmiRecipe(
MarimorphosisRecipe recipe,
EmiIngredient orechid) {
super(BotaniaEmiPlugin.MARIMORPHOSIS, recipe, orechid);
}

@NotNull
@Override
protected Stream<Component> getChanceTooltipComponents(double chance) {
Stream<Component> genericChanceTooltipComponents = super.getChanceTooltipComponents(chance);
Stream<Component> biomeChanceTooltipComponents = OrechidUIHelper.getBiomeChanceAndRatioTooltipComponents(chance, recipe);
return Stream.concat(genericChanceTooltipComponents, biomeChanceTooltipComponents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.TextWidget;
import dev.emi.emi.api.widget.WidgetHolder;

import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import vazkii.botania.api.recipe.OrechidRecipe;
import vazkii.botania.client.integration.shared.OrechidUIHelper;

import java.util.List;
import java.util.stream.Stream;

public class OrechidEmiRecipe extends BotaniaEmiRecipe {
private final EmiIngredient orechid;
private final int weight;
protected final OrechidRecipe recipe;

public OrechidEmiRecipe(EmiRecipeCategory category, OrechidRecipe recipe, EmiIngredient orechid) {
super(category, recipe);
Expand All @@ -25,7 +35,7 @@ public OrechidEmiRecipe(EmiRecipeCategory category, OrechidRecipe recipe, EmiIng
throw new RuntimeException(e);
}
this.orechid = orechid;
this.weight = recipe.getWeight();
this.recipe = recipe;
}

@Override
Expand All @@ -35,7 +45,7 @@ public int getDisplayHeight() {

@Override
public int getDisplayWidth() {
return 76;
return 96;
}

@Override
Expand All @@ -46,9 +56,34 @@ public boolean supportsRecipeTree() {
@Override
public void addWidgets(WidgetHolder widgets) {
PureDaisyEmiRecipe.addPureDaisyWidgets(widgets, this, input.get(0), orechid, output.get(0));

final Double chance = getChance(recipe);
if (chance != null) {
final Component chanceComponent = OrechidUIHelper.getPercentageComponent(chance);
widgets.add(new TextWidget(chanceComponent.getVisualOrderText(), 90, 3, 0x555555, false) {
@Override
public List<ClientTooltipComponent> getTooltip(int mouseX, int mouseY) {
return getChanceTooltipComponents(chance)
.map(Component::getVisualOrderText)
.map(ClientTooltipComponent::create)
.toList();
}
}.horizontalAlign(TextWidget.Alignment.END));
}
}

@NotNull
protected Stream<Component> getChanceTooltipComponents(double chance) {
final var ratio = OrechidUIHelper.getRatioForChance(chance);
return Stream.of(OrechidUIHelper.getRatioTooltipComponent(ratio));
}

@Nullable
protected Double getChance(@NotNull OrechidRecipe recipe) {
return OrechidUIHelper.getChance(recipe, null);
}

public int getWeight() {
return weight;
return recipe.getWeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int getDisplayHeight() {

@Override
public int getDisplayWidth() {
return 76;
return 96;
}

@Override
Expand All @@ -48,9 +48,9 @@ public void addWidgets(WidgetHolder widgets) {

public static void addPureDaisyWidgets(WidgetHolder widgets, EmiRecipe recipe,
EmiIngredient input, EmiIngredient flower, EmiStack output) {
widgets.add(new BlendTextureWidget(TEXTURE, 7, 0, 65, 44, 0, 0));
widgets.addSlot(input, 0, 13).drawBack(false);
widgets.addSlot(flower, 29, 13).catalyst(true).drawBack(false);
widgets.addSlot(output, 58, 13).drawBack(false).recipeContext(recipe);
widgets.add(new BlendTextureWidget(TEXTURE, 17, 0, 65, 44, 0, 0));
widgets.addSlot(input, 10, 13).drawBack(false);
widgets.addSlot(flower, 39, 13).catalyst(true).drawBack(false);
widgets.addSlot(output, 68, 13).drawBack(false).recipeContext(recipe);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void registerCategories(CategoryRegistry helper) {
new TerrestrialAgglomerationREICategory(),
new OrechidREICategory(BotaniaREICategoryIdentifiers.ORECHID, BotaniaFlowerBlocks.orechid),
new OrechidREICategory(BotaniaREICategoryIdentifiers.ORECHID_IGNEM, BotaniaFlowerBlocks.orechidIgnem),
new OrechidREICategory(BotaniaREICategoryIdentifiers.MARIMORPHOSIS, BotaniaFlowerBlocks.marimorphosis)
new MarimorphosisREICategory()
));

helper.addWorkstations(BuiltinPlugin.CRAFTING, EntryStacks.of(BotaniaItems.craftingHalo), EntryStacks.of(BotaniaItems.autocraftingHalo));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package vazkii.botania.fabric.integration.rei;

import net.minecraft.network.chat.Component;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.api.recipe.OrechidRecipe;
import vazkii.botania.client.integration.shared.OrechidUIHelper;
import vazkii.botania.common.block.BotaniaFlowerBlocks;

import java.util.stream.Stream;

public class MarimorphosisREICategory extends OrechidREICategory {
public MarimorphosisREICategory() {
super(BotaniaREICategoryIdentifiers.MARIMORPHOSIS, BotaniaFlowerBlocks.marimorphosis);
}

@NotNull
@Override
protected Stream<Component> getChanceTooltipComponents(double chance, OrechidRecipe recipe) {
Stream<Component> genericChanceTooltipComponents = super.getChanceTooltipComponents(chance, recipe);
Stream<Component> biomeChanceTooltipComponents = OrechidUIHelper.getBiomeChanceAndRatioTooltipComponents(chance, recipe);
return Stream.concat(genericChanceTooltipComponents, biomeChanceTooltipComponents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
public abstract class OrechidBaseREIDisplay<T extends OrechidRecipe> implements Display {
private final List<EntryIngredient> stone;
private final List<EntryIngredient> ores;
private final T recipe;

public OrechidBaseREIDisplay(T recipe) {
stone = Collections.singletonList(EntryIngredient.of(recipe.getInput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
ores = Collections.singletonList(EntryIngredient.of(recipe.getOutput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
this.recipe = recipe;
}

@Override
Expand All @@ -38,4 +40,8 @@ public OrechidBaseREIDisplay(T recipe) {
public @NotNull List<EntryIngredient> getOutputEntries() {
return ores;
}

public T getRecipe() {
return recipe;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Label;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
Expand All @@ -20,23 +21,25 @@

import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import vazkii.botania.api.recipe.OrechidRecipe;
import vazkii.botania.client.integration.shared.OrechidUIHelper;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.lib.ResourceLocationHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import static vazkii.botania.fabric.integration.rei.PureDaisyREICategory.setupPureDaisyDisplay;

public class OrechidREICategory implements DisplayCategory<OrechidBaseREIDisplay<?>> {
private final EntryStack<ItemStack> orechid;
private final CategoryIdentifier<? extends OrechidBaseREIDisplay<?>> categoryId;
private final String langKey;
private final ResourceLocation OVERLAY = ResourceLocationHelper.prefix("textures/gui/pure_daisy_overlay.png");

public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay<?>> categoryId, Block orechid) {
this.categoryId = categoryId;
Expand All @@ -61,19 +64,39 @@ public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay<?>>

@Override
public @NotNull List<Widget> setupDisplay(OrechidBaseREIDisplay<?> display, Rectangle bounds) {
List<Widget> widgets = new ArrayList<>();
Point center = new Point(bounds.getCenterX() - 8, bounds.getCenterY() - 9);

widgets.add(Widgets.createRecipeBase(bounds));
widgets.add(Widgets.createDrawableWidget(((helper, matrices, mouseX, mouseY, delta) -> CategoryUtils.drawOverlay(helper, matrices, OVERLAY, center.x - 23, center.y - 13, 0, 0, 65, 44))));
widgets.add(Widgets.createSlot(center).entry(orechid).disableBackground());
widgets.add(Widgets.createSlot(new Point(center.x - 30, center.y)).entries(display.getInputEntries().get(0)).disableBackground());
widgets.add(Widgets.createSlot(new Point(center.x + 29, center.y)).entries(display.getOutputEntries().get(0)).disableBackground());
List<Widget> widgets = setupPureDaisyDisplay(display, bounds, orechid);

final Double chance = getChance(display.getRecipe());
if (chance != null) {
final Component chanceComponent = OrechidUIHelper.getPercentageComponent(chance);
final Point center = new Point(bounds.getCenterX() - 8, bounds.getCenterY() - 9);
final Label chanceLabel = Widgets.createLabel(new Point(center.x + 51, center.y - 11), chanceComponent)
.rightAligned().color(0x555555, 0xAAAAAA).noShadow();
chanceLabel.tooltip(getChanceTooltipComponents(chance, display.getRecipe()).toArray(Component[]::new));
widgets.add(chanceLabel);
}

return widgets;
}

@NotNull
protected Stream<Component> getChanceTooltipComponents(double chance, OrechidRecipe recipe) {
final var ratio = OrechidUIHelper.getRatioForChance(chance);
return Stream.of(OrechidUIHelper.getRatioTooltipComponent(ratio));
}

@Nullable
protected Double getChance(@NotNull OrechidRecipe recipe) {
return OrechidUIHelper.getChance(recipe, null);
}

@Override
public int getDisplayHeight() {
return 54;
}

@Override
public int getDisplayWidth(OrechidBaseREIDisplay<?> display) {
return 112;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;

Expand All @@ -32,7 +33,7 @@

public class PureDaisyREICategory implements DisplayCategory<PureDaisyREIDisplay> {
private final EntryStack<ItemStack> daisy = EntryStacks.of(new ItemStack(BotaniaFlowerBlocks.pureDaisy));
private final ResourceLocation OVERLAY = ResourceLocationHelper.prefix("textures/gui/pure_daisy_overlay.png");
private static final ResourceLocation OVERLAY = ResourceLocationHelper.prefix("textures/gui/pure_daisy_overlay.png");

@Override
public @NotNull CategoryIdentifier<PureDaisyREIDisplay> getCategoryIdentifier() {
Expand All @@ -51,12 +52,17 @@ public class PureDaisyREICategory implements DisplayCategory<PureDaisyREIDisplay

@Override
public @NotNull List<Widget> setupDisplay(PureDaisyREIDisplay display, Rectangle bounds) {
return setupPureDaisyDisplay(display, bounds, daisy);
}

@NotNull
public static List<Widget> setupPureDaisyDisplay(Display display, Rectangle bounds, EntryStack<ItemStack> entryStack) {
List<Widget> widgets = new ArrayList<>();
Point center = new Point(bounds.getCenterX() - 8, bounds.getCenterY() - 9);

widgets.add(Widgets.createRecipeBase(bounds));
widgets.add(Widgets.createDrawableWidget(((helper, matrices, mouseX, mouseY, delta) -> CategoryUtils.drawOverlay(helper, matrices, OVERLAY, center.x - 23, center.y - 13, 0, 0, 65, 44))));
widgets.add(Widgets.createSlot(center).entry(daisy).disableBackground());
widgets.add(Widgets.createSlot(center).entry(entryStack).disableBackground());
widgets.add(Widgets.createSlot(new Point(center.x - 30, center.y)).entries(display.getInputEntries().get(0)).disableBackground());
widgets.add(Widgets.createSlot(new Point(center.x + 29, center.y)).entries(display.getOutputEntries().get(0)).disableBackground());
return widgets;
Expand All @@ -66,4 +72,9 @@ public class PureDaisyREICategory implements DisplayCategory<PureDaisyREIDisplay
public int getDisplayHeight() {
return 54;
}

@Override
public int getDisplayWidth(PureDaisyREIDisplay display) {
return 112;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public HitResult getClientHit() {
@Override
public Locale getLocale() {
final String languageCode = Minecraft.getInstance().getLanguageManager().getSelected().getCode();
return Locale.forLanguageTag(languageCode);
final var parts = languageCode.split("_", 3);
return parts.length > 2
? new Locale(parts[0], parts[1], parts[2])
: parts.length == 2 ? new Locale(parts[0], parts[1]) : new Locale(languageCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

import org.jetbrains.annotations.NotNull;

import vazkii.botania.api.recipe.OrechidRecipe;
import vazkii.botania.client.integration.shared.OrechidUIHelper;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.crafting.BotaniaRecipeTypes;
import vazkii.botania.common.crafting.MarimorphosisRecipe;
import vazkii.botania.common.lib.LibMisc;

import java.util.stream.Stream;

public class MarimorphosisRecipeCategory extends OrechidRecipeCategoryBase<MarimorphosisRecipe> {
public static final mezz.jei.api.recipe.RecipeType<MarimorphosisRecipe> TYPE =
mezz.jei.api.recipe.RecipeType.create(LibMisc.MOD_ID, "marimorphosis", MarimorphosisRecipe.class);
Expand All @@ -31,4 +35,13 @@ public mezz.jei.api.recipe.RecipeType<MarimorphosisRecipe> getRecipeType() {
protected RecipeType<MarimorphosisRecipe> recipeType() {
return BotaniaRecipeTypes.MARIMORPHOSIS_TYPE;
}

@NotNull
@Override
protected Stream<Component> getChanceTooltipComponents(double chance, @NotNull OrechidRecipe recipe) {
Stream<Component> genericChanceTooltipComponents = super.getChanceTooltipComponents(chance, recipe);
Stream<Component> biomeChanceTooltipComponents = OrechidUIHelper.getBiomeChanceAndRatioTooltipComponents(chance, recipe);
return Stream.concat(genericChanceTooltipComponents, biomeChanceTooltipComponents);
}

}
Loading

0 comments on commit 39fc60a

Please sign in to comment.