Compare commits

...

3 commits

Author SHA1 Message Date
rlnt
31d9963910
bump version
Some checks failed
Build / redirect (push) Has been cancelled
2024-09-20 11:40:20 +02:00
rlnt
702d1f0829
fix crash with JEI
fixes #93
2024-09-20 11:40:07 +02:00
rlnt
e0649dedd7
remove readme 2024-09-20 10:53:41 +02:00
11 changed files with 76 additions and 232 deletions

View file

@ -5,6 +5,15 @@ 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].
## [0.8.2] - 2024-09-20
### Fixed
- fixed crash with JEI ([#93])
- requires at least JEI version 11.8.0
<!-- Links -->
[#93]: https://github.com/AlmostReliable/almostunified/issues/93
## [0.8.1] - 2024-03-02
### Fixed
@ -444,6 +453,7 @@ Initial 1.19 release!
[semantic versioning]: https://semver.org/spec/v2.0.0.html
<!-- Versions -->
[0.8.2]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.19.2-0.8.1
[0.8.1]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.19.2-0.8.1
[0.8.0]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.19.2-0.8.0-beta
[0.7.2]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.19.2-0.7.2-beta

View file

@ -34,7 +34,6 @@ dependencies {
// compile time mods
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("dev.emi:emi-xplat-intermediary:$emiVersion+$minecraftVersion:api") // required for emi plugin

View file

@ -5,17 +5,22 @@ import com.almostreliable.unified.AlmostUnifiedFallbackRuntime;
import com.almostreliable.unified.api.ModConstants;
import com.almostreliable.unified.config.UnifyConfig;
import com.almostreliable.unified.recipe.CRTLookup;
import com.almostreliable.unified.recipe.ClientRecipeTracker;
import com.almostreliable.unified.utils.Utils;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
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.extensions.IRecipeCategoryDecorator;
import mezz.jei.api.registration.IAdvancedRegistration;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
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) {
var recipeId = recipeCategory.getRegistryName(recipe);
if (recipeId == null) return;
@Override
public void registerAdvanced(IAdvancedRegistration registration) {
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);
if (link == null) return;
private static final int RECIPE_BORDER_PADDING = 4;
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));
@Override
public void draw(T recipe, IRecipeCategory<T> recipeCategory, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) {
var recipeLink = resolveLink(recipeCategory, recipe);
if (recipeLink == null) return;
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);
}
}
}

View file

@ -5,6 +5,7 @@ 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;
@ -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) {
poseStack.pushPose();
poseStack.translate(area.getX(), area.getY(), 0);

View file

@ -90,17 +90,25 @@ public class DuplicationConfig extends Config {
JsonCompare.CompareSettings defaultRules = safeGet(() -> createCompareSet(json.getAsJsonObject(
DEFAULT_DUPLICATE_RULES)),
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)
.entrySet()
.stream()
.collect(Collectors.toMap(entry -> new ResourceLocation(entry.getKey()),
entry -> createCompareSet(entry.getValue().getAsJsonObject()),
(a, b) -> b,
LinkedHashMap::new)), Defaults.getDefaultDuplicateOverrides(platform));
boolean strictMode = safeGet(() -> json.get(STRICT_MODE).getAsBoolean(), false);
return new DuplicationConfig(defaultRules, overrideRules, ignoreRecipeTypes, ignoreRecipes, strictMode);
LinkedHashMap::new));
}
private JsonCompare.CompareSettings createCompareSet(JsonObject rules) {

View file

@ -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) {}
}

View file

@ -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);
}
}

View file

