Skip to content

Commit

Permalink
Add Slightly More Flexibility With Recycling Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 25, 2024
1 parent daa9740 commit e0abd1a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ replaceRecipeInput("electric_motor_hv", [
[metaitem('plateWroughtIron'), metaitem('plateWroughtIron'), metaitem('plateWroughtIron')],
[metaitem('plateWroughtIron'), ore('toolWrench'), metaitem('plateWroughtIron')],
[metaitem('plateWroughtIron'), metaitem('plateWroughtIron'), metaitem('plateWroughtIron')]
])
])

// Add a recipe with recycling, with a defined name
createRecipe("uhv_batbuf_4x", metaitem('battery_buffer.uhv.4'), [
[null, null, null],
[null, metaitem('battery_buffer.uv.4'), null],
[null, null, null]])

// Add a recipe with recycling, without a defined name
createRecipe(metaitem('battery_buffer.uhv.8'), [
[null, null, null],
[null, metaitem('battery_buffer.uv.8'), null],
[null, null, null]])

// Add / Change recycling to a stack
changeStackRecycling(metaitem('battery_buffer.uhv.16'), [metaitem('battery_buffer.uv.16'), metaitem('charger.uv')])
6 changes: 6 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public static void replaceRecipeInput(String name, List<List<IIngredient>> input
else
replaceRecipeInput(GTUtility.gregtechId(name), inputs);
}
public static void createRecipe(String name, ItemStack output, List<List<IIngredient>> inputs) {
ReplaceRecipe.createRecipe(name, output, inputs);
}
public static void createRecipe(ItemStack output, List<List<IIngredient>> inputs) {
ReplaceRecipe.createRecipe(output, inputs);
}
public static void changeStackRecycling(ItemStack output, List<IIngredient> ingredients) {
ReplaceRecipe.changeStackRecycling(output, ingredients);
}
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/com/nomiceu/nomilabs/groovy/ReplaceRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraftforge.common.crafting.IShapedRecipe;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -53,7 +54,7 @@ private static void removeRecipesInCategory(RecipeMap<?> recipeMap, GTRecipeCate
public static void replaceRecipeShaped(ResourceLocation name, ItemStack output, List<List<IIngredient>> inputs) {
validate(name, output, true);
crafting.remove(name);
crafting.addShaped(LabsNames.makeLabsName(name.getPath()), output, inputs);
crafting.addShaped(LabsNames.makeGroovyName(name.getPath()), output, inputs);
registerRecycling(output, inputs);
}

Expand All @@ -63,7 +64,7 @@ public static void replaceRecipeOutput(ResourceLocation name, ItemStack newOutpu
var newCount = newOutput.getCount();

crafting.remove(name);
ReloadableRegistryManager.addRegistryEntry(ForgeRegistries.RECIPES, LabsNames.makeLabsName(name.getPath()), new PartialRecipe(originalRecipe, newOutput.copy()));
ReloadableRegistryManager.addRegistryEntry(ForgeRegistries.RECIPES, LabsNames.makeGroovyName(name.getPath()), new PartialRecipe(originalRecipe, newOutput.copy()));

ImmutableList<MaterialStack> originalMaterials = Objects.requireNonNull(OreDictUnifier.getMaterialInfo(newOutput)).getMaterials();
List<MaterialStack> newMaterials = new ArrayList<>();
Expand All @@ -78,10 +79,21 @@ public static void replaceRecipeInput(ResourceLocation name, List<List<IIngredie
IRecipe originalRecipe = validate(name, ItemStack.EMPTY, false);
var originalOutput = originalRecipe.getRecipeOutput();
crafting.remove(name);
crafting.addShaped(LabsNames.makeLabsName(name.getPath()), originalOutput, newInputs);
crafting.addShaped(LabsNames.makeGroovyName(name.getPath()), originalOutput, newInputs);
registerRecycling(originalOutput, newInputs);
}

public static void createRecipe(String name, ItemStack output, List<List<IIngredient>> input) {
crafting.addShaped(LabsNames.makeGroovyName(name), output, input);
registerRecycling(output, input);
}

public static void createRecipe(ItemStack output, List<List<IIngredient>> input) {
crafting.addShaped(output, input);
registerRecycling(output, input);
}


public static void changeStackRecycling(ItemStack output, List<IIngredient> ingredients) {
registerRecycling(output, Collections.singletonList(ingredients));
}
Expand Down Expand Up @@ -111,7 +123,9 @@ private static void registerRecycling(ItemStack output, List<List<IIngredient>>
List<GTRecipeInput> gtInputs = new ArrayList<>();
for (var inputList : inputs) {
for (var input : inputList) {
gtInputs.add(ofGroovyIngredient(input));
var gtInput = ofGroovyIngredient(input);
if (gtInput != null)
gtInputs.add(gtInput);
}
}
LabsVirtualizedRegistries.REPLACE_RECIPE_MANAGER.registerOre(output, RecyclingHandler.getRecyclingIngredients(gtInputs, output.getCount()));
Expand All @@ -130,13 +144,14 @@ private static ItemStack checkAndGetOutput(ItemStack output, boolean validateOut
}

@SuppressWarnings("ConstantValue")
@Nullable
private static GTRecipeInput ofGroovyIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient oreDictIngredient) {
return new GTRecipeOreInput(oreDictIngredient.getOreDict(), ingredient.getAmount());
}
if ((Object) ingredient instanceof ItemStack stack) {
return new GTRecipeItemInput(stack);
}
throw new IllegalArgumentException("Could not add groovy ingredient " + ingredient + " to recipe!");
return null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/util/LabsNames.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.nomiceu.nomilabs.util;

import com.cleanroommc.groovyscript.helper.GroovyHelper;
import com.nomiceu.nomilabs.LabsValues;
import net.minecraft.util.ResourceLocation;

public class LabsNames {
public static ResourceLocation makeLabsName(String name) {
return new ResourceLocation(LabsValues.LABS_MODID, name);
}

public static ResourceLocation makeGroovyName(String name) {
return new ResourceLocation(GroovyHelper.getPackId(), name);
}
}

0 comments on commit e0abd1a

Please sign in to comment.