Skip to content

Commit

Permalink
Updated to latest JEI, require JEI >=19.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Aug 11, 2024
1 parent 786b890 commit aeed609
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 144 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ dependencies {
exclude group: "net.minecraftforge", module: "forge"
}

compileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
compileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")
runtimeOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}")
runtimeOnly("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}")
compileOnly("mezz.jei:jei-1.21-common-api:${jei_version}")
compileOnly("mezz.jei:jei-1.21-neoforge-api:${jei_version}")
runtimeOnly("mezz.jei:jei-1.21-common:${jei_version}")
runtimeOnly("mezz.jei:jei-1.21-neoforge:${jei_version}")

compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}:api")
runtimeOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}")
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ org.gradle.daemon=false
#########################################################
# Minecraft versions
#########################################################
minecraft_version=1.21
minecraft_version=1.21.1
minecraft_version_range=[1.21,)
neo_version=21.0.157
neo_version=21.1.4
neo_version_range=[21.0.143,)
loader_version_range=[4,)
#mappings_version=1.20.6-2024.06.02
Expand All @@ -34,7 +34,7 @@ curse_project_id=281849
#########################################################
# API versions
#########################################################
jei_version=19.5.0.35
jei_version=19.8.2.99
curios_version=9.0.5+1.21
top_version=1.21_neo-12.0.3-5
ffs_version=3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import me.desht.pneumaticcraft.api.misc.Symbols;
import me.desht.pneumaticcraft.client.gui.AbstractPneumaticCraftContainerScreen;
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.gui.handlers.IGuiClickableArea;
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.recipe.IFocusFactory;
Expand Down Expand Up @@ -66,31 +67,29 @@ public void onClick(IFocusFactory focusFactory, IRecipesGui recipesGui) {
}

