Skip to content

Commit

Permalink
Migrate to new RecipeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune committed Dec 1, 2023
1 parent 02a935c commit a45590d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 69 deletions.
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
.settings
/.idea/
/.vscode/
/run/
/build/
/eclipse/
Expand All @@ -25,7 +26,13 @@ whitelist.json
*.iml
*.ipr
*.iws
src/main/resources/mixins.*.json
src/main/resources/mixins.*([!.]).json
*.bat
.vscode
*.bak
*.DS_Store
!gradlew.bat
.factorypath
addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
layout.json
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1695474595
//version: 1700844281
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -302,7 +302,7 @@ if (apiPackage) {
}

if (accessTransformersFile) {
for (atFile in accessTransformersFile.split(",")) {
for (atFile in accessTransformersFile.split(" ")) {
String targetFile = "src/main/resources/META-INF/" + atFile.trim()
if (!getFile(targetFile).exists()) {
throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile)
Expand Down Expand Up @@ -646,7 +646,7 @@ repositories {

def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.7.1"
def mixinProviderVersion = "0.1.13"
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
ext.mixinProviderSpec = mixinProviderSpec
Expand Down Expand Up @@ -793,12 +793,12 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies"
}

dependencies {
def lwjgl3ifyVersion = '1.5.0'
def lwjgl3ifyVersion = '1.5.1'
if (modId != 'lwjgl3ify') {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.5')
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.17')
}

java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false}
Expand Down Expand Up @@ -1187,9 +1187,8 @@ publishing {
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
}
}

repositories {
if (usesMavenPublishing.toBoolean()) {
if (usesMavenPublishing.toBoolean() && System.getenv("MAVEN_USER") != null) {
maven {
url = mavenPublishUrl
allowInsecureProtocol = mavenPublishUrl.startsWith("http://") // Mostly for the GTNH maven
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* For more details, see https://docs.gradle.org/7.6/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.23:dev")
api("com.github.GTNewHorizons:GTplusplus:1.10.10:dev")
api("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.92-pre:dev")
api("com.github.GTNewHorizons:GTplusplus:1.10.35-pre:dev")
api("com.github.GTNewHorizons:CraftTweaker:3.2.13:dev")
}
11 changes: 6 additions & 5 deletions src/main/java/gttweaker/mods/gregtech/GTRecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import java.util.HashMap;

import gregtech.api.util.GT_Recipe;
import gregtech.api.recipe.RecipeMap;

public class GTRecipeMap {

public static HashMap<String, GT_Recipe.GT_Recipe_Map> recipeMaps = new HashMap<>();
public static HashMap<String, RecipeMap<?>> recipeMaps = new HashMap<>();

public static GT_Recipe.GT_Recipe_Map getRecipeMap(String map) {
public static RecipeMap<?> getRecipeMap(String map) {
if (!recipeMaps.containsKey(map)) {
recipeMaps.put(
map,
GT_Recipe.GT_Recipe_Map.sMappings.stream()
.filter(m -> m.mUnlocalizedName.equals(map))
RecipeMap.ALL_RECIPE_MAPS.values()
.stream()
.filter(m -> m.unlocalizedName.equals(map))
.findAny()
.orElse(null));
}
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/gttweaker/mods/gregtech/RA2Builder.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package gttweaker.mods.gregtech;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import gregtech.api.enums.GT_Values;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_RecipeBuilder;
import gttweaker.GTTweaker;
Expand Down Expand Up @@ -141,7 +140,7 @@ public void addTo(String recipeMap) {
MineTweakerAPI.logError("Could not build recipe!");
return;
}
GT_Recipe.GT_Recipe_Map map = GTRecipeMap.getRecipeMap(recipeMap);
RecipeMap<?> map = GTRecipeMap.getRecipeMap(recipeMap);
if (map == null) {
MineTweakerAPI.logError("Could not find recipe map named \"" + recipeMap + "\"");
return;
Expand All @@ -153,9 +152,9 @@ public void addTo(String recipeMap) {
public static class RecipeAddAction implements IUndoableAction {

GT_Recipe recipe;
GT_Recipe.GT_Recipe_Map map;
RecipeMap<?> map;

public RecipeAddAction(GT_Recipe recipe, GT_Recipe.GT_Recipe_Map map) {
public RecipeAddAction(GT_Recipe recipe, RecipeMap<?> map) {
this.recipe = recipe;
this.map = map;
}
Expand All @@ -172,27 +171,8 @@ public boolean canUndo() {

@Override
public void undo() {
map.mRecipeList.remove(recipe);
map.mRecipeItemMap.entrySet()
.stream()
.filter(
e -> e.getValue()
.removeIf(r -> r == recipe)
&& e.getValue()
.isEmpty())
.map(Map.Entry::getKey)
.collect(Collectors.toSet())
.forEach(k -> map.mRecipeItemMap.remove(k));
map.mRecipeFluidMap.entrySet()
.stream()
.filter(
e -> e.getValue()
.removeIf(r -> r == recipe)
&& e.getValue()
.isEmpty())
.map(Map.Entry::getKey)
.collect(Collectors.toSet())
.forEach(k -> map.mRecipeFluidMap.remove(k));
map.getBackend()
.removeRecipe(recipe);
}

@Override
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/gttweaker/mods/gregtech/RecipeRemover.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package gttweaker.mods.gregtech;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import gregtech.api.recipe.RecipeMap;
import gregtech.api.util.GT_Recipe;
import gttweaker.GTTweaker;
import minetweaker.IUndoableAction;
Expand All @@ -24,7 +23,7 @@ public class RecipeRemover {

@ZenMethod
public static void remove(String map, IIngredient[] inputs, IIngredient[] fluidInputs) {
GT_Recipe.GT_Recipe_Map recipeMap = GTRecipeMap.getRecipeMap(map);
RecipeMap<?> recipeMap = GTRecipeMap.getRecipeMap(map);
if (recipeMap == null) {
MineTweakerAPI.logError("Could not find recipe map named \"" + map + "\"");
return;
Expand Down Expand Up @@ -52,36 +51,17 @@ public static void remove(String map, IIngredient[] inputs, IIngredient[] fluidI
public static class RecipeRemoveAction implements IUndoableAction {

GT_Recipe recipe;
GT_Recipe.GT_Recipe_Map map;
RecipeMap<?> map;

public RecipeRemoveAction(GT_Recipe recipe, GT_Recipe.GT_Recipe_Map map) {
public RecipeRemoveAction(GT_Recipe recipe, RecipeMap<?> map) {
this.recipe = recipe;
this.map = map;
}

@Override
public void apply() {
map.mRecipeList.remove(recipe);
map.mRecipeItemMap.entrySet()
.stream()
.filter(
e -> e.getValue()
.removeIf(r -> r == recipe)
&& e.getValue()
.size() == 0)
.map(Map.Entry::getKey)
.collect(Collectors.toSet())
.forEach(k -> map.mRecipeItemMap.remove(k));
map.mRecipeFluidMap.entrySet()
.stream()
.filter(
e -> e.getValue()
.removeIf(r -> r == recipe)
&& e.getValue()
.size() == 0)
.map(Map.Entry::getKey)
.collect(Collectors.toSet())
.forEach(k -> map.mRecipeFluidMap.remove(k));
map.getBackend()
.removeRecipe(recipe);
}

@Override
Expand Down

0 comments on commit a45590d

Please sign in to comment.