Skip to content

Commit

Permalink
fix(jei): fix bad text color in the biomancy recipe previews
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Jan 22, 2024
1 parent 1bc4a00 commit 08dc86a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.elenterius.biomancy.crafting.recipe.IngredientStack;
import com.github.elenterius.biomancy.init.ModItems;
import com.github.elenterius.biomancy.init.ModRecipes;
import com.github.elenterius.biomancy.styles.ColorStyles;
import com.github.elenterius.biomancy.util.ComponentUtil;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -19,12 +20,14 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

import java.util.List;
import java.util.Objects;

public class BioForgeRecipeCategory implements IRecipeCategory<BioForgeRecipe> {

Expand Down Expand Up @@ -60,7 +63,7 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, BioForgeRecipe recipe, IFocusGroup focuses) {
//builder.setShapeless();
ClientLevel level = Objects.requireNonNull(Minecraft.getInstance().level);

List<IngredientStack> ingredientQuantities = recipe.getIngredientQuantities();
int y = 5;
Expand All @@ -70,7 +73,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, BioForgeRecipe recipe, IFocu
addInputSlot(builder, 55, y, ingredientQuantities, 3);
addInputSlot(builder, 73, y, ingredientQuantities, 4);

builder.addSlot(RecipeIngredientRole.OUTPUT, 131, y).addItemStack(recipe.getResultItem(null));
builder.addSlot(RecipeIngredientRole.OUTPUT, 131, y).addItemStack(recipe.getResultItem(level.registryAccess()));
}

