port 1.18 changes

- JEI indicator placement rework
- format portuguese translation
This commit is contained in:
Relentless 2022-11-07 13:45:39 +01:00
parent ab8049fab8
commit a46d274165
No known key found for this signature in database
GPG key ID: 759D97B8C6F25265
5 changed files with 68 additions and 32 deletions

View file

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning]. 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 ## [0.2.2] - 2022-11-01
### Added ### Added

View file

@ -3,10 +3,15 @@ package com.almostreliable.unified.compat;
import com.almostreliable.unified.BuildConfig; import com.almostreliable.unified.BuildConfig;
import com.almostreliable.unified.config.Config; import com.almostreliable.unified.config.Config;
import com.almostreliable.unified.config.UnifyConfig; 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.IModPlugin;
import mezz.jei.api.JeiPlugin; import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.runtime.IJeiRuntime; import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -32,4 +37,19 @@ public class AlmostJEI implements IModPlugin {
jei.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, items); jei.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, items);
} }
} }
public static <R> void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, IRecipeCategory<R> 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));
}
}
} }

View file

@ -15,12 +15,13 @@ import java.util.List;
public final class RecipeIndicator { 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 static final ResourceLocation TEXTURE = Utils.getRL("textures/ingot.png");
private RecipeIndicator() {} private RecipeIndicator() {}
public static List<Component> constructTooltip(ClientRecipeLink link) { static List<Component> constructTooltip(ClientRecipeLink link) {
var unified = Component.translatable(Utils.prefix("unified")).append(": ") var unified = Component.translatable(Utils.prefix("unified")).append(": ")
.withStyle(c -> c.withColor(ChatFormatting.AQUA)); .withStyle(c -> c.withColor(ChatFormatting.AQUA));
unified.append(Component.translatable(Utils.prefix(link.isUnified() ? "yes" : "no")) 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.pushPose();
poseStack.translate(area.getX(), area.getY(), 0); 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); poseStack.scale(scale, scale, scale);
RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, TEXTURE); 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(); poseStack.popPose();
} }
} }

View file

@ -1,46 +1,54 @@
package com.almostreliable.unified.mixin; package com.almostreliable.unified.mixin;
import com.almostreliable.unified.compat.AlmostJEI;
import com.almostreliable.unified.compat.RecipeIndicator; 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 com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.common.gui.recipes.layout.RecipeLayout; 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.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable;
@Mixin(RecipeLayout.class) @Mixin(RecipeLayout.class)
public abstract class JeiRecipeLayoutMixin<R> { public abstract class JeiRecipeLayoutMixin<R> {
@Shadow(remap = false) @Final
private static int RECIPE_BORDER_PADDING;
@Shadow(remap = false) @Final @Shadow(remap = false) @Final
private IRecipeCategory<R> recipeCategory; private IRecipeCategory<R> recipeCategory;
@Shadow(remap = false) @Final @Shadow(remap = false) @Final
private R recipe; 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) @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) { private void unified$drawCornerIndicator(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 (recipeTransferButton != null && recipeTransferButton.visible) return;
if (recipeId == null) 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); @Inject(method = "drawRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getInstance()Lnet/minecraft/client/Minecraft;"))
if (link == null) return; private void unified$drawButtonIndicator(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci) {
assert recipeTransferButton != null;
var posX = x - RecipeIndicator.SIZE / 2 - RECIPE_BORDER_PADDING + 1; if (handled) {
var posY = y - RecipeIndicator.SIZE / 2 - RECIPE_BORDER_PADDING + 1; handled = false;
var area = new Rect2i(posX, posY, 10, 10); return;
RecipeIndicator.renderIndicator(stack, area); }
if (mX >= area.getX() && mX <= area.getX() + area.getWidth() && var posX = recipeTransferButton.x + (RecipeTransferButton.RECIPE_BUTTON_SIZE - RecipeIndicator.RENDER_SIZE) / 2;
mY >= area.getY() && mY <= area.getY() + area.getHeight()) { var posY = recipeTransferButton.y - RecipeIndicator.RENDER_SIZE - 2;
Utils.renderTooltip(stack, mX, mY, RecipeIndicator.constructTooltip(link)); AlmostJEI.handleIndicator(stack, mouseX, mouseY, posX, posY, recipeCategory, recipe);
}
} }
} }

View file

@ -6,4 +6,3 @@
"almostunified.yes": "Sim", "almostunified.yes": "Sim",
"almostunified.no": "Não" "almostunified.no": "Não"
} }