mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
parent
e0649dedd7
commit
702d1f0829
9 changed files with 65 additions and 111 deletions
|
@ -34,7 +34,6 @@ dependencies {
|
||||||
|
|
||||||
// compile time mods
|
// compile time mods
|
||||||
modCompileOnly("mezz.jei:jei-$minecraftVersion-common-api:$jeiVersion") // required for jei plugin
|
modCompileOnly("mezz.jei:jei-$minecraftVersion-common-api:$jeiVersion") // required for jei plugin
|
||||||
modCompileOnly("mezz.jei:jei-$minecraftVersion-lib:$jeiVersion") // required for jei mixin
|
|
||||||
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:$reiVersion") // required for rei plugin
|
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:$reiVersion") // required for rei plugin
|
||||||
modCompileOnly("dev.emi:emi-xplat-intermediary:$emiVersion+$minecraftVersion:api") // required for emi plugin
|
modCompileOnly("dev.emi:emi-xplat-intermediary:$emiVersion+$minecraftVersion:api") // required for emi plugin
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,22 @@ import com.almostreliable.unified.AlmostUnifiedFallbackRuntime;
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
import com.almostreliable.unified.api.ModConstants;
|
||||||
import com.almostreliable.unified.config.UnifyConfig;
|
import com.almostreliable.unified.config.UnifyConfig;
|
||||||
import com.almostreliable.unified.recipe.CRTLookup;
|
import com.almostreliable.unified.recipe.CRTLookup;
|
||||||
|
import com.almostreliable.unified.recipe.ClientRecipeTracker;
|
||||||
import com.almostreliable.unified.utils.Utils;
|
import com.almostreliable.unified.utils.Utils;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore;
|
import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore;
|
||||||
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.gui.ingredient.IRecipeSlotsView;
|
||||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||||
|
import mezz.jei.api.recipe.category.extensions.IRecipeCategoryDecorator;
|
||||||
|
import mezz.jei.api.registration.IAdvancedRegistration;
|
||||||
import mezz.jei.api.runtime.IJeiRuntime;
|
import mezz.jei.api.runtime.IJeiRuntime;
|
||||||
import net.minecraft.client.renderer.Rect2i;
|
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;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@ -44,19 +49,40 @@ public class AlmostJEI implements IModPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R> void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, IRecipeCategory<R> recipeCategory, R recipe) {
|
@Override
|
||||||
var recipeId = recipeCategory.getRegistryName(recipe);
|
public void registerAdvanced(IAdvancedRegistration registration) {
|
||||||
if (recipeId == null) return;
|
var recipeTypes = registration.getJeiHelpers().getAllRecipeTypes();
|
||||||
|
recipeTypes.forEach(rt -> registration.addRecipeCategoryDecorator(rt, new Decorator<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Decorator<T> implements IRecipeCategoryDecorator<T> {
|
||||||
|
|
||||||
var link = CRTLookup.getLink(recipeId);
|
private static final int RECIPE_BORDER_PADDING = 4;
|
||||||
if (link == null) return;
|
|
||||||
|
|
||||||
var area = new Rect2i(posX, posY, RecipeIndicator.RENDER_SIZE, RecipeIndicator.RENDER_SIZE);
|
@Override
|
||||||
RecipeIndicator.renderIndicator(stack, area);
|
public void draw(T recipe, IRecipeCategory<T> recipeCategory, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) {
|
||||||
if (mX >= area.getX() && mX <= area.getX() + area.getWidth() &&
|
var recipeLink = resolveLink(recipeCategory, recipe);
|
||||||
mY >= area.getY() && mY <= area.getY() + area.getHeight()) {
|
if (recipeLink == null) return;
|
||||||
Utils.renderTooltip(stack, mX, mY, RecipeIndicator.constructTooltip(link));
|
|
||||||
|
var pX = recipeCategory.getWidth() + (2 * RECIPE_BORDER_PADDING) - RecipeIndicator.RENDER_SIZE;
|
||||||
|
var pY = recipeCategory.getHeight() + (2 * RECIPE_BORDER_PADDING) - RecipeIndicator.RENDER_SIZE;
|
||||||
|
RecipeIndicator.renderIndicator(
|
||||||
|
poseStack,
|
||||||
|
new Rect2i(pX, pY, RecipeIndicator.RENDER_SIZE, RecipeIndicator.RENDER_SIZE)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mouseX >= pX && mouseX <= pX + RecipeIndicator.RENDER_SIZE &&
|
||||||
|
mouseY >= pY && mouseY <= pY + RecipeIndicator.RENDER_SIZE) {
|
||||||
|
RecipeIndicator.renderTooltip(poseStack, recipeLink, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static <R> ClientRecipeTracker.ClientRecipeLink resolveLink(IRecipeCategory<R> recipeCategory, R recipe) {
|
||||||
|
var recipeId = recipeCategory.getRegistryName(recipe);
|
||||||
|
if (recipeId == null) return null;
|
||||||
|
|
||||||
|
return CRTLookup.getLink(recipeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.almostreliable.unified.utils.Utils;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiComponent;
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.client.renderer.Rect2i;
|
import net.minecraft.client.renderer.Rect2i;
|
||||||
|
@ -42,6 +43,20 @@ public final class RecipeIndicator {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void renderTooltip(PoseStack poseStack, ClientRecipeLink link, double mouseX, double mouseY) {
|
||||||
|
var mc = Minecraft.getInstance();
|
||||||
|
var font = mc.font;
|
||||||
|
var screen = mc.screen;
|
||||||
|
if (screen == null) return;
|
||||||
|
|
||||||
|
var tooltip = constructTooltip(link).stream()
|
||||||
|
.map(c -> font.split(c, screen.width - (int) mouseX - 200))
|
||||||
|
.flatMap(List::stream)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
screen.renderTooltip(poseStack, tooltip, (int) mouseX, (int) mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -90,17 +90,25 @@ public class DuplicationConfig extends Config {
|
||||||
JsonCompare.CompareSettings defaultRules = safeGet(() -> createCompareSet(json.getAsJsonObject(
|
JsonCompare.CompareSettings defaultRules = safeGet(() -> createCompareSet(json.getAsJsonObject(
|
||||||
DEFAULT_DUPLICATE_RULES)),
|
DEFAULT_DUPLICATE_RULES)),
|
||||||
Defaults.getDefaultDuplicateRules(platform));
|
Defaults.getDefaultDuplicateRules(platform));
|
||||||
LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> overrideRules = safeGet(() -> json
|
LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> overrideRules = safeGet(
|
||||||
|
() -> getOverrideRules(json), Defaults.getDefaultDuplicateOverrides(platform)
|
||||||
|
);
|
||||||
|
boolean strictMode = safeGet(() -> json.get(STRICT_MODE).getAsBoolean(), false);
|
||||||
|
|
||||||
|
return new DuplicationConfig(defaultRules, overrideRules, ignoreRecipeTypes, ignoreRecipes, strictMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extracted as method because `safeGet` couldn't cast the type... Seems to be an old SDK bug :-)
|
||||||
|
// https://bugs.openjdk.org/browse/JDK-8324860
|
||||||
|
private LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> getOverrideRules(JsonObject json) {
|
||||||
|
return json
|
||||||
.getAsJsonObject(OVERRIDE_DUPLICATE_RULES)
|
.getAsJsonObject(OVERRIDE_DUPLICATE_RULES)
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(entry -> new ResourceLocation(entry.getKey()),
|
.collect(Collectors.toMap(entry -> new ResourceLocation(entry.getKey()),
|
||||||
entry -> createCompareSet(entry.getValue().getAsJsonObject()),
|
entry -> createCompareSet(entry.getValue().getAsJsonObject()),
|
||||||
(a, b) -> b,
|
(a, b) -> b,
|
||||||
LinkedHashMap::new)), Defaults.getDefaultDuplicateOverrides(platform));
|
LinkedHashMap::new));
|
||||||
boolean strictMode = safeGet(() -> json.get(STRICT_MODE).getAsBoolean(), false);
|
|
||||||
|
|
||||||
return new DuplicationConfig(defaultRules, overrideRules, ignoreRecipeTypes, ignoreRecipes, strictMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonCompare.CompareSettings createCompareSet(JsonObject rules) {
|
private JsonCompare.CompareSettings createCompareSet(JsonObject rules) {
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.almostreliable.unified.mixin;
|
|
||||||
|
|
||||||
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
|
||||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.BooleanSupplier;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class AlmostMixinPlugin implements IMixinConfigPlugin {
|
|
||||||
|
|
||||||
private static final BooleanSupplier TRUE = () -> true;
|
|
||||||
private static final Map<String, BooleanSupplier> CONDITIONS = ImmutableMap.of(
|
|
||||||
"com.almostreliable.unified.mixin.compat.JeiRecipeLayoutMixin", modLoaded(ModConstants.JEI)
|
|
||||||
);
|
|
||||||
|
|
||||||
private static BooleanSupplier modLoaded(String id) {
|
|
||||||
return () -> AlmostUnifiedPlatform.INSTANCE.isModLoaded(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad(String mixinPackage) {}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "ReturnOfNull", "DataFlowIssue" })
|
|
||||||
@Override
|
|
||||||
public String getRefMapperConfig() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
|
||||||
return CONDITIONS.getOrDefault(mixinClassName, TRUE).getAsBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "ReturnOfNull", "DataFlowIssue" })
|
|
||||||
@Override
|
|
||||||
public List<String> getMixins() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.almostreliable.unified.mixin.compat;
|
|
||||||
|
|
||||||
import com.almostreliable.unified.compat.AlmostJEI;
|
|
||||||
import com.almostreliable.unified.compat.RecipeIndicator;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import mezz.jei.api.gui.drawable.IDrawable;
|
|
||||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
|
||||||
import mezz.jei.library.gui.recipes.RecipeLayout;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Mixin(RecipeLayout.class)
|
|
||||||
public abstract class JeiRecipeLayoutMixin<R> {
|
|
||||||
|
|
||||||
@Shadow(remap = false) @Final
|
|
||||||
private IRecipeCategory<R> recipeCategory;
|
|
||||||
@Shadow(remap = false) @Final
|
|
||||||
private R recipe;
|
|
||||||
|
|
||||||
@Inject(method = "drawRecipe", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
|
|
||||||
private void unified$catchLayoutInfo(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci, IDrawable background, int mX, int mY, int x, int y) {
|
|
||||||
var posX = x - RecipeIndicator.RENDER_SIZE;
|
|
||||||
var posY = y - RecipeIndicator.RENDER_SIZE;
|
|
||||||
AlmostJEI.handleIndicator(stack, mX, mY, posX, posY, recipeCategory, recipe);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
|
|
||||||
package com.almostreliable.unified.mixin.compat;
|
|
||||||
|
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
|
|
@ -3,7 +3,6 @@
|
||||||
"minVersion": "0.8.5",
|
"minVersion": "0.8.5",
|
||||||
"package": "com.almostreliable.unified.mixin",
|
"package": "com.almostreliable.unified.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"plugin": "com.almostreliable.unified.mixin.AlmostMixinPlugin",
|
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"runtime.RecipeManagerMixin",
|
"runtime.RecipeManagerMixin",
|
||||||
"runtime.TagLoaderMixin",
|
"runtime.TagLoaderMixin",
|
||||||
|
@ -11,7 +10,6 @@
|
||||||
"unifier.TieredItemMixin"
|
"unifier.TieredItemMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"compat.JeiRecipeLayoutMixin",
|
|
||||||
"runtime.ClientPacketListenerMixin"
|
"runtime.ClientPacketListenerMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|
|
@ -21,7 +21,7 @@ junitVersion = 5.9.0
|
||||||
parchmentVersion = 2022.11.27
|
parchmentVersion = 2022.11.27
|
||||||
|
|
||||||
# Mod Dependencies
|
# Mod Dependencies
|
||||||
jeiVersion = 11.6.0.1012
|
jeiVersion = 11.8.0.1030
|
||||||
reiVersion = 9.1.580
|
reiVersion = 9.1.580
|
||||||
emiVersion = 1.1.2
|
emiVersion = 1.1.2
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue