mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fff244d95 | ||
|
|
e4a0cc8f35 | ||
|
|
7c0eb67215 | ||
|
|
9167cd1f1d |
No files matched your search
@@ -58,6 +58,7 @@ public class MineTweakerImplementationAPI {
|
|||||||
private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn();
|
private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn();
|
||||||
private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut();
|
private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut();
|
||||||
private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo();
|
private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo();
|
||||||
|
private static final EventList<ReloadEvent> ONROLLBACK = new EventList<>();
|
||||||
private static final EventList<ReloadEvent> ONRELOAD = new EventList<>();
|
private static final EventList<ReloadEvent> ONRELOAD = new EventList<>();
|
||||||
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<>();
|
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<>();
|
||||||
|
|
||||||
@@ -573,6 +574,9 @@ public class MineTweakerImplementationAPI {
|
|||||||
* @param handler
|
* @param handler
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
public static IEventHandle onRollbackEvent(IEventHandler<ReloadEvent> handler) {
|
||||||
|
return ONROLLBACK.add(handler);
|
||||||
|
}
|
||||||
public static IEventHandle onReloadEvent(IEventHandler<ReloadEvent> handler) {
|
public static IEventHandle onReloadEvent(IEventHandler<ReloadEvent> handler) {
|
||||||
return ONRELOAD.add(handler);
|
return ONRELOAD.add(handler);
|
||||||
}
|
}
|
||||||
@@ -623,6 +627,8 @@ public class MineTweakerImplementationAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MineTweakerAPI.tweaker.rollback();
|
MineTweakerAPI.tweaker.rollback();
|
||||||
|
ONROLLBACK.publish(new ReloadEvent());
|
||||||
|
|
||||||
if (MineTweakerAPI.server != null) {
|
if (MineTweakerAPI.server != null) {
|
||||||
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
||||||
server.addCommand("minetweaker", "", new String[]{"mt", "crafttweaker", "ct"}, new ICommandFunction() {
|
server.addCommand("minetweaker", "", new String[]{"mt", "crafttweaker", "ct"}, new ICommandFunction() {
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
int remove(IIngredient output, @Optional boolean nbtMatch);
|
int remove(IIngredient output, @Optional boolean nbtMatch);
|
||||||
|
|
||||||
|
int remove(IIngredient output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a shaped recipe.
|
* Adds a shaped recipe.
|
||||||
*
|
*
|
||||||
@@ -51,7 +53,12 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||||
|
|
||||||
|
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||||
|
|
||||||
|
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||||
|
|
||||||
|
void addShaped(IItemStack output, IIngredient[][] ingredients);
|
||||||
/**
|
/**
|
||||||
* Adds a mirrored shaped recipe.
|
* Adds a mirrored shaped recipe.
|
||||||
*
|
*
|
||||||
@@ -61,7 +68,12 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||||
|
|
||||||
|
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||||
|
|
||||||
|
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||||
|
|
||||||
|
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients);
|
||||||
/**
|
/**
|
||||||
* Adds a shapeless recipe.
|
* Adds a shapeless recipe.
|
||||||
*
|
*
|
||||||
@@ -71,7 +83,13 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||||
|
|
||||||
|
void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function);
|
||||||
|
|
||||||
|
void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeAction action);
|
||||||
|
|
||||||
|
void addShapeless(IItemStack output, IIngredient[] ingredients);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes shaped recipes.
|
* Removes shaped recipes.
|
||||||
*
|
*
|
||||||
@@ -82,7 +100,8 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients);
|
int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients);
|
||||||
|
|
||||||
|
int removeShaped(IIngredient output);
|
||||||
/**
|
/**
|
||||||
* Removes shapeless recipes.
|
* Removes shapeless recipes.
|
||||||
*
|
*
|
||||||
@@ -95,7 +114,13 @@ public interface IRecipeManager {
|
|||||||
*/
|
*/
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard);
|
int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard);
|
||||||
|
|
||||||
|
int removeShapeless(IIngredient output, boolean wildcard);
|
||||||
|
|
||||||
|
int removeShapeless(IIngredient output, IIngredient[] ingredients);
|
||||||
|
|
||||||
|
int removeShapeless(IIngredient output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a crafting with the specified ingredients. Returns null if no
|
* Performs a crafting with the specified ingredients. Returns null if no
|
||||||
* crafting recipe exists.
|
* crafting recipe exists.
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class MTTweaker implements ITweaker {
|
|||||||
|
|
||||||
Object overrideKey = action.getOverrideKey();
|
Object overrideKey = action.getOverrideKey();
|
||||||
if (wereStuck.contains(action)) {
|
if (wereStuck.contains(action)) {
|
||||||
|
MineTweakerAPI.logInfo("WAS STUCK");
|
||||||
wereStuck.remove(action);
|
wereStuck.remove(action);
|
||||||
|
|
||||||
if (overrideKey != null) {
|
if (overrideKey != null) {
|
||||||
@@ -76,7 +77,8 @@ public class MTTweaker implements ITweaker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IUndoableAction> rollback() {
|
public List<IUndoableAction> rollback() {
|
||||||
List<IUndoableAction> stuck = new ArrayList<IUndoableAction>();
|
// Note: Requires a OnRollback event to be fired. If this is called from MineTweakerImplementationAPI it's handled there.
|
||||||
|
List<IUndoableAction> stuck = new ArrayList<>();
|
||||||
for (int i = actions.size() - 1; i >= 0; i--) {
|
for (int i = actions.size() - 1; i >= 0; i--) {
|
||||||
IUndoableAction action = actions.get(i);
|
IUndoableAction action = actions.get(i);
|
||||||
if (action.canUndo()) {
|
if (action.canUndo()) {
|
||||||
|
|||||||
+139
-29
@@ -48,12 +48,14 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
public static final List<ActionBaseAddRecipe> recipesToAdd = new ArrayList<>();
|
public static final List<ActionBaseAddRecipe> recipesToAdd = new ArrayList<>();
|
||||||
public static final List<ActionBaseRemoveRecipes> recipesToRemove = new ArrayList<>();
|
public static final List<ActionBaseRemoveRecipes> recipesToRemove = new ArrayList<>();
|
||||||
public static final ActionRemoveRecipesNoIngredients actionRemoveRecipesNoIngredients = new ActionRemoveRecipesNoIngredients();
|
public static final ActionRemoveRecipesNoIngredients actionRemoveRecipesNoIngredients = new ActionRemoveRecipesNoIngredients();
|
||||||
|
public static final List<IRecipe> recipesToUndo = new ArrayList<>();
|
||||||
|
|
||||||
public static List<IRecipe> recipes;
|
public static List<IRecipe> recipes;
|
||||||
public static final List<ICraftingRecipe> transformerRecipes = new ArrayList<>();
|
public static final List<ICraftingRecipe> transformerRecipes = new ArrayList<>();
|
||||||
|
|
||||||
public MCRecipeManager() {
|
public MCRecipeManager() {
|
||||||
MineTweakerImplementationAPI.onPostReload(new HandlePostReload());
|
MineTweakerImplementationAPI.onPostReload(new HandleLateAdditionsAndRemovals());
|
||||||
|
MineTweakerImplementationAPI.onRollbackEvent(new HandleLateAdditionsAndRemovals());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasTransformerRecipes() {
|
public static boolean hasTransformerRecipes() {
|
||||||
@@ -109,6 +111,11 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int remove(IIngredient output) {
|
||||||
|
return remove(output, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int remove(IIngredient output, @Optional boolean nbtMatch) {
|
public int remove(IIngredient output, @Optional boolean nbtMatch) {
|
||||||
if(output == null) {
|
if(output == null) {
|
||||||
@@ -119,11 +126,41 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, null, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeAction action) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, null, action, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShaped(IItemStack output, IIngredient[][] ingredients) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, null, null, false));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||||
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, false));
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, null, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, null, null, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeAction action) {
|
||||||
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, null, action, true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||||
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, true));
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, true));
|
||||||
@@ -137,6 +174,21 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action));
|
recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function){
|
||||||
|
addShapeless(output, ingredients, function, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeAction action){
|
||||||
|
addShapeless(output, ingredients, null, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addShapeless(IItemStack output, IIngredient[] ingredients){
|
||||||
|
addShapeless(output, ingredients, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkShapelessNulls(IItemStack output, IIngredient[] ingredients) {
|
private boolean checkShapelessNulls(IItemStack output, IIngredient[] ingredients) {
|
||||||
if(output != null && Arrays.stream(ingredients).allMatch(Objects::isNull)) {
|
if(output != null && Arrays.stream(ingredients).allMatch(Objects::isNull)) {
|
||||||
MineTweakerAPI.logError("Null not allowed in shapeless recipes! Recipe for: " + output + " not created!");
|
MineTweakerAPI.logError("Null not allowed in shapeless recipes! Recipe for: " + output + " not created!");
|
||||||
@@ -155,6 +207,11 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int removeShaped(IIngredient output) {
|
||||||
|
return removeShaped(output, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||||
if(output == null) {
|
if(output == null) {
|
||||||
@@ -165,6 +222,21 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int removeShapeless(IIngredient output, IIngredient[] ingredients) {
|
||||||
|
return removeShapeless(output, ingredients, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int removeShapeless(IIngredient output, boolean wildcard) {
|
||||||
|
return removeShapeless(output, null, wildcard);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int removeShapeless(IIngredient output) {
|
||||||
|
return removeShapeless(output, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IItemStack craft(IItemStack[][] contents) {
|
public IItemStack craft(IItemStack[][] contents) {
|
||||||
Container container = new ContainerVirtual();
|
Container container = new ContainerVirtual();
|
||||||
@@ -205,14 +277,19 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
public static class ActionRemoveRecipesNoIngredients extends ActionBaseRemoveRecipes implements IUndoableAction {
|
public static class ActionRemoveRecipesNoIngredients extends ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
// pair of output, nbtMatch
|
// pair of output, nbtMatch
|
||||||
private final List<Pair<IIngredient, Boolean>> outputs = new ArrayList<>();
|
private final List<Pair<IIngredient, Boolean>> outputs = new ArrayList<>();
|
||||||
|
private final Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
public void addOutput(IIngredient output, @Optional boolean nbtMatch) {
|
public void addOutput(IIngredient output, @Optional boolean nbtMatch) {
|
||||||
outputs.add(Pair.of(output, nbtMatch));
|
outputs.add(Pair.of(output, nbtMatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearOutputs() {
|
||||||
|
outputs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
Set<IRecipe> toRemove = new HashSet<>();
|
toRemove.clear();
|
||||||
|
|
||||||
for (final IRecipe recipe : recipes) {
|
for (final IRecipe recipe : recipes) {
|
||||||
final ItemStack recipeOutput = recipe.getRecipeOutput();
|
final ItemStack recipeOutput = recipe.getRecipeOutput();
|
||||||
@@ -228,12 +305,14 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return !toRemove.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
for(IRecipe recipe: toRemove) {
|
||||||
|
recipesToAdd.add(new ActionBaseAddRecipe(recipe));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -243,7 +322,7 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return null;
|
return "Trying to restore " + toRemove.size() + " recipes.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -268,7 +347,8 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
final IIngredient output;
|
final IIngredient output;
|
||||||
final IIngredient[] ingredients;
|
final IIngredient[] ingredients;
|
||||||
final boolean wildcard;
|
final boolean wildcard;
|
||||||
|
Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
@@ -277,7 +357,7 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
Set<IRecipe> toRemove = new HashSet<>();
|
toRemove.clear();
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for (IRecipe recipe : recipes) {
|
for (IRecipe recipe : recipes) {
|
||||||
@@ -342,12 +422,14 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return !toRemove.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
for(IRecipe recipe: toRemove) {
|
||||||
|
recipesToAdd.add(new ActionBaseAddRecipe(recipe));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -361,7 +443,7 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return null;
|
return "Trying to restore " + toRemove.size() + " shapeless recipes.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -373,6 +455,8 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
|
public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
final IIngredient output;
|
final IIngredient output;
|
||||||
final IIngredient[][] ingredients;
|
final IIngredient[][] ingredients;
|
||||||
|
final Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ActionRemoveShapedRecipes(IIngredient output, IIngredient[][] ingredients) {
|
public ActionRemoveShapedRecipes(IIngredient output, IIngredient[][] ingredients) {
|
||||||
@@ -384,6 +468,7 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
public void apply() {
|
public void apply() {
|
||||||
int ingredientsWidth = 0;
|
int ingredientsWidth = 0;
|
||||||
int ingredientsHeight = 0;
|
int ingredientsHeight = 0;
|
||||||
|
toRemove.clear();
|
||||||
|
|
||||||
if (ingredients != null) {
|
if (ingredients != null) {
|
||||||
ingredientsHeight = ingredients.length;
|
ingredientsHeight = ingredients.length;
|
||||||
@@ -393,8 +478,6 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<IRecipe> toRemove = new HashSet<>();
|
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for (final IRecipe recipe : recipes) {
|
for (final IRecipe recipe : recipes) {
|
||||||
final ItemStack output = recipe.getRecipeOutput();
|
final ItemStack output = recipe.getRecipeOutput();
|
||||||
@@ -438,22 +521,28 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return !toRemove.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
for(IRecipe recipe: toRemove) {
|
||||||
|
recipesToAdd.add(new ActionBaseAddRecipe(recipe));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe() {
|
public String describe() {
|
||||||
return null;
|
if(output != null) {
|
||||||
|
return "Removing Shaped recipes for " + output.toString();
|
||||||
|
} else {
|
||||||
|
return "Trying to remove recipes for invalid output";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return null;
|
return "Trying to restore " + toRemove.size() + " shaped recipes.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -468,39 +557,49 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
protected final IItemStack output;
|
protected final IItemStack output;
|
||||||
protected final boolean isShaped;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
private ActionBaseAddRecipe(ICraftingRecipe craftingRecipe, IItemStack output, boolean isShaped) {
|
private ActionBaseAddRecipe(ICraftingRecipe craftingRecipe, IItemStack output, boolean isShaped) {
|
||||||
this.iRecipe = RecipeConverter.convert(craftingRecipe);
|
this.iRecipe = RecipeConverter.convert(craftingRecipe);
|
||||||
this.craftingRecipe = craftingRecipe;
|
this.craftingRecipe = craftingRecipe;
|
||||||
|
this.isRestoring = false;
|
||||||
|
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.isShaped = isShaped;
|
this.isShaped = isShaped;
|
||||||
|
|
||||||
// if(craftingRecipe.hasTransformers())
|
|
||||||
// transformerRecipes.add(craftingRecipe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
recipes.add(iRecipe);
|
recipes.add(iRecipe);
|
||||||
if (craftingRecipe.hasTransformers())
|
if (craftingRecipe != null && craftingRecipe.hasTransformers())
|
||||||
transformerRecipes.add(craftingRecipe);
|
transformerRecipes.add(craftingRecipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return iRecipe != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
recipesToUndo.add(iRecipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describe() {
|
public String describe() {
|
||||||
|
|
||||||
if(output != null) {
|
if(output != null) {
|
||||||
return "Adding " + (isShaped ? "shaped" : "shapeless") + " recipe for " + output.getDisplayName();
|
return "" + (this.isRestoring ? "Restoring" : "Adding ") + (isShaped ? "shaped" : "shapeless") + " recipe for " + output.getDisplayName();
|
||||||
} else {
|
} else {
|
||||||
return "Trying to add " + (isShaped ? "shaped" : "shapeless") + "recipe without correct output";
|
return "Trying to add " + (isShaped ? "shaped" : "shapeless") + "recipe without correct output";
|
||||||
}
|
}
|
||||||
@@ -508,7 +607,7 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
return null;
|
return "Undoing addition of " + output.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -528,17 +627,28 @@ public final class MCRecipeManager implements IRecipeManager {
|
|||||||
super(new ShapelessRecipe(output, ingredients, function, action), output, false);
|
super(new ShapelessRecipe(output, ingredients, function, action), output, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void applyAdditionsAndRemovals() {
|
||||||
|
System.out.println("MineTweaker: Applying additions and removals");
|
||||||
|
MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients);
|
||||||
|
if(recipesToUndo.size() > 0) {
|
||||||
|
recipes.removeIf(recipesToUndo::contains);
|
||||||
|
}
|
||||||
|
MCRecipeManager.recipesToRemove.forEach(MineTweakerAPI::apply);
|
||||||
|
MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply);
|
||||||
|
|
||||||
|
actionRemoveRecipesNoIngredients.clearOutputs();
|
||||||
|
recipesToRemove.clear();;
|
||||||
|
recipesToAdd.clear();
|
||||||
|
recipesToUndo.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static class HandlePostReload implements IEventHandler<MineTweakerImplementationAPI.ReloadEvent>
|
public static class HandleLateAdditionsAndRemovals implements IEventHandler<MineTweakerImplementationAPI.ReloadEvent>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void handle(MineTweakerImplementationAPI.ReloadEvent event)
|
public void handle(MineTweakerImplementationAPI.ReloadEvent event)
|
||||||
{
|
{
|
||||||
System.out.println("MineTweaker: Applying additions and removals");
|
MCRecipeManager.applyAdditionsAndRemovals();
|
||||||
MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients);
|
|
||||||
MCRecipeManager.recipesToRemove.forEach(MineTweakerAPI::apply);
|
|
||||||
MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import javax.tools.ToolProvider
|
|||||||
// ### Global settings ###
|
// ### Global settings ###
|
||||||
// #######################
|
// #######################
|
||||||
|
|
||||||
ext.mineTweakerVersion = "3.2.1-GTNH"
|
ext.mineTweakerVersion = "3.2.2-GTNH"
|
||||||
if (System.getenv('BUILD_NUMBER') != null)
|
if (System.getenv('BUILD_NUMBER') != null)
|
||||||
project.mineTweakerVersion += "."+System.getenv('BUILD_NUMBER')
|
project.mineTweakerVersion += "."+System.getenv('BUILD_NUMBER')
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in new issue
Block a user