Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/api/IIngredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public interface IIngredient extends IResourceStack, Predicate<ItemStack> {

ItemStack[] getMatchingStacks();

default boolean isEmpty() {
return getAmount() <= 0 || getMatchingStacks().length == 0;
}

default ItemStack applyTransform(ItemStack matchedInput) {
return ForgeHooks.getContainerItem(matchedInput);
}
Expand Down Expand Up @@ -56,6 +60,11 @@ public int getAmount() {
public void setAmount(int amount) {
}

@Override
public boolean isEmpty() {
return true;
}

@Override
public IIngredient exactCopy() {
return this;
Expand Down Expand Up @@ -102,6 +111,11 @@ public ItemStack[] getMatchingStacks() {
return new ItemStack[0];
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public int getAmount() {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IBlockState parse(String mainArg, Object[] args) {
return blockState;
}
}
String[] stringArgs = (String[]) Arrays.copyOfRange(args, 1, args.length);
String[] stringArgs = Arrays.stream(args).map(Object::toString).toArray(String[]::new);
return parseBlockStates(blockState, Iterators.forArray(stringArgs));
}
return blockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean removeByOutput(FluidStack output) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement High Oven override")
.add("could not find override with output %s", output)
.add("could not find override with output {}", output)
.error()
.post();
return false;
Expand All @@ -85,7 +85,7 @@ public boolean removeByInput(IIngredient input) {

list.clear();
GroovyLog.msg("Error removing Tinkers Complement High Oven override")
.add("could not find override with input %s", input)
.add("could not find override with input {}", input)
.error()
.post();
return false;
Expand All @@ -102,7 +102,7 @@ public boolean removeByInputAndOutput(IIngredient input, FluidStack output) {

list.clear();
GroovyLog.msg("Error removing Tinkers Complement High Oven override")
.add("could not find override with input %s and output %s", input, output)
.add("could not find override with input {} and output {]", input, output)
.error()
.post();
return false;
Expand Down Expand Up @@ -150,7 +150,7 @@ public boolean removeByOutput(FluidStack output) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement High Oven Mixing recipe")
.add("could not find recipe with output %s", output)
.add("could not find recipe with output {}", output)
.error()
.post();
return false;
Expand All @@ -165,7 +165,7 @@ public boolean removeByInput(FluidStack input) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement High Oven Mixing recipe")
.add("could not find recipe with input %s", input)
.add("could not find recipe with input {}", input)
.error()
.post();
return false;
Expand All @@ -180,7 +180,7 @@ public boolean removeByInputAndOutput(FluidStack input, FluidStack output) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement High Oven Mixing recipe")
.add("could not find recipe with input %s and output %s", input, output)
.add("could not find recipe with input {} and output {}", input, output)
.error()
.post();
return false;
Expand All @@ -201,7 +201,7 @@ public boolean removeByAdditives(Map<MixAdditive, IIngredient> additives) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement High Oven Mixing recipe")
.add("could not find override with additives %s", additives.values())
.add("could not find override with additives {}", additives.values())
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean removeFromBlacklist(ItemStack item) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement Melter blacklist")
.add("could not find a blacklist for item %s", item)
.add("could not find a blacklist for item {}", item)
.error()
.post();
return false;
Expand All @@ -130,7 +130,7 @@ public boolean removeByInput(IIngredient input) {

list.clear();
GroovyLog.msg("Error removing Tinkers Complement Melter override")
.add("could not find a override for input %s", input)
.add("could not find a override for input {}", input)
.error()
.post();
return false;
Expand All @@ -144,7 +144,7 @@ public boolean removeByOutput(FluidStack stack) {
})) return true;

GroovyLog.msg("Error removing Tinkers Complement Melter override")
.add("could not find a override for output %s", stack)
.add("could not find a override for output {}", stack)
.error()
.post();
return false;
Expand All @@ -161,7 +161,7 @@ public boolean removeByInputAndOutput(IIngredient input, FluidStack output) {

list.clear();
GroovyLog.msg("Error removing Tinkers Complement Melter override")
.add("could not find a override for input %s and output %s", input, output)
.add("could not find a override for input {} and output {}", input, output)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean removeByOutput(FluidStack output) {
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Alloying recipe")
.add("could not find recipe with output %s", output)
.add("could not find recipe with output {}", output)
.error()
.post();
return false;
Expand All @@ -66,7 +66,7 @@ public boolean removeByInputs(FluidStack... inputs) {
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Alloying recipe")
.add("could not find recipe with inputs %s", Arrays.asList(inputs))
.add("could not find recipe with inputs {}", Arrays.asList(inputs))
.error()
.post();
return false;
Expand All @@ -80,7 +80,7 @@ public boolean removeByInputsAndOutput(FluidStack output, FluidStack... inputs)
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Alloying recipe")
.add("could not find recipe with inputs %s and output %s", Arrays.asList(inputs), output)
.add("could not find recipe with inputs %s and output {}", Arrays.asList(inputs), output)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ public boolean remove(ICastingRecipe recipe) {

public boolean removeByOutput(ItemStack output){
if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> {
boolean found = recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER).isItemEqual(output);
boolean found = ItemStack.areItemStacksEqual(recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER), output);
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe")
.add("could not find recipe with output %s", output)
.add("could not find recipe with output {}", output)
.error()
.post();
return false;
Expand All @@ -191,21 +191,22 @@ public boolean removeByInput(FluidStack input) {
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe")
.add("could not find recipe with input %s", input)
.add("could not find recipe with input {}", input)
.error()
.post();
return false;
}

public boolean removeByCast(IIngredient cast) {
ItemStack castStack = cast.getMatchingStacks()[0];
if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> {
boolean found = recipe.matches(cast.getMatchingStacks()[0], recipe.getFluid(cast.getMatchingStacks()[0], FluidRegistry.WATER).getFluid());
boolean found = recipe.matches(castStack, recipe.getFluid(castStack, FluidRegistry.WATER).getFluid());
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe")
.add("could not find recipe with cast %s", cast)
.add("could not find recipe with cast {}", cast)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import org.jetbrains.annotations.Nullable;
import slimeknights.tconstruct.library.DryingRecipe;

Expand Down Expand Up @@ -45,42 +46,44 @@ public boolean remove(DryingRecipe recipe) {
}

public boolean removeByInput(IIngredient input) {
NonNullList<ItemStack> matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks());
if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> {
boolean found = input.test(recipe.input.getInputs().get(0));
boolean found = recipe.input.matches(matching).isPresent();
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Drying recipe")
.add("could not find recipe with input %s", input)
.add("could not find recipe with input {}", input)
.error()
.post();
return false;
}

public boolean removeByOutput(ItemStack output) {
if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> {
boolean found = recipe.output.isItemEqual(output);
boolean found = ItemStack.areItemStacksEqual(recipe.output, output);
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Drying recipe")
.add("could not find recipe with output %s", output)
.add("could not find recipe with output {}", output)
.error()
.post();
return false;
}

public boolean removeByInputAndOutput(IIngredient input, ItemStack output) {
NonNullList<ItemStack> matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks());
if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> {
boolean found = input.test(recipe.input.getInputs().get(0)) && recipe.output.isItemEqual(output);
boolean found = recipe.input.matches(matching).isPresent() && ItemStack.areItemStacksEqual(recipe.output, output);
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Drying recipe")
.add("could not find recipe with input %s and output %s", input, output)
.add("could not find recipe with input {} and output {}", input, output)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cleanroommc.groovyscript.compat.mods.tinkersconstruct;

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
Expand All @@ -11,6 +12,8 @@
import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.entity.EntityList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.registry.EntityEntry;
Expand Down Expand Up @@ -56,14 +59,15 @@ public boolean remove(MeltingRecipe recipe) {
}

public boolean removeByInput(IIngredient input) {
NonNullList<ItemStack> matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks());
if (TinkerRegistryAccessor.getMeltingRegistry().removeIf(recipe -> {
boolean found = input.test(recipe.input.getInputs().get(0));
boolean found = recipe.input.matches(matching).isPresent();
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Melting recipe")
.add("could not find recipe with input %s", input)
.add("could not find recipe with input {}", input)
.error()
.post();
return false;
Expand All @@ -77,21 +81,22 @@ public boolean removeByOutput(FluidStack output) {
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Melting recipe")
.add("could not find recipe with output %s", output)
.add("could not find recipe with output {}", output)
.error()
.post();
return false;
}

public boolean removeByInputAndOutput(IIngredient input, FluidStack output) {
NonNullList<ItemStack> matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks());
if (TinkerRegistryAccessor.getMeltingRegistry().removeIf(recipe -> {
boolean found = input.test(recipe.input.getInputs().get(0)) && recipe.getResult().isFluidEqual(output);
boolean found = recipe.input.matches(matching).isPresent() && recipe.getResult().isFluidEqual(output);
if (found) addBackup(recipe);
return found;
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Melting recipe")
.add("could not find recipe with input %s and output %s", input, output)
.add("could not find recipe with input {} and output {}", input, output)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean removeFuel(FluidStack fluid) {
})) return true;

GroovyLog.msg("Error removing Tinkers Construct Smeltery Fuel")
.add("could not find smeltery fuel entry for %s", fluid)
.add("could not find smeltery fuel entry for {}", fluid)
.error()
.post();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public ItemStack[] getMatchingStacks() {
return new ItemStack[0];
}

@Override
public boolean isEmpty() {
return getAmount() <= 0;
}

@Override
public boolean test(ItemStack stack) {
if (matchCondition == null || ClosureHelper.call(true, matchCondition, stack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static NonNullList<Ingredient> toIngredientNonNullList(Collection<IIngred
}

public static boolean isEmpty(@Nullable IIngredient ingredient) {
return ingredient == null || ingredient.getMatchingStacks().length == 0 || ingredient.getAmount() <= 0;
return ingredient == null || ingredient.isEmpty();
}

public static boolean isEmpty(@Nullable ItemStack itemStack) {
Expand Down