Skip to content

Commit

Permalink
Address JEI deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Aug 24, 2024
1 parent 6212343 commit 8a8e25f
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 157 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def setupTasks(SourceSet sourceSet) {
tasks.named(sourceSet.processResourcesTaskName, ProcessResources).configure { ProcessResources process ->
process.setGroup('process resources')
process.duplicatesStrategy(DuplicatesStrategy.FAIL)
var versionProperties = ['version': mod_version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range, 'loader_version': loader_version_range]
var versionProperties = ['version': mod_version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range, 'loader_version': loader_version_range,
'jei_version': jei_version_range]
//Mark the properties as inputs so that when they change things update
process.inputs.properties(versionProperties)
process.filesMatching('META-INF/neoforge.mods.toml') { expand(versionProperties) }
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ emi_version=1.1.12
grand_power_version=3.0.0
jade_api_id=5427895
jade_id=5639932
jei_version=19.8.5.118
jei_version=19.9.0.120
json_things_version=0.12.1
top_version=1.21_neo-12.0.3-5
wildfire_gender_mod_id=5579007
wthit_version=12.3.0
framedblocks_mod_id=5629510

#Mod dependency min version ranges

jei_version_range=[19.9.0.120,)

#Mod dependency min version ranges until next MC version. For deps that we need a min version of but otherwise don't have to force ourselves loading after

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mekanism.api.chemical.attribute;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import net.minecraft.network.chat.Component;

/**
Expand All @@ -25,8 +27,27 @@ public boolean needsValidation() {
* @param list list of tooltips to be displayed
*
* @return updated list of tooltips
*
* @deprecated since 10.7.4. Use {@link #collectTooltips(Consumer)} instead.
*/
@Deprecated(since = "10.7.4", forRemoval = true)
public List<Component> addTooltipText(List<Component> list) {
return list;
}

/**
* Add text components to this chemical attribute's tooltip.
*
* @param adder Method reference to add tooltips to be displayed.
*
* @since 10.7.4
*/
public void collectTooltips(Consumer<Component> adder) {
//TODO - 1.22: When removing this legacy handling, make overriders call super
List<Component> list = new ArrayList<>();
addTooltipText(list);
for (Component component : list) {
adder.accept(component);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mekanism.api.chemical.attribute;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntSupplier;
import java.util.function.LongSupplier;
import mekanism.api.MekanismAPI;
Expand Down Expand Up @@ -58,14 +59,19 @@ public boolean needsValidation() {
}

@Override
@Deprecated(since = "10.7.4", forRemoval = true)
public List<Component> addTooltipText(List<Component> list) {
super.addTooltipText(list);
collectTooltips(list::add);
return list;
}

@Override
public void collectTooltips(Consumer<Component> adder) {
if (needsValidation()) {
//Only show the radioactive tooltip information if radiation is actually enabled
ITooltipHelper tooltipHelper = ITooltipHelper.INSTANCE;
list.add(APILang.CHEMICAL_ATTRIBUTE_RADIATION.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getRadioactivityDisplayShort(getRadioactivity())));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_RADIATION.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getRadioactivityDisplayShort(getRadioactivity())));
}
return list;
}
}

Expand Down Expand Up @@ -114,13 +120,18 @@ public double getConductivity() {
}

@Override
@Deprecated(since = "10.7.4", forRemoval = true)
public List<Component> addTooltipText(List<Component> list) {
super.addTooltipText(list);
collectTooltips(list::add);
return list;
}

@Override
public void collectTooltips(Consumer<Component> adder) {
ITooltipHelper tooltipHelper = ITooltipHelper.INSTANCE;
list.add(APILang.CHEMICAL_ATTRIBUTE_COOLANT_EFFICIENCY.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getPercent(conductivity)));
list.add(APILang.CHEMICAL_ATTRIBUTE_COOLANT_ENTHALPY.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
adder.accept(APILang.CHEMICAL_ATTRIBUTE_COOLANT_EFFICIENCY.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getPercent(conductivity)));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_COOLANT_ENTHALPY.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
tooltipHelper.getEnergyPerMBDisplayShort(MathUtils.clampToLong(thermalEnthalpy))));
return list;
}
}

Expand Down Expand Up @@ -245,13 +256,18 @@ public long getEnergyPerTick() {
}

@Override
@Deprecated(since = "10.7.4", forRemoval = true)
public List<Component> addTooltipText(List<Component> list) {
super.addTooltipText(list);
collectTooltips(list::add);
return list;
}

