diff --git a/Common/build.gradle.kts b/Common/build.gradle.kts index cb727c7..b917575 100644 --- a/Common/build.gradle.kts +++ b/Common/build.gradle.kts @@ -3,6 +3,7 @@ val junitVersion: String by project val minecraftVersion: String by project val fabricLoaderVersion: String by project +val reiVersion: String by project val jeiVersion: String by project val kubejsVersion: String by project val mappingsChannel: String by project @@ -22,15 +23,11 @@ base { } loom { - shareCaches() remapArchives.set(false) - setupRemappedVariants.set(false); + setupRemappedVariants.set(false) runConfigs.configureEach { ideConfigGenerated(false) } - mixin { - useLegacyMixinAp.set(false) - } } dependencies { @@ -42,6 +39,7 @@ dependencies { parchment("org.parchmentmc.data:$mappingsChannel-$minecraftVersion.2:$mappingsVersion@zip") }) + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:$reiVersion") // required for common rei plugin modCompileOnly("mezz.jei:jei-$minecraftVersion-common:$jeiVersion") // required for common jei plugin and mixin modCompileOnly("dev.latvian.mods:kubejs:$kubejsVersion") // required for common kubejs plugin @@ -51,14 +49,6 @@ dependencies { } tasks { - // TODO: test if this is necessary - processResources { - val buildProps = project.properties - - filesMatching("pack.mcmeta") { - expand(buildProps) - } - } withType { useJUnitPlatform() } diff --git a/Fabric/src/main/java/com/almostreliable/unified/compat/AlmostREI.java b/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java similarity index 94% rename from Fabric/src/main/java/com/almostreliable/unified/compat/AlmostREI.java rename to Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java index cdd065e..6bec17e 100644 --- a/Fabric/src/main/java/com/almostreliable/unified/compat/AlmostREI.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/AlmostREI.java @@ -1,5 +1,7 @@ package com.almostreliable.unified.compat; +import com.almostreliable.unified.AlmostUnifiedPlatform; +import com.almostreliable.unified.Platform; import com.almostreliable.unified.config.Config; import com.almostreliable.unified.config.UnifyConfig; import com.almostreliable.unified.recipe.CRTLookup; @@ -30,6 +32,9 @@ public class AlmostREI implements REIClientPlugin { @Override public void registerEntries(EntryRegistry registry) { + // REI compat layer will automatically hide entries for Forge through JEI + if (AlmostUnifiedPlatform.INSTANCE.getPlatform() == Platform.FORGE) return; + UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer()); if (config.reiOrJeiDisabled()) return; 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 4b4b75d..fe0a25e 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/RecipeIndicator.java @@ -5,7 +5,6 @@ import com.almostreliable.unified.utils.Utils; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.Rect2i; @@ -52,13 +51,4 @@ public final class RecipeIndicator { GuiComponent.blit(poseStack, 0, 0, 0, 0, SIZE, SIZE, SIZE, SIZE); poseStack.popPose(); } - - public static void renderTooltip(PoseStack poseStack, Rect2i area, int mX, int mY, ClientRecipeLink link) { - var screen = Minecraft.getInstance().screen; - if (screen == null) return; - if (mX >= area.getX() && mX <= area.getX() + area.getWidth() && - mY >= area.getY() && mY <= area.getY() + area.getHeight()) { - screen.renderComponentTooltip(poseStack, constructTooltip(link), mX, mY); - } - } } 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 1336ce8..96e07a7 100644 --- a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java +++ b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java @@ -5,6 +5,7 @@ import com.almostreliable.unified.recipe.CRTLookup; 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.TooltipRenderer; import mezz.jei.common.gui.recipes.layout.RecipeLayout; import net.minecraft.client.renderer.Rect2i; import org.spongepowered.asm.mixin.Final; @@ -37,6 +38,9 @@ public abstract class JeiRecipeLayoutMixin { var posY = y - RecipeIndicator.SIZE / 2 - RECIPE_BORDER_PADDING + 1; var area = new Rect2i(posX, posY, 10, 10); RecipeIndicator.renderIndicator(stack, area); - RecipeIndicator.renderTooltip(stack, area, mX, mY, link); + if (mX >= area.getX() && mX <= area.getX() + area.getWidth() && + mY >= area.getY() && mY <= area.getY() + area.getHeight()) { + TooltipRenderer.drawHoveringText(stack, RecipeIndicator.constructTooltip(link), mX, mY); + } } } diff --git a/Fabric/build.gradle.kts b/Fabric/build.gradle.kts index 640bf10..b9a616d 100644 --- a/Fabric/build.gradle.kts +++ b/Fabric/build.gradle.kts @@ -24,8 +24,6 @@ base { } loom { - shareCaches() - runs { named("client") { client() @@ -49,7 +47,7 @@ loom { } dependencies { - implementation(project(":Common", "namedElements")) { isTransitive = false } + compileOnly(project(":Common", "namedElements")) { isTransitive = false } minecraft("com.mojang:minecraft:$minecraftVersion") modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") @@ -60,7 +58,7 @@ dependencies { parchment("org.parchmentmc.data:$mappingsChannel-$minecraftVersion.2:$mappingsVersion@zip") }) - modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$reiVersion") // required for fabric rei plugin + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$reiVersion") // required for common rei plugin modCompileOnly("mezz.jei:jei-$minecraftVersion-fabric:$jeiVersion") // required for common jei plugin and mixin // runtime only when (fabricRecipeViewer) { @@ -90,20 +88,8 @@ dependencies { } tasks { - // TODO: test if this is necessary - jar { - from("LICENSE") { - rename { "${it}_${modName}" } - } - } - // TODO: test if this is necessary processResources { from(project(":Common").sourceSets.main.get().resources) - inputs.property("version", project.version) - - filesMatching("fabric.mod.json") { - expand("version" to project.version) - } } withType { source(project(":Common").sourceSets.main.get().allSource) diff --git a/Forge/build.gradle.kts b/Forge/build.gradle.kts index 5700d82..123bc69 100644 --- a/Forge/build.gradle.kts +++ b/Forge/build.gradle.kts @@ -25,7 +25,6 @@ base { } loom { - shareCaches() silentMojangMappingsLicense() runs { @@ -55,7 +54,7 @@ loom { } dependencies { - implementation(project(":Common", "namedElements")) { isTransitive = false } + compileOnly(project(":Common", "namedElements")) { isTransitive = false } minecraft("com.mojang:minecraft:$minecraftVersion") forge("net.minecraftforge:forge:$minecraftVersion-$forgeVersion") @@ -65,7 +64,7 @@ dependencies { parchment("org.parchmentmc.data:$mappingsChannel-$minecraftVersion.2:$mappingsVersion@zip") }) - modCompileOnly("me.shedaniel:RoughlyEnoughItems-forge:$reiVersion") // required for forge rei plugin | api does not work here! + modCompileOnly("me.shedaniel:RoughlyEnoughItems-forge:$reiVersion") // required for common rei plugin | api does not work here! modCompileOnly("mezz.jei:jei-$minecraftVersion-forge:$jeiVersion") // required for common jei plugin and mixin // runtime only when (forgeRecipeViewer) { @@ -97,20 +96,8 @@ dependencies { } tasks { - // TODO: test if this is necessary - jar { - from("LICENSE") { - rename { "${it}_${modName}" } - } - } - // TODO: test if this is necessary processResources { from(project(":Common").sourceSets.main.get().resources) - inputs.property("version", project.version) - - filesMatching("META-INF/mods.toml") { - expand("version" to project.version) - } } withType { source(project(":Common").sourceSets.main.get().allSource) diff --git a/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREI.java b/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREI.java deleted file mode 100644 index 0261491..0000000 --- a/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREI.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.almostreliable.unified.compat; - -import com.almostreliable.unified.recipe.CRTLookup; -import com.almostreliable.unified.recipe.ClientRecipeTracker; -import com.almostreliable.unified.utils.Utils; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.gui.DisplayRenderer; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.api.client.plugins.REIClientPlugin; -import me.shedaniel.rei.api.client.registry.category.ButtonArea; -import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; -import me.shedaniel.rei.api.client.registry.category.extension.CategoryExtensionProvider; -import me.shedaniel.rei.api.client.registry.display.DisplayCategory; -import me.shedaniel.rei.api.client.registry.display.DisplayCategoryView; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.registry.ReloadStage; -import me.shedaniel.rei.forge.REIPlugin; -import net.minecraft.client.renderer.Rect2i; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -import javax.annotation.Nullable; -import java.util.List; - -@REIPlugin(Dist.CLIENT) -@OnlyIn(Dist.CLIENT) -@SuppressWarnings("UnstableApiUsage") -public class AlmostREI implements REIClientPlugin { - - @Override - public void postStage(PluginManager manager, ReloadStage stage) { - if (stage != ReloadStage.END || !manager.equals(PluginManager.getClientInstance())) return; - CategoryRegistry.getInstance().forEach(category -> { - IndicatorExtension extension = new IndicatorExtension(category.getPlusButtonArea().orElse(null)); - category.registerExtension(Utils.cast(extension)); - }); - } - - @SuppressWarnings("OverrideOnly") - private record IndicatorExtension(@Nullable ButtonArea plusButtonArea) - implements CategoryExtensionProvider { - - @Override - public DisplayCategoryView provide(Display display, DisplayCategory category, DisplayCategoryView lastView) { - return display - .getDisplayLocation() - .map(CRTLookup::getLink) - .map(link -> (DisplayCategoryView) new IndicatorView(lastView, link)) - .orElse(lastView); - } - - private final class IndicatorView implements DisplayCategoryView { - - private final DisplayCategoryView lastView; - private final ClientRecipeTracker.ClientRecipeLink link; - - private IndicatorView(DisplayCategoryView lastView, ClientRecipeTracker.ClientRecipeLink link) { - this.lastView = lastView; - this.link = link; - } - - @Override - public DisplayRenderer getDisplayRenderer(Display display) { - return lastView.getDisplayRenderer(display); - } - - @Override - public List setupDisplay(Display display, Rectangle bounds) { - var widgets = lastView.setupDisplay(display, bounds); - var area = calculateArea(bounds); - widgets.add(Widgets.createDrawableWidget((helper, stack, mX, mY, delta) -> - RecipeIndicator.renderIndicator(stack, area))); - var tooltipArea = new Rectangle(area.getX(), area.getY(), area.getWidth(), area.getHeight()); - widgets.add(Widgets.createTooltip(tooltipArea, RecipeIndicator.constructTooltip(link))); - return widgets; - } - - private Rect2i calculateArea(Rectangle bounds) { - if (plusButtonArea != null) { - var area = plusButtonArea.get(bounds); - return new Rect2i(area.x, area.y - area.height - 2, area.width, area.height); - } - return new Rect2i(bounds.x, bounds.y, bounds.width, bounds.height); - } - } - } -} diff --git a/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREIForge.java b/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREIForge.java new file mode 100644 index 0000000..8bc9674 --- /dev/null +++ b/Forge/src/main/java/com/almostreliable/unified/compat/AlmostREIForge.java @@ -0,0 +1,8 @@ +package com.almostreliable.unified.compat; + +import me.shedaniel.rei.forge.REIPluginClient; + +@REIPluginClient +public class AlmostREIForge extends AlmostREI { + // dummy class to activate the plugin on Forge +}