@ -1,6 +0,0 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.almostreliable.unified.mixin.compat;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -3,7 +3,6 @@
"minVersion": "0.8.5",
"package": "com.almostreliable.unified.mixin",
"compatibilityLevel": "JAVA_17",
"plugin": "com.almostreliable.unified.mixin.AlmostMixinPlugin",
"mixins": [
"runtime.RecipeManagerMixin",
"runtime.TagLoaderMixin",
@ -11,7 +10,6 @@
"unifier.TieredItemMixin"
],
"client": [
"compat.JeiRecipeLayoutMixin",
"runtime.ClientPacketListenerMixin"
],
"injectors": {

120
README.md
View file

@ -1,120 +0,0 @@
<h1 align="center">
<a href="https://github.com/AlmostReliable/almostunified"><img src=https://i.imgur.com/3b7Gjkn.png" alt="Preview" width=200></a>
<p>Almost Unified</p>
</h1>
<div align="center">
A [Minecraft] mod to unify resources.
[![Workflow Status][workflow_status_badge]][workflow_status_link]
[![License][license_badge]][license]
[![Version][version_badge]][version_link]
[![Total Downloads CF][total_downloads_cf_badge]][curseforge]
[![Total Downloads MR][total_downloads_mr_badge]][modrinth]
[![Discord][discord_badge]][discord]
[![Wiki][wiki_badge]][wiki]
</div>
## **📖 Information**
For an in-depth explanation of the mod, its functionality, config descriptions, FAQs and more, check out the [wiki].
## **🔧 Manual Installation**
1. Download the latest **mod jar** from the [releases], from [CurseForge] or [Modrinth].
2. Install Minecraft [Forge] or [Fabric].
3. Drop the **jar file** into your mods folder.
## **🔗 Depending on the Mod**
### Maven
Every release of this project is built on and published to the [BlameJared] maven.
```groovy
repositories {
maven {
url = 'https://maven.blamejared.com'
name = 'BlameJared Maven'
}
}
```
### Common [![Maven][maven_common_badge]][maven_common_link]
```groovy
dependencies {
modApi("com.almostreliable.mods:almostunified-common:<version>")
}
```
### Fabric [![Maven][maven_fabric_badge]][maven_fabric_link]
```groovy
dependencies {
modApi("com.almostreliable.mods:almostunified-fabric:<version>")
}
```
### Forge [![Maven][maven_forge_badge]][maven_forge_link]
```groovy
dependencies {
modApi(fg.deobf("com.almostreliable.mods:almostunified-forge:<version>"))
}
```
### Examples
For code examples on how to use the API, check out the [wiki][api-wiki].
## **🖥️ Dev Environment Setup**
1. Clone the repository
2. Import into IntelliJ (VSCode and Eclipse are not tested)
3. Run
- `gradle -> common -> Tasks -> fabric -> genSources`
- `gradle -> fabric -> Tasks -> fabric -> genSources`
- `gradle -> forge -> Tasks -> loom -> genSources`
- `gradle -> Tasks -> buildconfig -> generateBuildConfig`
4. Restart the IDE
The `common` module uses [fabric-loom]. This allows to use [ParchmentMC][parchment].<br>
Do not use Fabric related features inside the `common` module!
## **💚 Credits**
The logo was made by [mo_shark].
## **🎓 License**
This project is licensed under the [GNU Lesser General Public License v3.0][license].
<!-- Badges -->
[workflow_status_badge]: https://img.shields.io/github/actions/workflow/status/AlmostReliable/almostunified/build.yml?branch=1.19.2&style=for-the-badge
[workflow_status_link]: https://github.com/AlmostReliable/almostunified/actions
[license_badge]: https://img.shields.io/github/license/AlmostReliable/almostunified?style=for-the-badge
[version_badge]: https://img.shields.io/badge/dynamic/json?color=0078FF&label=release&style=for-the-badge&query=name&url=https://api.razonyang.com/v1/github/tag/AlmostReliable/almostunified%3Fprefix=v1.19.2-
[version_link]: https://github.com/AlmostReliable/almostunified/releases/latest
[total_downloads_cf_badge]: https://img.shields.io/badge/dynamic/json?color=e04e14&label=CurseForge&style=for-the-badge&query=downloads.total&url=https%3A%2F%2Fapi.cfwidget.com%2F633823&logo=curseforge
[total_downloads_mr_badge]: https://img.shields.io/modrinth/dt/sdaSaQEz?color=5da545&label=Modrinth&style=for-the-badge&logo=modrinth
[discord_badge]: https://img.shields.io/discord/917251858974789693?color=5865f2&label=Discord&logo=discord&style=for-the-badge
[wiki_badge]: https://img.shields.io/badge/Read%20the-Wiki-ba00ff?style=for-the-badge
[maven_common_badge]: https://img.shields.io/maven-metadata/v?color=C71A36&label=Latest%20version&logo=Latest%20version&metadataUrl=https%3A%2F%2Fmaven.blamejared.com%2Fcom%2Falmostreliable%2Fmods%2Falmostunified-common%2Fmaven-metadata.xml&style=flat-square
[maven_common_link]: https://maven.blamejared.com/com/almostreliable/mods/almostunified-common/
[maven_fabric_badge]: https://img.shields.io/maven-metadata/v?color=C71A36&label=Latest%20version&logo=Latest%20version&metadataUrl=https%3A%2F%2Fmaven.blamejared.com%2Fcom%2Falmostreliable%2Fmods%2Falmostunified-fabric%2Fmaven-metadata.xml&style=flat-square
[maven_fabric_link]: https://maven.blamejared.com/com/almostreliable/mods/almostunified-fabric/
[maven_forge_badge]: https://img.shields.io/maven-metadata/v?color=C71A36&label=Latest%20version&logo=Latest%20version&metadataUrl=https%3A%2F%2Fmaven.blamejared.com%2Fcom%2Falmostreliable%2Fmods%2Falmostunified-forge%2Fmaven-metadata.xml&style=flat-square
[maven_forge_link]: https://maven.blamejared.com/com/almostreliable/mods/almostunified-forge/
<!-- Links -->
[minecraft]: https://www.minecraft.net/
[discord]: https://discord.com/invite/ThFnwZCyYY
[wiki]: https://github.com/AlmostReliable/almostunified/wiki
[curseforge]: https://www.curseforge.com/minecraft/mc-mods/almost-unified
[modrinth]: https://modrinth.com/mod/almost-unified
[releases]: https://github.com/AlmostReliable/almostunified/releases
[forge]: http://files.minecraftforge.net/
[fabric]: https://fabricmc.net/
[blamejared]: https://maven.blamejared.com
[api-wiki]: https://github.com/AlmostReliable/almostunified/wiki/API
[fabric-loom]: https://github.com/FabricMC/fabric-loom
[parchment]: https://parchmentmc.org/
[multiLoader template]: https://github.com/jaredlll08/MultiLoader-Template
[jared]: https://github.com/jaredlll08
[mo_shark]: https://www.curseforge.com/members/mo_shark
[license]: LICENSE

View file

@ -8,7 +8,7 @@ enableAccessWidener = false
minecraftVersion = 1.19.2
# Mod
modVersion = 0.8.1
modVersion = 0.8.2
modPackage = com.almostreliable.unified
modId = almostunified
modName = AlmostUnified
@ -21,7 +21,7 @@ junitVersion = 5.9.0
parchmentVersion = 2022.11.27
# Mod Dependencies
jeiVersion = 11.6.0.1012
jeiVersion = 11.8.0.1030
reiVersion = 9.1.580
emiVersion = 1.1.2