Skip to content

Commit ca2ba12

Browse files
authored
Add Almost Unified integration (#1128)
1 parent 959ccfb commit ca2ba12

File tree

8 files changed

+195
-13
lines changed

8 files changed

+195
-13
lines changed

build.gradle

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ repositories {
3838
includeGroup "curse.maven"
3939
}
4040
}
41-
// for AE2 and JEI
41+
// for AE2, JEI and Almost Unified
4242
maven {
4343
name "Modmaven"
4444
url "https://modmaven.dev"
4545
content {
4646
includeGroup "appeng"
4747
includeGroup "dev.technici4n"
4848
includeGroup "mezz.jei"
49+
includeGroup "com.almostreliable.mods"
4950
}
5051
}
5152
maven {
@@ -111,15 +112,6 @@ repositories {
111112
includeGroup "org.parchmentmc.data"
112113
}
113114
}
114-
// for AE2
115-
maven {
116-
name = "Modmaven"
117-
url = uri("https://modmaven.dev/")
118-
119-
content {
120-
includeGroup("appeng")
121-
}
122-
}
123115
// For the "No Indium?" mod
124116
maven {
125117
url = 'https://maven.cafeteria.dev/releases/'
@@ -274,6 +266,8 @@ dependencies {
274266

275267
compileOnly "dev.ftb.mods:ftb-quests-neoforge:${project.ftb_quests_version}"
276268
compileOnly "dev.ftb.mods:ftb-teams-neoforge:${project.ftb_teams_version}"
269+
270+
compileOnly "com.almostreliable.mods:almostunified-neoforge:${project.minecraft_version}-${project.au_version}:api"
277271
}
278272

279273
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ argonauts_minecraft_version=1.21
3737
argonauts_version=2.0.0-alpha.4
3838
athena_minecraft_version=1.21
3939
athena_version=4.0.0
40+
au_version=1.2.5
4041
emi_minecraft_version=1.21
4142
emi_version=1.1.10
4243
ftb_quests_version=2100.1.3
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.compat.almostunified;
25+
26+
import aztech.modern_industrialization.config.MIStartupConfig;
27+
import net.minecraft.world.item.Item;
28+
import net.minecraft.world.level.ItemLike;
29+
import net.neoforged.fml.ModList;
30+
import org.jetbrains.annotations.Nullable;
31+
32+
public interface AlmostUnifiedFacade {
33+
AlmostUnifiedFacade INSTANCE = getInstance();
34+
35+
private static AlmostUnifiedFacade getInstance() {
36+
if (ModList.get().isLoaded("almostunified") && MIStartupConfig.INSTANCE.almostUnifiedIntegration.getAsBoolean()) {
37+
try {
38+
return Class.forName("aztech.modern_industrialization.compat.almostunified.AlmostUnifiedFacadeImpl")
39+
.asSubclass(AlmostUnifiedFacade.class).getConstructor().newInstance();
40+
} catch (Throwable throwable) {
41+
throw new RuntimeException(throwable);
42+
}
43+
}
44+
45+
return item -> null;
46+
}
47+
48+
@Nullable
49+
Item getTargetItem(ItemLike item);
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.compat.almostunified;
25+
26+
import com.almostreliable.unified.api.AlmostUnified;
27+
import net.minecraft.world.item.Item;
28+
import net.minecraft.world.level.ItemLike;
29+
import org.jetbrains.annotations.Nullable;
30+
31+
public class AlmostUnifiedFacadeImpl implements AlmostUnifiedFacade {
32+
@Nullable
33+
@Override
34+
public Item getTargetItem(ItemLike item) {
35+
return AlmostUnified.INSTANCE.getVariantItemTarget(item);
36+
}
37+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.compat.almostunified;
25+
26+
import aztech.modern_industrialization.MI;
27+
import com.almostreliable.unified.api.plugin.AlmostUnifiedNeoPlugin;
28+
import com.almostreliable.unified.api.plugin.AlmostUnifiedPlugin;
29+
import com.almostreliable.unified.api.unification.recipe.RecipeUnifierRegistry;
30+
import net.minecraft.resources.ResourceLocation;
31+
32+
@AlmostUnifiedNeoPlugin
33+
public class MIAlmostUnifiedPlugin implements AlmostUnifiedPlugin {
34+
35+
@Override
36+
public ResourceLocation getPluginId() {
37+
return MI.id("almost_unified");
38+
}
39+
40+
@Override
41+
public void registerRecipeUnifiers(RecipeUnifierRegistry registry) {
42+
registry.registerForModId(MI.ID, new MIRecipeUnifier());
43+
}
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.compat.almostunified;
25+
26+
import com.almostreliable.unified.api.unification.bundled.GenericRecipeUnifier;
27+
import com.almostreliable.unified.api.unification.recipe.RecipeJson;
28+
import com.almostreliable.unified.api.unification.recipe.RecipeUnifier;
29+
import com.almostreliable.unified.api.unification.recipe.UnificationHelper;
30+
31+
public class MIRecipeUnifier implements RecipeUnifier {
32+
33+
private static final String ITEM_INPUTS = "item_inputs";
34+
private static final String ITEM_OUTPUTS = "item_outputs";
35+
36+
@Override
37+
public void unify(UnificationHelper helper, RecipeJson recipe) {
38+
GenericRecipeUnifier.INSTANCE.unify(helper, recipe);
39+
helper.unifyInputs(recipe, ITEM_INPUTS);
40+
helper.unifyOutputs(recipe, ITEM_OUTPUTS);
41+
}
42+
}

src/main/java/aztech/modern_industrialization/config/MIStartupConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public boolean loadAe2Compat() {
4444
public final ModConfigSpec.BooleanValue bidirectionalEnergyCompat;
4545
public final ModConfigSpec.BooleanValue ae2Integration;
4646
public final ModConfigSpec.BooleanValue ftbQuestsIntegration;
47+
public final ModConfigSpec.BooleanValue almostUnifiedIntegration;
4748

4849
public final ModConfigSpec.BooleanValue datagenOnStartup;
4950
public final ModConfigSpec.BooleanValue loadRuntimeGeneratedResources;
@@ -71,6 +72,11 @@ private MIStartupConfig(MIConfigBuilder builder) {
7172
"Enable the FTB Quests integration, if present.")
7273
.gameRestart()
7374
.define("ftbQuestsIntegration", true);
75+
this.almostUnifiedIntegration = builder.start("almostUnifiedIntegration",
76+
"Almost Unified integration",
77+
"Enable the Almost Unified integration, if present.")
78+
.gameRestart()
79+
.define("almostUnifiedIntegration", true);
7480
builder.popSection();
7581

7682
builder.pushSection("datagen", "Runtime Datagen");

src/main/java/aztech/modern_industrialization/machines/components/CrafterComponent.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import aztech.modern_industrialization.MI;
3030
import aztech.modern_industrialization.api.machine.component.CrafterAccess;
3131
import aztech.modern_industrialization.api.machine.component.InventoryAccess;
32+
import aztech.modern_industrialization.compat.almostunified.AlmostUnifiedFacade;
3233
import aztech.modern_industrialization.inventory.AbstractConfigurableStack;
3334
import aztech.modern_industrialization.inventory.ConfigurableFluidStack;
3435
import aztech.modern_industrialization.inventory.ConfigurableItemStack;
@@ -662,9 +663,16 @@ public void lockRecipe(ResourceLocation recipeId, net.minecraft.world.entity.pla
662663
break;
663664
}
664665
}
666+
List<Item> inputItems = input.getInputItems();
667+
if (targetItem == null) {
668+
// Find the preferred item with Almost Unified if possible
669+
if (!inputItems.isEmpty()) {
670+
targetItem = AlmostUnifiedFacade.INSTANCE.getTargetItem(inputItems.getFirst());
671+
}
672+
}
665673
if (targetItem == null) {
666674
// Find the first match that is an item from MI (useful for ingots for example)
667-
for (Item item : input.getInputItems()) {
675+
for (Item item : inputItems) {
668676
ResourceLocation id = BuiltInRegistries.ITEM.getKey(item);
669677
if (id.getNamespace().equals(MI.ID)) {
670678
targetItem = item;
@@ -674,8 +682,8 @@ public void lockRecipe(ResourceLocation recipeId, net.minecraft.world.entity.pla
674682
}
675683
if (targetItem == null) {
676684
// If there is only one value in the tag, pick that one
677-
if (input.getInputItems().size() == 1) {
678-
targetItem = input.getInputItems().get(0);
685+
if (inputItems.size() == 1) {
686+
targetItem = inputItems.get(0);
679687
}
680688
}
681689

0 commit comments

Comments
 (0)