@Override
public void collectTooltips(Consumer<Component> adder) {
ITooltipHelper tooltipHelper = ITooltipHelper.INSTANCE;
list.add(APILang.CHEMICAL_ATTRIBUTE_FUEL_BURN_TICKS.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getFormattedNumber(getBurnTicks())));
list.add(APILang.CHEMICAL_ATTRIBUTE_FUEL_ENERGY_DENSITY.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_BURN_TICKS.translateColored(EnumColor.GRAY, EnumColor.INDIGO, tooltipHelper.getFormattedNumber(getBurnTicks())));
adder.accept(APILang.CHEMICAL_ATTRIBUTE_FUEL_ENERGY_DENSITY.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
tooltipHelper.getEnergyPerMBDisplayShort(energyDensity.getAsLong())));
return list;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekanism.client.recipe_viewer.jei;

import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import java.util.ArrayList;
import java.util.EnumMap;
Expand Down Expand Up @@ -29,9 +28,11 @@
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.neoforge.NeoForgeTypes;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
Expand All @@ -49,6 +50,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

//TODO: Re-evaluate this extending AbstractContainerEventHandler
public abstract class BaseRecipeCategory<RECIPE> extends AbstractContainerEventHandler implements IRecipeCategory<RECIPE>, IGuiWrapper {

protected static IDrawable createIcon(IGuiHelper helper, IRecipeViewerRecipeType<?> recipeType) {
Expand Down Expand Up @@ -108,13 +110,12 @@ public ScreenRectangle getRectangle() {
}

@Override
public boolean handleInput(RECIPE recipe, double mouseX, double mouseY, InputConstants.Key input) {
return switch (input.getType()) {
case KEYSYM -> keyPressed(input.getValue(), -1, 0);
case SCANCODE -> keyPressed(-1, input.getValue(), 0);
//Shift by the offset as JEI doesn't realize we are actually starting at negatives
case MOUSE -> mouseClicked(mouseX, mouseY, input.getValue());
};
public void createRecipeExtras(IRecipeExtrasBuilder builder, RECIPE recipe, IFocusGroup focuses) {
for (GuiElement guiElement : guiElements) {
//TODO: I believe we can use this method and adding via builder.addWidget to reduce some of our draw override hacks
//TODO: Only add this for ones that we actually have interaction behavior for?
builder.addGuiEventListener(new MekJeiWidget(guiElement));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.mojang.datafixers.util.Pair;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.Chemical;
Expand Down Expand Up @@ -40,10 +40,17 @@ public String getDisplayName(ChemicalStack ingredient) {
}

@Override
@Deprecated(forRemoval = true)
public String getUniqueId(ChemicalStack ingredient, UidContext context) {
return "chemical:" + ingredient.getTypeRegistryName();
}

@Override
public Object getUid(ChemicalStack ingredient, UidContext context) {
//Note: We just return the registry element itself as we have no component data
return ingredient.getChemical();
}

@Override
public ResourceLocation getResourceLocation(ChemicalStack ingredient) {
return ingredient.getTypeRegistryName();
Expand Down Expand Up @@ -89,13 +96,14 @@ public Stream<ResourceLocation> getTagStream(ChemicalStack ingredient) {
}

@Override
public Optional<ResourceLocation> getTagEquivalent(Collection<ChemicalStack> stacks) {
public Optional<TagKey<?>> getTagKeyEquivalent(Collection<ChemicalStack> stacks) {
if (stacks.size() < 2) {
return Optional.empty();
}
Set<Chemical> values = stacks.stream()
List<Chemical> values = stacks.stream()
.map(ChemicalStack::getChemical)
.collect(Collectors.toSet());
.distinct()
.toList();
int expected = values.size();
if (expected != stacks.size()) {
//One of the chemicals is there more than once, definitely not a tag
Expand All @@ -104,8 +112,16 @@ public Optional<ResourceLocation> getTagEquivalent(Collection<ChemicalStack> sta
return MekanismAPI.CHEMICAL_REGISTRY.getTags()
.filter(pair -> {
Named<Chemical> tag = pair.getSecond();
return tag.size() == expected && tag.stream().allMatch(holder -> values.contains(holder.value()));
}).map(pair -> pair.getFirst().location())
if (tag.size() != expected) {
return false;
}
for (int i = 0; i < expected; i++) {
if (tag.get(i).value() != values.get(i)) {
return false;
}
}
return true;
}).<TagKey<?>>map(Pair::getFirst)
.findFirst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.math.MathUtils;
Expand All @@ -16,6 +17,7 @@
import mekanism.common.registries.MekanismChemicals;
import mekanism.common.util.ChemicalUtil;
import mekanism.common.util.text.TextUtils;
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.ingredients.IIngredientRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand Down Expand Up @@ -71,26 +73,40 @@ public void render(@NotNull GuiGraphics guiGraphics, ChemicalStack stack) {
}

@Override
@Deprecated(forRemoval = true)
public List<Component> getTooltip(ChemicalStack stack, TooltipFlag tooltipFlag) {
Chemical chemical = stack.getChemical();
if (chemical.isEmptyType()) {
return Collections.emptyList();
}
List<Component> tooltips = new ArrayList<>();
tooltips.add(TextComponentUtil.build(chemical));
if (stack.getChemical() == MekanismChemicals.ETHENE.get()) {
//TODO - 1.22: Remove this
tooltips.add(MekanismLang.ALSO_KNOWN_AS.translateColored(EnumColor.GRAY, EnumColor.INDIGO, MekanismLang.ETHENE_ETHYLENE_ALIAS));
}
if (tooltipMode == TooltipMode.SHOW_AMOUNT_AND_CAPACITY) {
tooltips.add(MekanismLang.JEI_AMOUNT_WITH_CAPACITY.translateColored(EnumColor.GRAY, TextUtils.format(stack.getAmount()), TextUtils.format(capacityMb)));
} else if (tooltipMode == TooltipMode.SHOW_AMOUNT) {
tooltips.add(MekanismLang.GENERIC_MB.translateColored(EnumColor.GRAY, TextUtils.format(stack.getAmount())));
}
ChemicalUtil.addChemicalDataToTooltip(tooltips, stack.getChemical(), tooltipFlag.isAdvanced());
collectTooltips(stack, tooltipFlag, tooltips::add);
return tooltips;
}

@Override
public void getTooltip(ITooltipBuilder tooltip, ChemicalStack stack, TooltipFlag tooltipFlag) {
//TODO - 1.22: Flatten the collectTooltips into this method
collectTooltips(stack, tooltipFlag, tooltip::add);
}

private void collectTooltips(ChemicalStack stack, TooltipFlag tooltipFlag, Consumer<Component> tooltipAdder) {
Chemical chemical = stack.getChemical();
if (!chemical.isEmptyType()) {
tooltipAdder.accept(TextComponentUtil.build(chemical));
if (stack.getChemical() == MekanismChemicals.ETHENE.get()) {
//TODO - 1.22: Remove this
tooltipAdder.accept(MekanismLang.ALSO_KNOWN_AS.translateColored(EnumColor.GRAY, EnumColor.INDIGO, MekanismLang.ETHENE_ETHYLENE_ALIAS));
}
if (tooltipMode == TooltipMode.SHOW_AMOUNT_AND_CAPACITY) {
tooltipAdder.accept(MekanismLang.JEI_AMOUNT_WITH_CAPACITY.translateColored(EnumColor.GRAY, TextUtils.format(stack.getAmount()), TextUtils.format(capacityMb)));
} else if (tooltipMode == TooltipMode.SHOW_AMOUNT) {
tooltipAdder.accept(MekanismLang.GENERIC_MB.translateColored(EnumColor.GRAY, TextUtils.format(stack.getAmount())));
}
ChemicalUtil.addChemicalDataToTooltip(stack.getChemical(), tooltipFlag.isAdvanced(), tooltipAdder);
}
}

@Override
public Font getFontRenderer(Minecraft minecraft, ChemicalStack stack) {
return minecraft.font;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public IRecipeTransferError transferRecipe(CONTAINER container, RecipeHolder<Cra
private record JeiRecipeInfo(
QIOItemViewerContainer container, RecipeHolder<CraftingRecipe> recipeHolder, IRecipeSlotsView recipeSlots, Player player, int transferAmount,
IRecipeTransferHandlerHelper handlerHelper, IStackHelper stackHelper
) implements RVRecipeInfo<IRecipeTransferError, JeiRecipeSlot, String> {
) implements RVRecipeInfo<IRecipeTransferError, JeiRecipeSlot, Object> {

@Override
public IRecipeTransferError createInternalError() {
Expand All @@ -85,8 +85,8 @@ public IRecipeTransferError createMissingSlotsError(List<JeiRecipeSlot> missing)
}

@Override
public String itemUUID(HashedItem hashed) {
return stackHelper.getUniqueIdentifierForStack(hashed.getInternalStack(), UidContext.Recipe);
public Object itemUUID(HashedItem hashed) {
return stackHelper.getUidForStack(hashed.getInternalStack(), UidContext.Recipe);
}

@Override
Expand Down
Loading

0 comments on commit 8a8e25f

Please sign in to comment.