From a46d27416566d15affc2f536106f0a95e4a78154 Mon Sep 17 00:00:00 2001 From: Relentless Date: Mon, 7 Nov 2022 13:45:39 +0100 Subject: [PATCH] port 1.18 changes - JEI indicator placement rework - format portuguese translation --- CHANGELOG.md | 8 ++++ .../unified/compat/AlmostJEI.java | 20 +++++++++ .../unified/compat/RecipeIndicator.java | 11 ++--- .../unified/mixin/JeiRecipeLayoutMixin.java | 44 +++++++++++-------- .../assets/almostunified/lang/pt_br.json | 17 ++++--- 5 files changed, 68 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0fdd2e..15d11eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +## Unreleased + +### Changed +- improved the placement for the recipe indicator icon in JEI + +### Fixed +- misaligned tooltips in JEI + ## [0.2.2] - 2022-11-01 ### Added diff --git a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java index 2c1a438..7b1bad3 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java @@ -3,10 +3,15 @@ package com.almostreliable.unified.compat; import com.almostreliable.unified.BuildConfig; import com.almostreliable.unified.config.Config; import com.almostreliable.unified.config.UnifyConfig; +import com.almostreliable.unified.recipe.CRTLookup; +import com.almostreliable.unified.utils.Utils; +import com.mojang.blaze3d.vertex.PoseStack; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.runtime.IJeiRuntime; +import net.minecraft.client.renderer.Rect2i; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -32,4 +37,19 @@ public class AlmostJEI implements IModPlugin { jei.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, items); } } + + public static void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, IRecipeCategory recipeCategory, R recipe) { + var recipeId = recipeCategory.getRegistryName(recipe); + if (recipeId == null) return; + + var link = CRTLookup.getLink(recipeId); + if (link == null) return; + + var area = new Rect2i(posX, posY, RecipeIndicator.RENDER_SIZE, RecipeIndicator.RENDER_SIZE); + RecipeIndicator.renderIndicator(stack, area); + if (mX >= area.getX() && mX <= area.getX() + area.getWidth() && + mY >= area.getY() && mY <= area.getY() + area.getHeight()) { + Utils.renderTooltip(stack, mX, mY, RecipeIndicator.constructTooltip(link)); + } + } } diff --git a/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java b/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java index fe0a25e..e66c19c 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java @@ -15,12 +15,13 @@ import java.util.List; public final class RecipeIndicator { - public static final int SIZE = 16; + public static final int RENDER_SIZE = 10; + private static final int TEXTURE_SIZE = 16; private static final ResourceLocation TEXTURE = Utils.getRL("textures/ingot.png"); private RecipeIndicator() {} - public static List constructTooltip(ClientRecipeLink link) { + static List constructTooltip(ClientRecipeLink link) { var unified = Component.translatable(Utils.prefix("unified")).append(": ") .withStyle(c -> c.withColor(ChatFormatting.AQUA)); unified.append(Component.translatable(Utils.prefix(link.isUnified() ? "yes" : "no")) @@ -41,14 +42,14 @@ public final class RecipeIndicator { ); } - public static void renderIndicator(PoseStack poseStack, Rect2i area) { + static void renderIndicator(PoseStack poseStack, Rect2i area) { poseStack.pushPose(); poseStack.translate(area.getX(), area.getY(), 0); - var scale = area.getWidth() / (float) SIZE; + var scale = area.getWidth() / (float) TEXTURE_SIZE; poseStack.scale(scale, scale, scale); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0, TEXTURE); - GuiComponent.blit(poseStack, 0, 0, 0, 0, SIZE, SIZE, SIZE, SIZE); + GuiComponent.blit(poseStack, 0, 0, 0, 0, TEXTURE_SIZE, TEXTURE_SIZE, TEXTURE_SIZE, TEXTURE_SIZE); poseStack.popPose(); } } diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java index 37ec36f..d2307b0 100644 --- a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java +++ b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java @@ -1,46 +1,54 @@ package com.almostreliable.unified.mixin; +import com.almostreliable.unified.compat.AlmostJEI; import com.almostreliable.unified.compat.RecipeIndicator; -import com.almostreliable.unified.recipe.CRTLookup; -import com.almostreliable.unified.utils.Utils; import com.mojang.blaze3d.vertex.PoseStack; import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.common.gui.recipes.layout.RecipeLayout; -import net.minecraft.client.renderer.Rect2i; +import mezz.jei.common.gui.recipes.layout.RecipeTransferButton; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import javax.annotation.Nullable; + @Mixin(RecipeLayout.class) public abstract class JeiRecipeLayoutMixin { - @Shadow(remap = false) @Final - private static int RECIPE_BORDER_PADDING; @Shadow(remap = false) @Final private IRecipeCategory recipeCategory; @Shadow(remap = false) @Final private R recipe; + @Shadow(remap = false) @Final + @Nullable private RecipeTransferButton recipeTransferButton; + + @Unique + private boolean handled; @Inject(method = "drawRecipe", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD) - private void unified$drawRecipe(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci, IDrawable background, int mX, int mY, IDrawable categoryBackground, int x, int y) { - var recipeId = recipeCategory.getRegistryName(recipe); - if (recipeId == null) return; + private void unified$drawCornerIndicator(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci, IDrawable background, int mX, int mY, IDrawable categoryBackground, int x, int y) { + if (recipeTransferButton != null && recipeTransferButton.visible) return; + var posX = x - RecipeIndicator.RENDER_SIZE; + var posY = y - RecipeIndicator.RENDER_SIZE; + AlmostJEI.handleIndicator(stack, mX, mY, posX, posY, recipeCategory, recipe); + handled = true; + } - var link = CRTLookup.getLink(recipeId); - if (link == null) return; - - var posX = x - RecipeIndicator.SIZE / 2 - RECIPE_BORDER_PADDING + 1; - var posY = y - RecipeIndicator.SIZE / 2 - RECIPE_BORDER_PADDING + 1; - var area = new Rect2i(posX, posY, 10, 10); - RecipeIndicator.renderIndicator(stack, area); - if (mX >= area.getX() && mX <= area.getX() + area.getWidth() && - mY >= area.getY() && mY <= area.getY() + area.getHeight()) { - Utils.renderTooltip(stack, mX, mY, RecipeIndicator.constructTooltip(link)); + @Inject(method = "drawRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getInstance()Lnet/minecraft/client/Minecraft;")) + private void unified$drawButtonIndicator(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci) { + assert recipeTransferButton != null; + if (handled) { + handled = false; + return; } + var posX = recipeTransferButton.x + (RecipeTransferButton.RECIPE_BUTTON_SIZE - RecipeIndicator.RENDER_SIZE) / 2; + var posY = recipeTransferButton.y - RecipeIndicator.RENDER_SIZE - 2; + AlmostJEI.handleIndicator(stack, mouseX, mouseY, posX, posY, recipeCategory, recipe); } } diff --git a/Common/src/main/resources/assets/almostunified/lang/pt_br.json b/Common/src/main/resources/assets/almostunified/lang/pt_br.json index 360f156..2f12a3f 100644 --- a/Common/src/main/resources/assets/almostunified/lang/pt_br.json +++ b/Common/src/main/resources/assets/almostunified/lang/pt_br.json @@ -1,9 +1,8 @@ -{ - "almostunified.description": "Modificado por Almost Unified!", - "almostunified.warning": "Não informe a receita ao autor original.", - "almostunified.unified": "Unificado", - "almostunified.duplicate": "Tinha duplicatas", - "almostunified.yes": "Sim", - "almostunified.no": "Não" - } - \ No newline at end of file +{ + "almostunified.description": "Modificado por Almost Unified!", + "almostunified.warning": "Não informe a receita ao autor original.", + "almostunified.unified": "Unificado", + "almostunified.duplicate": "Tinha duplicatas", + "almostunified.yes": "Sim", + "almostunified.no": "Não" +}