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

Check against the CT ingredient's internal object #1155

Merged
merged 6 commits into from
Aug 24, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,37 @@ public CTRecipeBuilder hidden() {
return this;
}

private static String extractOreDictEntry(IIngredient ingredient) {
if (ingredient instanceof IOreDictEntry)
return ((IOreDictEntry) ingredient).getName();
if (ingredient.getInternal() instanceof IOreDictEntry)
return ((IOreDictEntry) ingredient.getInternal()).getName();
return null;
}

private static void checkIfExists(IIngredient ingredient, String oreDict) {
if (ingredient == null) {
throw new IllegalArgumentException("Invalid ingredient: is null");
}

if (ingredient.getItems().size() == 0) {
if (oreDict != null) {
throw new IllegalArgumentException("Invalid Ore Dictionary [" + oreDict + "]: contains no items");
} else {
throw new IllegalArgumentException("Invalid Item [" + ingredient.toString() + "]: item not found");
}
}
}

@ZenMethod
public CTRecipeBuilder inputs(IIngredient... ingredients) {
for (IIngredient ingredient : ingredients) {
if (ingredient instanceof IOreDictEntry) {
String oreDict = extractOreDictEntry(ingredient);
checkIfExists(ingredient, oreDict);

if (oreDict != null) {
this.backingBuilder.input(
GTRecipeOreInput.getOrCreate(((IOreDictEntry) ingredient).getName(), ingredient.getAmount()));
GTRecipeOreInput.getOrCreate(oreDict, ingredient.getAmount()));
} else {
this.backingBuilder.input(GTRecipeItemInput.getOrCreate(
new CraftTweakerItemInputWrapper(ingredient), ingredient.getAmount()));
Expand All @@ -62,13 +87,16 @@ public CTRecipeBuilder inputs(IIngredient... ingredients) {
@ZenMethod
public CTRecipeBuilder notConsumable(IIngredient... ingredients) {
for (IIngredient ingredient : ingredients) {
if (ingredient instanceof IOreDictEntry) {
String oreDict = extractOreDictEntry(ingredient);
checkIfExists(ingredient, oreDict);

if (oreDict != null) {
this.backingBuilder.input(
GTRecipeOreInput.getOrCreate(((IOreDictEntry) ingredient).getName(), ingredient.getAmount())
GTRecipeOreInput.getOrCreate(oreDict, ingredient.getAmount())
.setNonConsumable());
} else {
this.backingBuilder.input(GTRecipeItemInput.getOrCreate(
new CraftTweakerItemInputWrapper(ingredient), ingredient.getAmount())
new CraftTweakerItemInputWrapper(ingredient), ingredient.getAmount())
.setNonConsumable());
}
}
Expand Down