private void addInputSlot(IRecipeLayoutBuilder builder, int x, int y, List<IngredientStack> ingredients, int index) {
Expand All @@ -87,6 +90,6 @@ private void addInputSlot(IRecipeLayoutBuilder builder, int x, int y, List<Ingre
public void draw(BioForgeRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
Font font = Minecraft.getInstance().font;
MutableComponent costString = ComponentUtil.literal("-" + recipe.getCraftingCostNutrients());
guiGraphics.drawString(font, costString, 108, 32 - font.lineHeight + 1, 0xff_808080);
guiGraphics.drawString(font, costString, 108, 32 - font.lineHeight + 1, ColorStyles.WHITE_ARGB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.elenterius.biomancy.crafting.recipe.IngredientStack;
import com.github.elenterius.biomancy.init.ModItems;
import com.github.elenterius.biomancy.init.ModRecipes;
import com.github.elenterius.biomancy.styles.ColorStyles;
import com.github.elenterius.biomancy.util.ComponentUtil;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -19,11 +20,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

import java.util.List;
import java.util.Objects;

public class BioLabRecipeCategory implements IRecipeCategory<BioLabRecipe> {

Expand Down Expand Up @@ -59,6 +62,8 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, BioLabRecipe recipe, IFocusGroup focuses) {
ClientLevel level = Objects.requireNonNull(Minecraft.getInstance().level);

builder.setShapeless();

List<IngredientStack> ingredientQuantities = recipe.getIngredientQuantities();
Expand All @@ -69,7 +74,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, BioLabRecipe recipe, IFocusG

builder.addSlot(RecipeIngredientRole.INPUT, 55, 10).addIngredients(recipe.getReactant());

builder.addSlot(RecipeIngredientRole.OUTPUT, 113, 10).addItemStack(recipe.getResultItem(null));
builder.addSlot(RecipeIngredientRole.OUTPUT, 113, 10).addItemStack(recipe.getResultItem(level.registryAccess()));
}

private void addInputSlot(IRecipeLayoutBuilder builder, int x, int y, List<IngredientStack> ingredients, int index) {
Expand All @@ -89,10 +94,10 @@ public void draw(BioLabRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraph
int ticks = recipe.getCraftingTimeTicks();
int seconds = ticks > 0 ? ticks / 20 : 0;
Component timeText = ComponentUtil.translatable("gui.jei.category.smelting.time.seconds", seconds);
guiGraphics.drawString(font, timeText, 102, 50 - font.lineHeight, 0xff808080);
guiGraphics.drawString(font, timeText, 102, 50 - font.lineHeight, ColorStyles.WHITE_ARGB);

Component costText = ComponentUtil.literal("-" + recipe.getCraftingCostNutrients());
guiGraphics.drawString(font, costText, 69, 50 - font.lineHeight, 0xff808080);
guiGraphics.drawString(font, costText, 69, 50 - font.lineHeight, ColorStyles.WHITE_ARGB);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void registerCategories(IRecipeCategoryRegistration registration) {

@Override
public void registerRecipes(IRecipeRegistration registration) {
ClientLevel world = Objects.requireNonNull(Minecraft.getInstance().level);
registration.addRecipes(DecomposerRecipeCategory.RECIPE_TYPE, world.getRecipeManager().getAllRecipesFor(ModRecipes.DECOMPOSING_RECIPE_TYPE.get()));
registration.addRecipes(BioLabRecipeCategory.RECIPE_TYPE, world.getRecipeManager().getAllRecipesFor(ModRecipes.BIO_BREWING_RECIPE_TYPE.get()));
registration.addRecipes(DigesterRecipeCategory.RECIPE_TYPE, world.getRecipeManager().getAllRecipesFor(ModRecipes.DIGESTING_RECIPE_TYPE.get()));
registration.addRecipes(BioForgeRecipeCategory.RECIPE_TYPE, world.getRecipeManager().getAllRecipesFor(ModRecipes.BIO_FORGING_RECIPE_TYPE.get()));
ClientLevel level = Objects.requireNonNull(Minecraft.getInstance().level);
registration.addRecipes(DecomposerRecipeCategory.RECIPE_TYPE, level.getRecipeManager().getAllRecipesFor(ModRecipes.DECOMPOSING_RECIPE_TYPE.get()));
registration.addRecipes(BioLabRecipeCategory.RECIPE_TYPE, level.getRecipeManager().getAllRecipesFor(ModRecipes.BIO_BREWING_RECIPE_TYPE.get()));
registration.addRecipes(DigesterRecipeCategory.RECIPE_TYPE, level.getRecipeManager().getAllRecipesFor(ModRecipes.DIGESTING_RECIPE_TYPE.get()));
registration.addRecipes(BioForgeRecipeCategory.RECIPE_TYPE, level.getRecipeManager().getAllRecipesFor(ModRecipes.BIO_FORGING_RECIPE_TYPE.get()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.elenterius.biomancy.crafting.recipe.VariableProductionOutput;
import com.github.elenterius.biomancy.init.ModBlocks;
import com.github.elenterius.biomancy.init.ModRecipes;
import com.github.elenterius.biomancy.styles.ColorStyles;
import com.github.elenterius.biomancy.util.ComponentUtil;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand Down Expand Up @@ -93,10 +94,10 @@ public void draw(DecomposerRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiG
int ticks = recipe.getCraftingTimeTicks();
int seconds = ticks > 0 ? ticks / 20 : 0;
MutableComponent timeString = ComponentUtil.translatable("gui.jei.category.smelting.time.seconds", seconds);
guiGraphics.drawString(font, timeString, 16, 59 - font.lineHeight, 0xff_808080);
guiGraphics.drawString(font, timeString, 16, 59 - font.lineHeight, ColorStyles.WHITE_ARGB);

MutableComponent costString = ComponentUtil.literal("-" + recipe.getCraftingCostNutrients());
guiGraphics.drawString(font, costString, 16, 43 - font.lineHeight, 0xff_808080);
guiGraphics.drawString(font, costString, 16, 43 - font.lineHeight, ColorStyles.WHITE_ARGB);

int x = 68;
List<VariableProductionOutput> outputs = recipe.getOutputs();
Expand Down Expand Up @@ -124,15 +125,15 @@ private void drawOutputAmount(Font font, GuiGraphics guiGraphics, int x, int y,
ItemCountRange countRange = output.getCountRange();
if (countRange instanceof ItemCountRange.UniformRange uniform) {
MutableComponent component = ComponentUtil.literal("%d-%d".formatted(Math.max(uniform.min(), 0), uniform.max()));
guiGraphics.drawString(font, component, x - font.width(component), y, 0xff_808080);
guiGraphics.drawString(font, component, x - font.width(component), y, ColorStyles.WHITE_ARGB);
}
else if (countRange instanceof ItemCountRange.ConstantValue constant) {
MutableComponent component = ComponentUtil.literal("" + constant.value());
guiGraphics.drawString(font, component, x - font.width(component), y, 0xff_808080);
guiGraphics.drawString(font, component, x - font.width(component), y, ColorStyles.WHITE_ARGB);
}
else if (countRange instanceof ItemCountRange.BinomialRange binomialRange) {
MutableComponent component = ComponentUtil.literal("n: %d, p: %s".formatted(binomialRange.n(), binomialRange.p()));
guiGraphics.drawString(font, component, x - font.width(component), y, 0xff_808080);
guiGraphics.drawString(font, component, x - font.width(component), y, ColorStyles.WHITE_ARGB);
}

guiGraphics.pose().popPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.elenterius.biomancy.crafting.recipe.DigesterRecipe;
import com.github.elenterius.biomancy.init.ModItems;
import com.github.elenterius.biomancy.init.ModRecipes;
import com.github.elenterius.biomancy.styles.ColorStyles;
import com.github.elenterius.biomancy.util.ComponentUtil;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -17,10 +18,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

import java.util.Objects;

public class DigesterRecipeCategory implements IRecipeCategory<DigesterRecipe> {

public static final RecipeType<DigesterRecipe> RECIPE_TYPE = new RecipeType<>(ModRecipes.DIGESTING_RECIPE_TYPE.getId(), DigesterRecipe.class);
Expand Down Expand Up @@ -55,9 +59,11 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, DigesterRecipe recipe, IFocusGroup focuses) {
ClientLevel level = Objects.requireNonNull(Minecraft.getInstance().level);

builder.setShapeless();
builder.addSlot(RecipeIngredientRole.INPUT, 1, 4).addIngredients(recipe.getIngredient());
builder.addSlot(RecipeIngredientRole.OUTPUT, 59, 5).addItemStack(recipe.getResultItem(null));
builder.addSlot(RecipeIngredientRole.OUTPUT, 59, 5).addItemStack(recipe.getResultItem(level.registryAccess()));
}

@Override
Expand All @@ -67,10 +73,10 @@ public void draw(DigesterRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGra
int ticks = recipe.getCraftingTimeTicks();
int seconds = ticks > 0 ? ticks / 20 : 0;
Component timeText = ComponentUtil.translatable("gui.jei.category.smelting.time.seconds", seconds);
guiGraphics.drawString(font, timeText, 48, 44 - font.lineHeight, 0xff_808080);
guiGraphics.drawString(font, timeText, 48, 44 - font.lineHeight, ColorStyles.WHITE_ARGB);

Component costText = ComponentUtil.literal("-" + recipe.getCraftingCostNutrients());
guiGraphics.drawString(font, costText, 15, 44 - font.lineHeight, 0xff_808080);
guiGraphics.drawString(font, costText, 15, 44 - font.lineHeight, ColorStyles.WHITE_ARGB);
}

}

0 comments on commit 08dc86a

Please sign in to comment.