-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38b2afd
commit 4e79c8e
Showing
11 changed files
with
359 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/groovy-tests/miscTests.groovy → src/main/groovy-tests/ncCoolerTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/nomiceu/nomilabs/groovy/SimpleIIngredient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.nomiceu.nomilabs.groovy; | ||
|
||
import net.minecraft.item.crafting.Ingredient; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.cleanroommc.groovyscript.api.IIngredient; | ||
|
||
/** | ||
* A template for a simple implementation of IIngredient, with stack size 1, no marks, and no copying. | ||
* <p> | ||
* Also sets `toMcIngredient` to return an ingredient of the matching stacks. | ||
*/ | ||
public abstract class SimpleIIngredient implements IIngredient { | ||
|
||
@Override | ||
public Ingredient toMcIngredient() { | ||
return Ingredient.fromStacks(getMatchingStacks()); | ||
} | ||
|
||
@Override | ||
public int getAmount() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public void setAmount(int amount) {} | ||
|
||
@Override | ||
public IIngredient exactCopy() { | ||
return this; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getMark() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setMark(String mark) {} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/StrictableItemRecipeWrappers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.nomiceu.nomilabs.groovy.mixinhelper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraftforge.common.crafting.IShapedRecipe; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.jei.ShapedRecipeWrapper; | ||
|
||
import mezz.jei.api.IJeiHelpers; | ||
import mezz.jei.api.ingredients.IIngredients; | ||
import mezz.jei.api.ingredients.VanillaTypes; | ||
import mezz.jei.api.recipe.IStackHelper; | ||
import mezz.jei.plugins.vanilla.crafting.ShapelessRecipeWrapper; | ||
import mezz.jei.recipes.BrokenCraftingRecipeException; | ||
import mezz.jei.util.ErrorUtil; | ||
|
||
/** | ||
* Recipe wrappers that can return the matching stacks exactly for JEI, | ||
* ignoring duplicates according to JEI and wildcard itemstacks. | ||
*/ | ||
public class StrictableItemRecipeWrappers { | ||
|
||
public static void getIngredientsImpl(@NotNull IIngredients ingredients, IRecipe recipe, IJeiHelpers jeiHelpers) { | ||
ItemStack recipeOutput = recipe.getRecipeOutput(); | ||
List<List<ItemStack>> inputLists; | ||
|
||
try { | ||
if (recipe instanceof StrictableRecipe strict && strict.labs$getIsStrict()) { | ||
inputLists = new ArrayList<>(); | ||
for (var input : recipe.getIngredients()) { | ||
inputLists.add(new ArrayList<>(Arrays.asList(input.getMatchingStacks()))); | ||
} | ||
} else { | ||
IStackHelper stackHelper = jeiHelpers.getStackHelper(); | ||
inputLists = stackHelper.expandRecipeItemStackInputs(recipe.getIngredients()); | ||
} | ||
ingredients.setInputLists(VanillaTypes.ITEM, inputLists); | ||
ingredients.setOutput(VanillaTypes.ITEM, recipeOutput); | ||
} catch (RuntimeException e) { | ||
String info = ErrorUtil.getInfoFromBrokenCraftingRecipe(recipe, recipe.getIngredients(), recipeOutput); | ||
throw new BrokenCraftingRecipeException(info, e); | ||
} | ||
} | ||
|
||
public static class Shapeless extends ShapelessRecipeWrapper<IRecipe> { | ||
|
||
protected final IJeiHelpers jeiHelpers; | ||
|
||
public Shapeless(IJeiHelpers jeiHelpers, IRecipe recipe) { | ||
super(jeiHelpers, recipe); | ||
this.jeiHelpers = jeiHelpers; | ||
} | ||
|
||
@Override | ||
public void getIngredients(@NotNull IIngredients ingredients) { | ||
StrictableItemRecipeWrappers.getIngredientsImpl(ingredients, recipe, jeiHelpers); | ||
} | ||
} | ||
|
||
public static class Shaped extends ShapedRecipeWrapper { | ||
|
||
protected final IJeiHelpers jeiHelpers; | ||
|
||
public Shaped(IJeiHelpers jeiHelpers, IShapedRecipe recipe) { | ||
super(jeiHelpers, recipe); | ||
this.jeiHelpers = jeiHelpers; | ||
} | ||
|
||
@Override | ||
public void getIngredients(@NotNull IIngredients ingredients) { | ||
StrictableItemRecipeWrappers.getIngredientsImpl(ingredients, recipe, jeiHelpers); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/nomiceu/nomilabs/groovy/mixinhelper/StrictableRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.nomiceu.nomilabs.groovy.mixinhelper; | ||
|
||
/** | ||
* A recipe that can return the matching stacks exactly for JEI, | ||
* ignoring duplicates according to JEI and wildcard itemstacks. | ||
*/ | ||
public interface StrictableRecipe { | ||
|
||
void labs$setStrict(); | ||
|
||
boolean labs$getIsStrict(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/CraftingRecipeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.nomiceu.nomilabs.mixin.groovyscript; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import com.cleanroommc.groovyscript.compat.vanilla.CraftingRecipe; | ||
import com.nomiceu.nomilabs.groovy.mixinhelper.StrictableRecipe; | ||
|
||
/** | ||
* Allows for recipes to be 'strict'. This means, in JEI, the list of 'matching stacks' will be displayed | ||
* exactly as set, instead of expanding wildcards and removing duplicates. | ||
*/ | ||
@Mixin(value = CraftingRecipe.class, remap = false) | ||
public class CraftingRecipeMixin implements StrictableRecipe { | ||
|
||
@Unique | ||
private boolean labs$isStrict = false; | ||
|
||
@Override | ||
@Unique | ||
public boolean labs$getIsStrict() { | ||
return labs$isStrict; | ||
} | ||
|
||
@Override | ||
@Unique | ||
public void labs$setStrict() { | ||
labs$isStrict = true; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/nomiceu/nomilabs/mixin/groovyscript/JEIPluginMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.nomiceu.nomilabs.mixin.groovyscript; | ||
|
||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraftforge.common.crafting.IShapedRecipe; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.jei.JeiPlugin; | ||
import com.cleanroommc.groovyscript.compat.mods.jei.ShapedRecipeWrapper; | ||
import com.nomiceu.nomilabs.groovy.mixinhelper.StrictableItemRecipeWrappers; | ||
|
||
import mezz.jei.api.IJeiHelpers; | ||
import mezz.jei.plugins.vanilla.crafting.ShapelessRecipeWrapper; | ||
|
||
/** | ||
* Registers recipes with the new 'strictable' wrappers. | ||
*/ | ||
@Mixin(value = JeiPlugin.class, remap = false) | ||
public class JEIPluginMixin { | ||
|
||
@Redirect(method = "lambda$register$0", | ||
at = @At(value = "NEW", | ||
target = "(Lmezz/jei/api/IJeiHelpers;Lnet/minecraftforge/common/crafting/IShapedRecipe;)Lcom/cleanroommc/groovyscript/compat/mods/jei/ShapedRecipeWrapper;")) | ||
private static ShapedRecipeWrapper returnNewHandlerShaped(IJeiHelpers jeiHelpers, IShapedRecipe recipe) { | ||
return new StrictableItemRecipeWrappers.Shaped(jeiHelpers, recipe); | ||
} | ||
|
||
@Redirect(method = "lambda$register$1", | ||
at = @At(value = "NEW", | ||
target = "(Lmezz/jei/api/IJeiHelpers;Lnet/minecraft/item/crafting/IRecipe;)Lmezz/jei/plugins/vanilla/crafting/ShapelessRecipeWrapper;")) | ||
private static ShapelessRecipeWrapper<?> returnNewHandlerShapeless(IJeiHelpers jeiHelpers, IRecipe recipe) { | ||
return new StrictableItemRecipeWrappers.Shapeless(jeiHelpers, recipe); | ||
} | ||
} |
Oops, something went wrong.