@Override
public List<Component> getTooltipStrings() {
public void getTooltip(ITooltipBuilder tooltip) {
Collection<ItemStack> items = gui.getTargetItems();
Collection<FluidStack> fluids = gui.getTargetFluids();
ImmutableList.Builder<Component> builder = ImmutableList.builder();
if (!items.isEmpty() || !fluids.isEmpty()) {
builder.add(Component.literal("Current Recipe:").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.literal("Current Recipe:").withStyle(ChatFormatting.GRAY));
for (ItemStack stack : items) {
if (!stack.isEmpty()) {
builder.add(Component.literal(Symbols.ARROW_RIGHT + " ").append(stack.getHoverName())
tooltip.add(Component.literal(Symbols.ARROW_RIGHT + " ").append(stack.getHoverName())
.withStyle(ChatFormatting.YELLOW));
}
}
for (FluidStack stack : fluids) {
if (!stack.isEmpty()) {
builder.add(Component.literal(Symbols.ARROW_RIGHT + " ").append(stack.getHoverName())
tooltip.add(Component.literal(Symbols.ARROW_RIGHT + " ").append(stack.getHoverName())
.withStyle(ChatFormatting.AQUA));
}
}
if (Minecraft.getInstance().options.advancedItemTooltips) {
builder.add(Component.literal(gui.te.getCurrentRecipeIdSynced()).withStyle(ChatFormatting.DARK_GRAY));
tooltip.add(Component.literal(gui.te.getCurrentRecipeIdSynced()).withStyle(ChatFormatting.DARK_GRAY));
}
builder.add(Component.empty());
tooltip.add(Component.empty());
}
builder.add(Component.translatable("jei.tooltip.show.recipes"));
return builder.build();
tooltip.add(Component.translatable("jei.tooltip.show.recipes"));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,37 @@ static IGuiProperties getGuiProperties(AbstractPneumaticCraftScreen gui) {

private record GuiProps(AbstractPneumaticCraftScreen gui) implements IGuiProperties {
@Override
public Class<? extends Screen> getScreenClass() {
public Class<? extends Screen> screenClass() {
return gui.getClass();
}

@Override
public int getGuiLeft() {
public int guiLeft() {
return gui.guiLeft;
}

@Override
public int getGuiTop() {
public int guiTop() {
return gui.guiTop;
}

@Override
public int getGuiXSize() {
public int guiXSize() {
return gui.xSize;
}

@Override
public int getGuiYSize() {
public int guiYSize() {
return gui.ySize;
}

@Override
public int getScreenWidth() {
public int screenWidth() {
return gui.width;
}

@Override
public int getScreenHeight() {
public int screenHeight() {
return gui.height;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.neoforge.NeoForgeTypes;
Expand All @@ -33,13 +34,9 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.fluids.FluidStack;

import java.util.ArrayList;
import java.util.List;

import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate;

public class JEIAmadronTradeCategory extends AbstractPNCCategory<AmadronRecipe> {
Expand Down Expand Up @@ -85,12 +82,10 @@ public void draw(AmadronRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGrap
}

@Override
public List<Component> getTooltipStrings(AmadronRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
List<Component> res = new ArrayList<>();
public void getTooltip(ITooltipBuilder tooltip, AmadronRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
if (recipe instanceof AmadronOffer offer && mouseX >= 22 && mouseX <= 51) {
res.addAll(WidgetAmadronOffer.makeTooltip(offer, -1));
tooltip.addAll(WidgetAmadronOffer.makeTooltip(offer, -1));
}
return res;
}

private static class FluidTextOverlay implements IDrawable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
import me.desht.pneumaticcraft.lib.Textures;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.gui.inputs.IJeiInputHandler;
import mezz.jei.api.gui.inputs.IJeiUserInput;
import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder;
import mezz.jei.api.neoforge.NeoForgeTypes;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IFocusGroup;
Expand All @@ -37,7 +41,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -47,6 +51,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.FluidType;
Expand All @@ -56,6 +61,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;

import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate;

Expand All @@ -64,10 +70,10 @@ public class JEIBlockHeatPropertiesCategory extends AbstractPNCCategory<HeatProp
private final IDrawable coldArea;
private final IDrawable air;

private static final Rect2i INPUT_AREA = new Rect2i(65, 44, 18, 18);
private static final Rect2i COLD_AREA = new Rect2i(5, 44, 18, 18);
private static final Rect2i HOT_AREA = new Rect2i(125, 44, 18, 18);
private static final Rect2i[] OUTPUT_AREAS = new Rect2i[] { COLD_AREA, HOT_AREA };
private static final ScreenRectangle INPUT_AREA = new ScreenRectangle(65, 44, 18, 18);
private static final ScreenRectangle COLD_AREA = new ScreenRectangle(5, 44, 18, 18);
private static final ScreenRectangle HOT_AREA = new ScreenRectangle(125, 44, 18, 18);
private static final ScreenRectangle[] OUTPUT_AREAS = new ScreenRectangle[] { COLD_AREA, HOT_AREA };

public JEIBlockHeatPropertiesCategory() {
super(RecipeTypes.HEAT_PROPERTIES,
Expand All @@ -83,6 +89,13 @@ public JEIBlockHeatPropertiesCategory() {
this.air = guiHelper().createDrawable(Textures.GUI_JEI_HEAT_PROPERTIES, 150, 36, 16, 16);
}

@Override
public void createRecipeExtras(IRecipeExtrasBuilder builder, HeatPropertiesRecipe recipe, IFocusGroup focuses) {
builder.addInputHandler(new ClickHandler(INPUT_AREA, recipe, HeatPropertiesRecipe::getBlock));
builder.addInputHandler(new ClickHandler(COLD_AREA, recipe, r -> r.getTransformCold().map(BlockBehaviour.BlockStateBase::getBlock).orElse(null)));
builder.addInputHandler(new ClickHandler(HOT_AREA, recipe, r -> r.getTransformHot().map(BlockBehaviour.BlockStateBase::getBlock).orElse(null)));
}

public static List<HeatPropertiesRecipe> getAllRecipes() {
// FIXME filtering out recipes whose input block has no item (e.g. minecraft:fire) is a kludge:
// it suppresses JEI errors when loading recipes, but such recipes still aren't shown in JEI
Expand All @@ -105,7 +118,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, HeatPropertiesRecipe recipe,

for (int idx = 0; idx < 2; idx++) {
if (!fluids.get(idx).isEmpty()) {
builder.addSlot(RecipeIngredientRole.OUTPUT, OUTPUT_AREAS[idx].getX() + 2, OUTPUT_AREAS[idx].getY() - 1)
builder.addSlot(RecipeIngredientRole.OUTPUT, OUTPUT_AREAS[idx].position().x() + 2, OUTPUT_AREAS[idx].position().y() - 1)
.addIngredient(NeoForgeTypes.FLUID_STACK, fluids.get(idx));
} else if (!items.get(idx).isEmpty()) {
builder.addInvisibleIngredients(RecipeIngredientRole.OUTPUT)
Expand Down Expand Up @@ -137,7 +150,7 @@ private void setInputIngredient(IRecipeLayoutBuilder builder, HeatPropertiesReci
Block block = recipe.getBlock();
if (block instanceof LiquidBlock l) {
FluidStack stack = new FluidStack(l.fluid, FluidType.BUCKET_VOLUME);
builder.addSlot(RecipeIngredientRole.INPUT, INPUT_AREA.getX() + 2, INPUT_AREA.getY() - 1)
builder.addSlot(RecipeIngredientRole.INPUT, INPUT_AREA.position().x() + 2, INPUT_AREA.position().y() - 1)
.addIngredient(NeoForgeTypes.FLUID_STACK, stack);
} else {
// items are rendered as blocks by renderBlock()
Expand Down Expand Up @@ -166,17 +179,17 @@ public void draw(HeatPropertiesRecipe recipe, IRecipeSlotsView recipeSlotsView,

boolean showCapacity = false;
if (recipe.getTransformCold().isPresent()) {
coldArea.draw(graphics, INPUT_AREA.getX() - coldArea.getWidth() - 5, 42);
coldArea.draw(graphics, INPUT_AREA.position().x() - coldArea.getWidth() - 5, 42);
showCapacity = true;
}
if (recipe.getTransformHot().isPresent()) {
hotArea.draw(graphics, HOT_AREA.getX() - hotArea.getWidth() - 5, 42);
hotArea.draw(graphics, HOT_AREA.position().x() - hotArea.getWidth() - 5, 42);
showCapacity = true;
}

renderBlock(recipe.getBlockState(), graphics, INPUT_AREA.getX() + 9, INPUT_AREA.getY() + 1);
recipe.getTransformCold().ifPresent(state -> renderBlock(state, graphics, COLD_AREA.getX() + 9, COLD_AREA.getY() + 1));
recipe.getTransformHot().ifPresent(state -> renderBlock(state, graphics, HOT_AREA.getX() + 9, HOT_AREA.getY() + 1));
renderBlock(recipe.getBlockState(), graphics, INPUT_AREA.position().x() + 9, INPUT_AREA.position().y() + 1);
recipe.getTransformCold().ifPresent(state -> renderBlock(state, graphics, COLD_AREA.position().x() + 9, COLD_AREA.position().y() + 1));
recipe.getTransformHot().ifPresent(state -> renderBlock(state, graphics, HOT_AREA.position().x() + 9, HOT_AREA.position().y() + 1));

if (showCapacity) {
recipe.getHeatCapacity().ifPresent(heatCapacity -> {
Expand All @@ -189,57 +202,33 @@ public void draw(HeatPropertiesRecipe recipe, IRecipeSlotsView recipeSlotsView,
}

@Override
public boolean handleInput(HeatPropertiesRecipe recipe, double mouseX, double mouseY, InputConstants.Key input) {
if (input.getType() == InputConstants.Type.MOUSE) {
int mouseButton = input.getValue();
IFocus<?> focus = null;
if (INPUT_AREA.contains((int) mouseX, (int) mouseY)) {
focus = makeFocus(recipe.getBlock(), mouseButton == 0 ? RecipeIngredientRole.OUTPUT : RecipeIngredientRole.INPUT);
} else if (recipe.getTransformCold().isPresent() && COLD_AREA.contains((int) mouseX, (int) mouseY)) {
focus = makeFocus(recipe.getTransformCold().get().getBlock(), mouseButton == 0 ? RecipeIngredientRole.OUTPUT : RecipeIngredientRole.INPUT);
} else if (recipe.getTransformHot().isPresent() && HOT_AREA.contains((int) mouseX, (int) mouseY)) {
focus = makeFocus(recipe.getTransformHot().get().getBlock(), mouseButton == 0 ? RecipeIngredientRole.OUTPUT : RecipeIngredientRole.INPUT);
}
if (focus != null) {
JEIPlugin.recipesGui.show(focus);
return true;
}
}
return false;
}

@Override
public List<Component> getTooltipStrings(HeatPropertiesRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
List<Component> l = new ArrayList<>();
if (INPUT_AREA.contains((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getBlock(), l);
} else if (recipe.getTransformCold().isPresent() && COLD_AREA.contains((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getTransformCold().get().getBlock(), l);
} else if (recipe.getTransformHot().isPresent() && HOT_AREA.contains((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getTransformHot().get().getBlock(), l);
public void getTooltip(ITooltipBuilder tooltip, HeatPropertiesRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
if (INPUT_AREA.containsPoint((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getBlock(), tooltip);
} else if (recipe.getTransformCold().isPresent() && COLD_AREA.containsPoint((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getTransformCold().get().getBlock(), tooltip);
} else if (recipe.getTransformHot().isPresent() && HOT_AREA.containsPoint((int)mouseX, (int)mouseY)) {
addTooltip(recipe.getTransformHot().get().getBlock(), tooltip);
} else if (mouseY > 20 && mouseY < 30) {
l.add(xlate("pneumaticcraft.gui.jei.tooltip.thermalResistance"));
tooltip.add(xlate("pneumaticcraft.gui.jei.tooltip.thermalResistance"));
} else if (recipe.getHeatCapacity().isPresent() && mouseY > 62) {
l.add(xlate("pneumaticcraft.gui.jei.tooltip.heatCapacity"));
tooltip.add(xlate("pneumaticcraft.gui.jei.tooltip.heatCapacity"));
}
return l;
super.getTooltip(tooltip, recipe, recipeSlotsView, mouseX, mouseY);
}

private IFocus<?> makeFocus(Block block, RecipeIngredientRole mode) {
return block == Blocks.AIR || block instanceof LiquidBlock ?
null :
JEIPlugin.jeiHelpers.getFocusFactory().createFocus(mode, VanillaTypes.ITEM_STACK, new ItemStack(block));
}

private void addTooltip(Block block, List<Component> list) {
private void addTooltip(Block block, ITooltipBuilder tooltip) {
ItemStack stack = new ItemStack(block);
list.add(stack.getHoverName());
tooltip.add(stack.getHoverName());
List<Component> list = new ArrayList<>();
stack.getItem().appendHoverText(stack, Item.TooltipContext.of(ClientUtils.getClientLevel()), list, ClientUtils.hasShiftDown() ? Default.ADVANCED : Default.NORMAL);
tooltip.addAll(list);
if (Minecraft.getInstance().options.advancedItemTooltips) {
String regName = PneumaticCraftUtils.getRegistryName(stack.getItem()).map(ResourceLocation::toString).orElse("?");
list.add(Component.literal(regName).withStyle(ChatFormatting.DARK_GRAY));
tooltip.add(Component.literal(regName).withStyle(ChatFormatting.DARK_GRAY));
}
list.add(Component.literal(ModNameCache.getModName(stack.getItem())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC));
tooltip.add(Component.literal(ModNameCache.getModName(stack.getItem())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC));
}

private void renderBlock(BlockState state, GuiGraphics graphics, int x, int y) {
Expand All @@ -253,4 +242,32 @@ private void renderBlock(BlockState state, GuiGraphics graphics, int x, int y) {
}
}
}

public record ClickHandler(ScreenRectangle area, HeatPropertiesRecipe recipe, Function<HeatPropertiesRecipe, Block> blockGetter) implements IJeiInputHandler {
@Override
public ScreenRectangle getArea() {
return area;
}

@Override
public boolean handleInput(double mouseX, double mouseY, IJeiUserInput input) {
if (input.getKey().getType() == InputConstants.Type.MOUSE) {
int mouseButton = input.getKey().getValue();
IFocus<?> focus = makeFocus(blockGetter.apply(recipe), mouseButton == 0 ? RecipeIngredientRole.OUTPUT : RecipeIngredientRole.INPUT);
if (focus != null) {
if (!input.isSimulate()) {
JEIPlugin.recipesGui.show(focus);
}
return true;
}
}
return false;
}

private static IFocus<?> makeFocus(Block block, RecipeIngredientRole mode) {
return block == null || block == Blocks.AIR || block instanceof LiquidBlock ?
null :
JEIPlugin.jeiHelpers.getFocusFactory().createFocus(mode, VanillaTypes.ITEM_STACK, new ItemStack(block));
}
}
}
Loading

0 comments on commit aeed609

Please sign in to comment.