Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CT 'inputs' getter, added 'nonConsumable' getter #1728

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions src/main/java/gregtech/api/recipes/crafttweaker/CTRecipe.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package gregtech.api.recipes.crafttweaker;

import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IngredientStack;
import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import crafttweaker.mc1120.item.MCItemStack;
import crafttweaker.mc1120.liquid.MCLiquidStack;
import gregtech.api.recipes.CountableIngredient;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import stanhebben.zenscript.annotations.Optional;
Expand All @@ -31,9 +34,22 @@ public CTRecipe(RecipeMap<?> recipeMap, Recipe backingRecipe) {
}

@ZenGetter("inputs")
public List<InputIngredient> getInputs() {
public List<IIngredient> getInputs() {
return this.backingRecipe.getInputs().stream()
.map(InputIngredient::new)
.filter(out -> out.getCount() > 0)
.map(ing -> new IngredientStack(
CraftTweakerMC.getIIngredient(ing.getIngredient()),
ing.getCount()))
.collect(Collectors.toList());
}

@ZenGetter("nonConsumable")
public List<IIngredient> getNonConsumableInputs() {
return this.backingRecipe.getInputs().stream()
.filter(out -> out.getCount() < 1)
.map(CountableIngredient::getIngredient)
.map(CraftTweakerMC::getIIngredient)
.map(ing -> new IngredientStack(ing, 0))
.collect(Collectors.toList());
}

Expand All @@ -51,6 +67,7 @@ public List<IItemStack> getResultItemOutputs(@Optional(valueLong = -1) long rand
.collect(Collectors.toList());
}

@Deprecated
@ZenGetter("changedOutputs")
public List<ChancedEntry> getChancedOutputs() {
ArrayList<ChancedEntry> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,16 @@ public CraftTweakerIngredientWrapper(IIngredient ingredient) {

@Override
public boolean apply(@Nullable ItemStack itemStack) {
itemStack = itemStack.copy();
if (itemStack == null) {
// Avoiding NPE
itemStack = ItemStack.EMPTY;
}

//because CT is dump enough to compare stack sizes by default...
itemStack.setCount(ingredient.getAmount());
return ingredient.matches(CraftTweakerMC.getIItemStack(itemStack));
// Setting stack size to 1 to avoid problem with non-consumable ingredients (count - 0)
IItemStack stack = CraftTweakerMC.getIItemStack(itemStack).amount(1);
return ingredient.amount(1)
.matches(stack);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

import java.util.List;

/**
* @deprecated
* 1. Not full implementation
* 2. CT provides required implementaions
* 3. Buggy
*/
@Deprecated
@ZenClass("mods.gregtech.recipe.InputIngredient")
@ZenRegister
public class InputIngredient implements IIngredient {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/gregtech/api/recipes/recipes/CokeOvenRecipe.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package gregtech.api.recipes.recipes;

import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IngredientStack;
import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import crafttweaker.mc1120.liquid.MCLiquidStack;
import gregtech.api.GTValues;
import gregtech.api.recipes.CountableIngredient;
import gregtech.api.recipes.crafttweaker.InputIngredient;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Optional.Method;
Expand Down Expand Up @@ -49,8 +50,11 @@ public int getDuration() {

@ZenGetter("input")
@Method(modid = GTValues.MODID_CT)
public InputIngredient ctGetInput() {
return new InputIngredient(getInput());
public IIngredient ctGetInput() {
CountableIngredient input = getInput();
return new IngredientStack(
CraftTweakerMC.getIIngredient(input.getIngredient()),
input.getCount());
}

@ZenGetter("output")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package gregtech.api.recipes.recipes;

import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IngredientStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import gregtech.api.GTValues;
import gregtech.api.recipes.CountableIngredient;
import gregtech.api.recipes.crafttweaker.InputIngredient;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Optional.Method;
import stanhebben.zenscript.annotations.ZenClass;
Expand Down Expand Up @@ -48,8 +49,11 @@ public int getFuelAmount() {

@ZenGetter("input")
@Method(modid = GTValues.MODID_CT)
public InputIngredient ctGetInput() {
return new InputIngredient(getInput());
public IIngredient ctGetInput() {
CountableIngredient input = getInput();
return new IngredientStack(
CraftTweakerMC.getIIngredient(input.getIngredient()),
input.getCount());
}

@ZenGetter("output")
Expand Down