Skip to content

Commit

Permalink
feat: updated deprecated JEI methods
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Aug 16, 2024
1 parent 4ab680f commit 581ad3f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 67 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod_description=An open-source magic mod built around classical alchemy to repli
## Dependency Properties

jei_version=19.8.5.118
jei_version_range=[19.3.1.0,)
jei_version_range=[19.8.5.0,)
modonomicon_version=1.99.0
modonomicon_version_range=[1.95.0,)
occultism_version=1.144.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.neoforge.NeoForgeTypes;
Expand All @@ -33,7 +33,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;

import static mezz.jei.api.recipe.RecipeIngredientRole.INPUT;
import static mezz.jei.api.recipe.RecipeIngredientRole.OUTPUT;
Expand Down Expand Up @@ -61,7 +60,7 @@ public AccumulationCategory(IGuiHelper guiHelper) {
});
}

public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {
public static IRecipeSlotRichTooltipCallback addFluidTooltip(int overrideAmount) {
return (view, tooltip) -> {
var displayed = view.getDisplayedIngredient(NeoForgeTypes.FLUID_STACK);
if (displayed.isEmpty())
Expand All @@ -71,13 +70,7 @@ public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {

var amount = overrideAmount == -1 ? fluidStack.getAmount() : overrideAmount;
var text = Component.translatable(TheurgyConstants.I18n.Misc.UNIT_MILLIBUCKETS, amount).withStyle(ChatFormatting.GOLD);
if (tooltip.isEmpty())
tooltip.addFirst(text);
else {
List<Component> siblings = tooltip.getFirst().getSiblings();
siblings.add(Component.literal(" "));
siblings.add(text);
}
tooltip.add(text);
};
}

Expand Down Expand Up @@ -130,7 +123,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<AccumulationRec
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(NeoForgeTypes.FLUID_STACK, Arrays.stream(recipe.value().getEvaporant().getFluids()).toList())
.setFluidRenderer(1000, false, 16, 16)
.addTooltipCallback(addFluidTooltip(recipe.value().getEvaporantAmount()));
.addRichTooltipCallback(addFluidTooltip(recipe.value().getEvaporantAmount()));

if (recipe.value().hasSolute()) {
assert recipe.value().getSolute() != null;
Expand All @@ -142,7 +135,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<AccumulationRec
builder.addSlot(OUTPUT, 56, 1)
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addFluidStack(recipe.value().getResult().getFluid(), recipe.value().getResult().getAmount())
.addTooltipCallback(addFluidTooltip(recipe.value().getResult().getAmount()));
.addRichTooltipCallback(addFluidTooltip(recipe.value().getResult().getAmount()));

//now add the bucket to the recipe lookup for the output fluid
builder.addInvisibleIngredients(OUTPUT).addItemStack(new ItemStack(recipe.value().getResult().getFluid().getBucket()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
Expand Down Expand Up @@ -66,7 +67,7 @@ public DigestionCategory(IGuiHelper guiHelper) {
});
}

public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {
public static IRecipeSlotRichTooltipCallback addFluidTooltip(int overrideAmount) {
return (view, tooltip) -> {
var displayed = view.getDisplayedIngredient(NeoForgeTypes.FLUID_STACK);
if (displayed.isEmpty())
Expand All @@ -76,13 +77,7 @@ public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {

var amount = overrideAmount == -1 ? fluidStack.getAmount() : overrideAmount;
var text = Component.translatable(TheurgyConstants.I18n.Misc.UNIT_MILLIBUCKETS, amount).withStyle(ChatFormatting.GOLD);
if (tooltip.isEmpty())
tooltip.addFirst(text);
else {
List<Component> siblings = tooltip.getFirst().getSiblings();
siblings.add(Component.literal(" "));
siblings.add(text);
}
tooltip.add(text);
};
}

Expand Down Expand Up @@ -160,7 +155,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<DigestionRecipe
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(NeoForgeTypes.FLUID_STACK, this.getFluids(recipe))
.setFluidRenderer(1000, false, 16, 16)
.addTooltipCallback(addFluidTooltip(recipe.value().getFluidAmount()));
.addRichTooltipCallback(addFluidTooltip(recipe.value().getFluidAmount()));

//now add the bucket to the recipe lookup for the output fluid
builder.addInvisibleIngredients(INPUT).addItemStacks(Arrays.stream(recipe.value().getFluid().getFluids()).map(f -> new ItemStack(f.getFluid().getBucket())).toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.klikli_dev.theurgy.TheurgyConstants;
import com.klikli_dev.theurgy.content.gui.GuiTextures;
import com.klikli_dev.theurgy.content.recipe.DistillationRecipe;
import com.klikli_dev.theurgy.content.recipe.DistillationRecipe;
import com.klikli_dev.theurgy.integration.jei.JeiDrawables;
import com.klikli_dev.theurgy.integration.jei.JeiRecipeTypes;
import com.klikli_dev.theurgy.registry.BlockRegistry;
Expand All @@ -30,6 +29,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

Expand All @@ -56,7 +56,7 @@ public DistillationCategory(IGuiHelper guiHelper) {
.maximumSize(25)
.build(new CacheLoader<>() {
@Override
public IDrawableAnimated load(Integer cookTime) {
public @NotNull IDrawableAnimated load(@NotNull Integer cookTime) {
return JeiDrawables.asAnimatedDrawable(guiHelper, GuiTextures.JEI_ARROW_RIGHT_FULL, cookTime, IDrawableAnimated.StartDirection.LEFT, false);
}
});
Expand All @@ -81,7 +81,7 @@ public IDrawable getIcon() {
}

@Override
public void draw(RecipeHolder<DistillationRecipe> recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
public void draw(@NotNull RecipeHolder<DistillationRecipe> recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
GuiTextures.JEI_FIRE_EMPTY.render(guiGraphics, 1, 20);
this.animatedFire.draw(guiGraphics, 1, 20);

Expand All @@ -104,12 +104,12 @@ protected void drawCookTime(RecipeHolder<DistillationRecipe> recipe, GuiGraphics
}

@Override
public Component getTitle() {
public @NotNull Component getTitle() {
return this.localizedName;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<DistillationRecipe> recipe, IFocusGroup focuses) {
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<DistillationRecipe> recipe, @NotNull IFocusGroup focuses) {
builder.addSlot(INPUT, 1, 1)
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(VanillaTypes.ITEM_STACK, Arrays.stream(recipe.value().getIngredient().getItems()).map(i -> i.copyWithCount(recipe.value().getIngredientCount())).toList());
Expand All @@ -120,7 +120,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<DistillationRec
}

@Override
public RecipeType<RecipeHolder<DistillationRecipe>> getRecipeType() {
public @NotNull RecipeType<RecipeHolder<DistillationRecipe>> getRecipeType() {
return JeiRecipeTypes.DISTILLATION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.neoforge.NeoForgeTypes;
Expand All @@ -32,6 +32,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.neoforged.neoforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
Expand All @@ -56,13 +57,13 @@ public FermentationCategory(IGuiHelper guiHelper) {
.maximumSize(25)
.build(new CacheLoader<>() {
@Override
public IDrawableAnimated load(Integer cookTime) {
public @NotNull IDrawableAnimated load(@NotNull Integer cookTime) {
return JeiDrawables.asAnimatedDrawable(guiHelper, GuiTextures.JEI_ARROW_RIGHT_FULL, cookTime, IDrawableAnimated.StartDirection.LEFT, false);
}
});
}

public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {
public static IRecipeSlotRichTooltipCallback addFluidTooltip(int overrideAmount) {
return (view, tooltip) -> {
var displayed = view.getDisplayedIngredient(NeoForgeTypes.FLUID_STACK);
if (displayed.isEmpty())
Expand All @@ -72,13 +73,8 @@ public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {

var amount = overrideAmount == -1 ? fluidStack.getAmount() : overrideAmount;
var text = Component.translatable(TheurgyConstants.I18n.Misc.UNIT_MILLIBUCKETS, amount).withStyle(ChatFormatting.GOLD);
if (tooltip.isEmpty())
tooltip.add(0, text);
else {
List<Component> siblings = tooltip.get(0).getSiblings();
siblings.add(Component.literal(" "));
siblings.add(text);
}

tooltip.add(text);
};
}

Expand All @@ -91,7 +87,7 @@ protected IDrawableAnimated getAnimatedArrow(RecipeHolder<FermentationRecipe> re
}

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

Expand All @@ -101,7 +97,7 @@ public IDrawable getIcon() {
}

@Override
public void draw(RecipeHolder<FermentationRecipe> recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
public void draw(@NotNull RecipeHolder<FermentationRecipe> recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
GuiTextures.JEI_ARROW_RIGHT_EMPTY.render(guiGraphics, 45, 8);
this.getAnimatedArrow(recipe).draw(guiGraphics, 45, 8);

Expand All @@ -121,12 +117,12 @@ protected void drawCookTime(RecipeHolder<FermentationRecipe> recipe, GuiGraphics
}

@Override
public Component getTitle() {
public @NotNull Component getTitle() {
return this.localizedName;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<FermentationRecipe> recipe, IFocusGroup focuses) {
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<FermentationRecipe> recipe, @NotNull IFocusGroup focuses) {
var topLeft = builder.addSlot(INPUT, 1, 1)
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1);
var topRight = builder.addSlot(INPUT, 1 + 18, 1)
Expand All @@ -151,7 +147,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<FermentationRec
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(NeoForgeTypes.FLUID_STACK, this.getFluids(recipe))
.setFluidRenderer(1000, false, 16, 16)
.addTooltipCallback(addFluidTooltip(recipe.value().getFluidAmount()));
.addRichTooltipCallback(addFluidTooltip(recipe.value().getFluidAmount()));

//now add the bucket to the recipe lookup for the output fluid
builder.addInvisibleIngredients(INPUT).addItemStacks(Arrays.stream(recipe.value().getFluid().getFluids()).map(f -> new ItemStack(f.getFluid().getBucket())).toList());
Expand All @@ -167,7 +163,7 @@ public List<FluidStack> getFluids(RecipeHolder<FermentationRecipe> recipe) {
}

@Override
public RecipeType<RecipeHolder<FermentationRecipe>> getRecipeType() {
public @NotNull RecipeType<RecipeHolder<FermentationRecipe>> getRecipeType() {
return JeiRecipeTypes.FERMENTATION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -58,7 +59,7 @@ public IncubationCategory(IGuiHelper guiHelper) {
.maximumSize(25)
.build(new CacheLoader<>() {
@Override
public IDrawableAnimated load(Integer cookTime) {
public @NotNull IDrawableAnimated load(@NotNull Integer cookTime) {
return JeiDrawables.asAnimatedDrawable(guiHelper, GuiTextures.JEI_ARROW_RIGHT_FULL, cookTime, IDrawableAnimated.StartDirection.LEFT, false);
}
});
Expand All @@ -73,7 +74,7 @@ protected IDrawableAnimated getAnimatedArrow(RecipeHolder<IncubationRecipe> reci
}

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

Expand All @@ -83,7 +84,7 @@ public IDrawable getIcon() {
}

@Override
public void draw(RecipeHolder<IncubationRecipe> recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
public void draw(@NotNull RecipeHolder<IncubationRecipe> recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
GuiTextures.JEI_FIRE_EMPTY.render(guiGraphics, 28, 44);
this.animatedFire.draw(guiGraphics, 28, 44);

Expand All @@ -106,13 +107,13 @@ protected void drawCookTime(RecipeHolder<IncubationRecipe> recipe, GuiGraphics g
}

@Override
public Component getTitle() {
public @NotNull Component getTitle() {
return this.localizedName;
}


@Override
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<IncubationRecipe> recipe, IFocusGroup focuses) {
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<IncubationRecipe> recipe, @NotNull IFocusGroup focuses) {
builder.addSlot(INPUT, 1, 1)
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(recipe.value().getMercury());
Expand All @@ -131,7 +132,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<IncubationRecip
}

@Override
public RecipeType<RecipeHolder<IncubationRecipe>> getRecipeType() {
public @NotNull RecipeType<RecipeHolder<IncubationRecipe>> getRecipeType() {
return JeiRecipeTypes.INCUBATION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.neoforge.NeoForgeTypes;
Expand Down Expand Up @@ -66,7 +66,7 @@ public LiquefactionCategory(IGuiHelper guiHelper) {
});
}

public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {
public static IRecipeSlotRichTooltipCallback addFluidTooltip(int overrideAmount) {
return (view, tooltip) -> {
var displayed = view.getDisplayedIngredient(NeoForgeTypes.FLUID_STACK);
if (displayed.isEmpty())
Expand All @@ -76,13 +76,8 @@ public static IRecipeSlotTooltipCallback addFluidTooltip(int overrideAmount) {

var amount = overrideAmount == -1 ? fluidStack.getAmount() : overrideAmount;
var text = Component.translatable(TheurgyConstants.I18n.Misc.UNIT_MILLIBUCKETS, amount).withStyle(ChatFormatting.GOLD);
if (tooltip.isEmpty())
tooltip.add(0, text);
else {
List<Component> siblings = tooltip.get(0).getSiblings();
siblings.add(Component.literal(" "));
siblings.add(text);
}

tooltip.add(text);
};
}

Expand Down Expand Up @@ -138,7 +133,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, @NotNull RecipeHolder<Liquef
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
.addIngredients(NeoForgeTypes.FLUID_STACK, this.getFluids(recipe))
.setFluidRenderer(1000, false, 16, 16)
.addTooltipCallback(addFluidTooltip(recipe.value().getSolventAmount()));
.addRichTooltipCallback(addFluidTooltip(recipe.value().getSolventAmount()));

builder.addSlot(INPUT, 19, 1)
.setBackground(JeiDrawables.INPUT_SLOT, -1, -1)
Expand Down
Loading

0 comments on commit 581ad3f

Please sign in to comment.