From b0b91653f2cf19beb13018eb6a361ca0bdfe7db8 Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:42:13 +0800 Subject: [PATCH 1/4] RecipeMapGroup --- .../api/recipes/RecipeMapGroup.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java diff --git a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java new file mode 100644 index 000000000..18a340c2b --- /dev/null +++ b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java @@ -0,0 +1,51 @@ +package supersymmetry.api.recipes; + +import gregtech.api.recipes.Recipe; +import gregtech.api.recipes.RecipeBuilder; +import gregtech.api.recipes.RecipeMap; +import gregtech.api.recipes.builders.SimpleRecipeBuilder; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +public class RecipeMapGroup> extends RecipeMap { + + private final RecipeMap[] recipeMaps; + + public RecipeMapGroup(@NotNull String unlocalizedName, int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs, @NotNull R defaultRecipeBuilder, boolean isHidden, @NotNull RecipeMap[] recipeMaps) { + super(unlocalizedName, maxInputs, maxOutputs, maxFluidInputs, maxFluidOutputs, defaultRecipeBuilder, isHidden); + this.recipeMaps = recipeMaps; + } + + @Nonnull + public static RecipeMapGroup create(@NotNull String unlocalizedName, @NotNull RecipeMap[] recipeMaps) { + AtomicInteger maxInputs = new AtomicInteger(), maxOutputs = new AtomicInteger(), + maxFluidInputs = new AtomicInteger(), maxFluidOutputs = new AtomicInteger(); + Arrays.stream(recipeMaps).forEach(recipeMap -> { + maxInputs.set(Math.max(maxInputs.get(), recipeMap.getMaxInputs())); + maxOutputs.set(Math.max(maxOutputs.get(), recipeMap.getMaxOutputs())); + maxFluidInputs.set(Math.max(maxFluidInputs.get(), recipeMap.getMaxFluidInputs())); + maxFluidOutputs.set(Math.max(maxFluidOutputs.get(), recipeMap.getMaxFluidOutputs())); + }); + return new RecipeMapGroup<>(unlocalizedName, maxInputs.get(), maxOutputs.get(), maxFluidInputs.get(), maxFluidOutputs.get(), new SimpleRecipeBuilder(), true, recipeMaps); + } + + @Nullable + @Override + public Recipe findRecipe(long voltage, List inputs, List fluidInputs, boolean exactVoltage) { + AtomicReference recipe = new AtomicReference<>(); + Arrays.stream(recipeMaps) + .parallel() + .map(recipeMap -> recipeMap.findRecipe(voltage, inputs, fluidInputs, exactVoltage)) + .filter(java.util.Objects::nonNull) + .findFirst().ifPresent(recipe::set); + return recipe.get(); + } +} From 571b0f085e40d610588101ebaa10b6c6a4fcb754 Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:01:36 +0800 Subject: [PATCH 2/4] catalyst register --- .../api/recipes/RecipeMapGroup.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java index 18a340c2b..2ca199fee 100644 --- a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java +++ b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java @@ -4,6 +4,8 @@ import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.builders.SimpleRecipeBuilder; +import gregtech.api.recipes.category.GTRecipeCategory; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -11,7 +13,9 @@ import javax.annotation.Nonnull; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -48,4 +52,18 @@ public Recipe findRecipe(long voltage, List inputs, List .findFirst().ifPresent(recipe::set); return recipe.get(); } + + @Nonnull + @Override + public Map> getRecipesByCategory() { + Map> res = new Object2ObjectOpenHashMap<>(); + for (RecipeMap recipeMap : recipeMaps) { + recipeMap.getRecipesByCategory().forEach((category, recipes) -> { + List list = res.getOrDefault(category, new java.util.ArrayList<>()); + list.addAll(recipes); + res.put(category, list); + }); + } + return Collections.unmodifiableMap(res); + } } From 2e31b2d25a07070a6bccd58e3e4b3085f5adcd08 Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:05:55 +0800 Subject: [PATCH 3/4] this better ig --- .../api/recipes/RecipeMapGroup.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java index 2ca199fee..aae5ae1c3 100644 --- a/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java +++ b/src/main/java/supersymmetry/api/recipes/RecipeMapGroup.java @@ -16,29 +16,27 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; public class RecipeMapGroup> extends RecipeMap { - private final RecipeMap[] recipeMaps; + protected final RecipeMap[] recipeMaps; - public RecipeMapGroup(@NotNull String unlocalizedName, int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs, @NotNull R defaultRecipeBuilder, boolean isHidden, @NotNull RecipeMap[] recipeMaps) { + protected RecipeMapGroup(@NotNull String unlocalizedName, int maxInputs, int maxOutputs, int maxFluidInputs, int maxFluidOutputs, @NotNull R defaultRecipeBuilder, boolean isHidden, @NotNull RecipeMap[] recipeMaps) { super(unlocalizedName, maxInputs, maxOutputs, maxFluidInputs, maxFluidOutputs, defaultRecipeBuilder, isHidden); this.recipeMaps = recipeMaps; } @Nonnull - public static RecipeMapGroup create(@NotNull String unlocalizedName, @NotNull RecipeMap[] recipeMaps) { - AtomicInteger maxInputs = new AtomicInteger(), maxOutputs = new AtomicInteger(), - maxFluidInputs = new AtomicInteger(), maxFluidOutputs = new AtomicInteger(); - Arrays.stream(recipeMaps).forEach(recipeMap -> { - maxInputs.set(Math.max(maxInputs.get(), recipeMap.getMaxInputs())); - maxOutputs.set(Math.max(maxOutputs.get(), recipeMap.getMaxOutputs())); - maxFluidInputs.set(Math.max(maxFluidInputs.get(), recipeMap.getMaxFluidInputs())); - maxFluidOutputs.set(Math.max(maxFluidOutputs.get(), recipeMap.getMaxFluidOutputs())); - }); - return new RecipeMapGroup<>(unlocalizedName, maxInputs.get(), maxOutputs.get(), maxFluidInputs.get(), maxFluidOutputs.get(), new SimpleRecipeBuilder(), true, recipeMaps); + public static RecipeMapGroup create(@NotNull String unlocalizedName, @NotNull RecipeMap... recipeMaps) { + int maxInputs = 0, maxOutputs = 0, maxFluidInputs = 0, maxFluidOutputs = 0; + for (RecipeMap recipeMap : recipeMaps) { + maxInputs = Math.max(maxInputs, recipeMap.getMaxInputs()); + maxOutputs = Math.max(maxOutputs, recipeMap.getMaxOutputs()); + maxFluidInputs = Math.max(maxFluidInputs, recipeMap.getMaxFluidInputs()); + maxFluidOutputs = Math.max(maxFluidOutputs, recipeMap.getMaxFluidOutputs()); + } + return new RecipeMapGroup<>(unlocalizedName, maxInputs, maxOutputs, maxFluidInputs, maxFluidOutputs, new SimpleRecipeBuilder(), true, recipeMaps); } @Nullable @@ -58,11 +56,7 @@ public Recipe findRecipe(long voltage, List inputs, List public Map> getRecipesByCategory() { Map> res = new Object2ObjectOpenHashMap<>(); for (RecipeMap recipeMap : recipeMaps) { - recipeMap.getRecipesByCategory().forEach((category, recipes) -> { - List list = res.getOrDefault(category, new java.util.ArrayList<>()); - list.addAll(recipes); - res.put(category, list); - }); + res.putAll(recipeMap.getRecipesByCategory()); } return Collections.unmodifiableMap(res); } From 626f0e3acc07dbeccd9ae989c3f4b8009db6e7cc Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 29 Sep 2024 22:03:04 +0800 Subject: [PATCH 4/4] add crt to dependencies.gradle --- dependencies.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dependencies.gradle b/dependencies.gradle index 1ee8b360b..54bb666af 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -63,4 +63,6 @@ dependencies { compileOnly rfg.deobf("curse.maven:travelers-backpack-321117:3150850") compileOnly rfg.deobf("curse.maven:barrels-drums-storage-more-319404:2708193") + + api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700") }