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

Fix NPE #11

Merged
merged 2 commits into from
May 11, 2022
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
1 change: 1 addition & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {
maven {
name = "ic2"
url = "https://maven.ic2.player.to/"
url = "https://maven2.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/minetweaker/mc1710/recipes/MCRecipeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IR
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
if(checkShapelessNulls(output, ingredients))
return;

recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action));
}

Expand Down Expand Up @@ -267,7 +267,7 @@ public IItemStack craft(IItemStack[][] contents) {
return getIItemStack(result);
}
}

public abstract static class ActionBaseRemoveRecipes implements IUndoableAction {
public abstract boolean matches(IRecipe r);
public abstract Set<IRecipe> find();
Expand All @@ -284,7 +284,7 @@ public static class ActionRemoveRecipesNoIngredients extends ActionBaseRemoveRec
public void addOutput(IIngredient output, @Optional boolean nbtMatch) {
outputs.add(Pair.of(output, nbtMatch));
}

public void clearOutputs() {
outputs.clear();
}
Expand Down Expand Up @@ -350,13 +350,13 @@ private boolean matches(IItemStack stack) {
}

}

public static class ActionRemoveShapelessRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
final IIngredient output;
final IIngredient[] ingredients;
final boolean wildcard;
Set<IRecipe> toRemove = new HashSet<>();

public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
this.output = output;
this.ingredients = ingredients;
Expand Down Expand Up @@ -434,7 +434,7 @@ public Set<IRecipe> find() {
public void apply() {
toRemove = find();
MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes.");
super.removeRecipes(toRemove);
super.removeRecipes(toRemove);
}

@Override
Expand Down Expand Up @@ -468,7 +468,7 @@ public Object getOverrideKey() {
return null;
}
}

public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
final IIngredient output;
final IIngredient[][] ingredients;
Expand Down Expand Up @@ -548,7 +548,7 @@ public void apply() {
toRemove = find();

MineTweakerAPI.logInfo(toRemove.size() + " removed");
super.removeRecipes(toRemove);
super.removeRecipes(toRemove);
}

@Override
Expand Down Expand Up @@ -582,20 +582,20 @@ public Object getOverrideKey() {
return null;
}
}

public static class ActionBaseAddRecipe implements IUndoableAction {
private final IRecipe iRecipe;
private final ICraftingRecipe craftingRecipe;

protected final IItemStack output;
protected final boolean isShaped;
protected final boolean isRestoring;

private ActionBaseAddRecipe(IRecipe iRecipe) {
this.iRecipe = iRecipe;
this.craftingRecipe = null;
this.isRestoring = true;

this.isShaped = iRecipe instanceof ShapedRecipes;
this.output = new MCItemStack(iRecipe.getRecipeOutput());
}
Expand All @@ -604,10 +604,10 @@ private ActionBaseAddRecipe(ICraftingRecipe craftingRecipe, IItemStack output, b
this.iRecipe = RecipeConverter.convert(craftingRecipe);
this.craftingRecipe = craftingRecipe;
this.isRestoring = false;

this.output = output;
this.isShaped = isShaped;

}

@Override
Expand Down Expand Up @@ -639,7 +639,7 @@ public String describe() {

@Override
public String describeUndo() {
return "Undoing addition of " + output.getDisplayName();
return "Undoing addition of " + (output != null ? output.getDisplayName() : "invalid output");
}

@Override
Expand All @@ -653,7 +653,7 @@ public ActionAddShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRe
super(new ShapedRecipe(output, ingredients, function, action, mirrored), output, true);
}
}

private static class ActionAddShapelessRecipe extends ActionBaseAddRecipe {
public ActionAddShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
super(new ShapelessRecipe(output, ingredients, function, action), output, false);
Expand Down Expand Up @@ -698,7 +698,7 @@ public Object getOverrideKey() {
return null;
}
}

public static void applyAdditionsAndRemovals() {
System.out.println("MineTweaker: Applying additions and removals");
MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients);
Expand All @@ -722,7 +722,7 @@ public static void applyAdditionsAndRemovals() {
recipesToRemove.forEach(ActionBaseRemoveRecipes::apply);
}
MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply);

actionRemoveRecipesNoIngredients.clearOutputs();
recipesToRemove.clear();;
recipesToAdd.clear();
Expand Down