mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11c68ce42a | ||
|
|
94705aeacf | ||
|
|
449ce974f4 |
No files matched your search
@@ -58,8 +58,8 @@ 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> ONRELOAD = new EventList<ReloadEvent>();
|
private static final EventList<ReloadEvent> ONRELOAD = new EventList<>();
|
||||||
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<ReloadEvent>();
|
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
minetweakerCommands = new HashMap<String, MineTweakerCommand>();
|
minetweakerCommands = new HashMap<String, MineTweakerCommand>();
|
||||||
@@ -621,27 +621,6 @@ public class MineTweakerImplementationAPI {
|
|||||||
events.onPlayerLoggedIn(LISTEN_LOGIN);
|
events.onPlayerLoggedIn(LISTEN_LOGIN);
|
||||||
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// byte[] currentScript = MineTweakerAPI.tweaker.getScriptData();
|
|
||||||
// if (currentScript != null) {
|
|
||||||
// System.out.println("Already loaded a script before");
|
|
||||||
//
|
|
||||||
// // alread loaded a script
|
|
||||||
// byte[] stagedScript = MineTweakerAPI.tweaker.getStagedScriptData();
|
|
||||||
//
|
|
||||||
// if (Arrays.equals(currentScript, stagedScript)) {
|
|
||||||
// System.out.println("No reload needed");
|
|
||||||
// return; // no reload necessary
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (MineTweakerAPI.game.isLocked()) {
|
|
||||||
// System.out.println("Reload blocked");
|
|
||||||
// MineTweakerAPI.game.signalLockError();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// System.out.println("First time loading a script, go ahead");
|
|
||||||
// }
|
|
||||||
|
|
||||||
MineTweakerAPI.tweaker.rollback();
|
MineTweakerAPI.tweaker.rollback();
|
||||||
if (MineTweakerAPI.server != null) {
|
if (MineTweakerAPI.server != null) {
|
||||||
|
|||||||
@@ -28,21 +28,14 @@ public class ShapedRecipe implements ICraftingRecipe {
|
|||||||
|
|
||||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
||||||
int numIngredients = 0;
|
int numIngredients = 0;
|
||||||
for(int i = 0; i < ingredients.length; i++) {
|
for (IIngredient[] ingredient : ingredients) {
|
||||||
IIngredient[] ingredient = ingredients[i];
|
for (IIngredient iIngredient : ingredient) {
|
||||||
for(int i1 = 0; i1 < ingredient.length; i1++) {
|
if (iIngredient != null) {
|
||||||
if(ingredient[i1] != null) {
|
|
||||||
numIngredients++;
|
numIngredients++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// for(IIngredient[] row : ingredients) {
|
|
||||||
// for(IIngredient ingredient : row) {
|
|
||||||
// if(ingredient != null) {
|
|
||||||
// numIngredients++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
this.posx = new byte[numIngredients];
|
this.posx = new byte[numIngredients];
|
||||||
this.posy = new byte[numIngredients];
|
this.posy = new byte[numIngredients];
|
||||||
this.output = output;
|
this.output = output;
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class MTTweaker implements ITweaker {
|
|||||||
System.out.println("Loading scripts");
|
System.out.println("Loading scripts");
|
||||||
|
|
||||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||||
Set<String> executed = new HashSet<String>();
|
Set<String> executed = new HashSet<>();
|
||||||
|
|
||||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||||
while (scripts.hasNext()) {
|
while (scripts.hasNext()) {
|
||||||
@@ -120,10 +120,10 @@ public class MTTweaker implements ITweaker {
|
|||||||
if (!executed.contains(script.getGroupName())) {
|
if (!executed.contains(script.getGroupName())) {
|
||||||
executed.add(script.getGroupName());
|
executed.add(script.getGroupName());
|
||||||
|
|
||||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
Map<String, byte[]> classes = new HashMap<>();
|
||||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||||
|
|
||||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
List<ZenParsedFile> files = new ArrayList<>();
|
||||||
|
|
||||||
while (script.next()) {
|
while (script.next()) {
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import minetweaker.api.minecraft.MineTweakerMC;
|
|||||||
import minetweaker.api.player.IPlayer;
|
import minetweaker.api.player.IPlayer;
|
||||||
import minetweaker.mc1710.network.MineTweakerLoadScriptsPacket;
|
import minetweaker.mc1710.network.MineTweakerLoadScriptsPacket;
|
||||||
import minetweaker.mc1710.recipes.MCCraftingInventory;
|
import minetweaker.mc1710.recipes.MCCraftingInventory;
|
||||||
|
import minetweaker.mc1710.recipes.MCRecipeManager;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||||
@@ -32,8 +33,8 @@ public class FMLEventHandler {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent ev) {
|
public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent ev) {
|
||||||
IPlayer iPlayer = MineTweakerMC.getIPlayer(ev.player);
|
IPlayer iPlayer = MineTweakerMC.getIPlayer(ev.player);
|
||||||
if (MineTweakerMod.INSTANCE.recipes.hasTransformerRecipes()) {
|
if (MCRecipeManager.hasTransformerRecipes()) {
|
||||||
MineTweakerMod.INSTANCE.recipes.applyTransformations(MCCraftingInventory.get(ev.craftMatrix, ev.player), iPlayer);
|
MCRecipeManager.applyTransformations(MCCraftingInventory.get(ev.craftMatrix, ev.player), iPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MineTweakerImplementationAPI.events.hasPlayerCrafted()) {
|
if (MineTweakerImplementationAPI.events.hasPlayerCrafted()) {
|
||||||
|
|||||||
@@ -35,10 +35,13 @@ import minetweaker.runtime.*;
|
|||||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||||
import minetweaker.runtime.providers.ScriptProviderCustom;
|
import minetweaker.runtime.providers.ScriptProviderCustom;
|
||||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main mod class. Performs some general logic, initialization of the API and
|
* Main mod class. Performs some general logic, initialization of the API and
|
||||||
@@ -77,20 +80,21 @@ public class MineTweakerMod {
|
|||||||
@Mod.Instance(MODID)
|
@Mod.Instance(MODID)
|
||||||
public static MineTweakerMod INSTANCE;
|
public static MineTweakerMod INSTANCE;
|
||||||
|
|
||||||
public final MCRecipeManager recipes;
|
|
||||||
private final IScriptProvider scriptsGlobal;
|
private final IScriptProvider scriptsGlobal;
|
||||||
private final ScriptProviderCustom scriptsIMC;
|
private final ScriptProviderCustom scriptsIMC;
|
||||||
|
|
||||||
public MineTweakerMod() {
|
public MineTweakerMod() {
|
||||||
|
MCRecipeManager.recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
||||||
MineTweakerImplementationAPI.init(
|
MineTweakerImplementationAPI.init(
|
||||||
new MCOreDict(),
|
new MCOreDict(),
|
||||||
recipes = new MCRecipeManager(),
|
new MCRecipeManager(),
|
||||||
new MCFurnaceManager(),
|
new MCFurnaceManager(),
|
||||||
MCGame.INSTANCE,
|
MCGame.INSTANCE,
|
||||||
new MCLoadedMods(),
|
new MCLoadedMods(),
|
||||||
new MCFormatter(),
|
new MCFormatter(),
|
||||||
new MCVanilla());
|
new MCVanilla());
|
||||||
|
|
||||||
|
|
||||||
MineTweakerImplementationAPI.logger.addLogger(new FileLogger(new File("minetweaker.log")));
|
MineTweakerImplementationAPI.logger.addLogger(new FileLogger(new File("minetweaker.log")));
|
||||||
MineTweakerImplementationAPI.platform = MCPlatformFunctions.INSTANCE;
|
MineTweakerImplementationAPI.platform = MCPlatformFunctions.INSTANCE;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class MCItemStack implements IItemStack {
|
|||||||
throw new IllegalArgumentException("stack cannot be null");
|
throw new IllegalArgumentException("stack cannot be null");
|
||||||
|
|
||||||
stack = itemStack.copy();
|
stack = itemStack.copy();
|
||||||
items = Collections.<IItemStack>singletonList(this);
|
items = Collections.singletonList(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MCItemStack(ItemStack itemStack, boolean wildcardSize) {
|
public MCItemStack(ItemStack itemStack, boolean wildcardSize) {
|
||||||
@@ -67,13 +67,13 @@ public class MCItemStack implements IItemStack {
|
|||||||
throw new IllegalArgumentException("stack cannot be null");
|
throw new IllegalArgumentException("stack cannot be null");
|
||||||
|
|
||||||
stack = itemStack;
|
stack = itemStack;
|
||||||
items = Collections.<IItemStack>singletonList(this);
|
items = Collections.singletonList(this);
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) {
|
private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) {
|
||||||
stack = itemStack;
|
stack = itemStack;
|
||||||
items = Collections.<IItemStack>singletonList(this);
|
items = Collections.singletonList(this);
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.wildcardSize = wildcardSize;
|
this.wildcardSize = wildcardSize;
|
||||||
}
|
}
|
||||||
|
|||||||
+430
-297
@@ -2,12 +2,21 @@ package minetweaker.mc1710.recipes;
|
|||||||
|
|
||||||
import minetweaker.IUndoableAction;
|
import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
|
import minetweaker.MineTweakerImplementationAPI;
|
||||||
import minetweaker.api.item.IIngredient;
|
import minetweaker.api.item.IIngredient;
|
||||||
import minetweaker.api.item.IItemStack;
|
import minetweaker.api.item.IItemStack;
|
||||||
import minetweaker.api.minecraft.MineTweakerMC;
|
import minetweaker.api.minecraft.MineTweakerMC;
|
||||||
import minetweaker.api.player.IPlayer;
|
import minetweaker.api.player.IPlayer;
|
||||||
import minetweaker.api.recipes.*;
|
import minetweaker.api.recipes.ICraftingInventory;
|
||||||
|
import minetweaker.api.recipes.ICraftingRecipe;
|
||||||
|
import minetweaker.api.recipes.IRecipeAction;
|
||||||
|
import minetweaker.api.recipes.IRecipeFunction;
|
||||||
|
import minetweaker.api.recipes.IRecipeManager;
|
||||||
|
import minetweaker.api.recipes.ShapedRecipe;
|
||||||
|
import minetweaker.api.recipes.ShapelessRecipe;
|
||||||
|
import minetweaker.mc1710.item.MCItemStack;
|
||||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||||
|
import minetweaker.util.IEventHandler;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
@@ -18,30 +27,40 @@ import net.minecraft.item.crafting.ShapedRecipes;
|
|||||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
import stanhebben.zenscript.annotations.Optional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static minetweaker.api.minecraft.MineTweakerMC.*;
|
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||||
|
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||||
|
import static minetweaker.api.minecraft.MineTweakerMC.getOreDict;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stan
|
* @author Stan
|
||||||
*/
|
*/
|
||||||
public class MCRecipeManager implements IRecipeManager {
|
public final class MCRecipeManager implements IRecipeManager {
|
||||||
private final List<IRecipe> recipes;
|
public static final List<ActionBaseAddRecipe> recipesToAdd = new ArrayList<>();
|
||||||
private final List<ICraftingRecipe> transformerRecipes;
|
public static final List<ActionBaseRemoveRecipes> recipesToRemove = new ArrayList<>();
|
||||||
|
public static final ActionRemoveRecipesNoIngredients actionRemoveRecipesNoIngredients = new ActionRemoveRecipesNoIngredients();
|
||||||
|
|
||||||
|
public static List<IRecipe> recipes;
|
||||||
|
public static final List<ICraftingRecipe> transformerRecipes = new ArrayList<>();
|
||||||
|
|
||||||
public MCRecipeManager() {
|
public MCRecipeManager() {
|
||||||
recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
MineTweakerImplementationAPI.onPostReload(new HandlePostReload());
|
||||||
transformerRecipes = new ArrayList<ICraftingRecipe>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasTransformerRecipes() {
|
public static boolean hasTransformerRecipes() {
|
||||||
return transformerRecipes.size() > 0;
|
return transformerRecipes.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyTransformations(ICraftingInventory inventory, IPlayer byPlayer) {
|
public static void applyTransformations(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||||
for (ICraftingRecipe recipe : transformerRecipes) {
|
for (ICraftingRecipe recipe : transformerRecipes) {
|
||||||
if (recipe.matches(inventory)) {
|
if (recipe.matches(inventory)) {
|
||||||
recipe.applyTransformers(inventory, byPlayer);
|
recipe.applyTransformers(inventory, byPlayer);
|
||||||
@@ -50,9 +69,35 @@ public class MCRecipeManager implements IRecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean matches(Object input, IIngredient ingredient) {
|
||||||
|
if ((input == null) != (ingredient == null)) {
|
||||||
|
return false;
|
||||||
|
} else if (ingredient != null) {
|
||||||
|
if (input instanceof ItemStack) {
|
||||||
|
return ingredient.matches(getIItemStack((ItemStack) input));
|
||||||
|
} else if (input instanceof String) {
|
||||||
|
return ingredient.contains(getOreDict((String) input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICraftingRecipe> getAll() {
|
||||||
|
List<ICraftingRecipe> results = new ArrayList<>();
|
||||||
|
|
||||||
|
for (IRecipe recipe : recipes) {
|
||||||
|
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
||||||
|
results.add(converted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
||||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
List<ICraftingRecipe> results = new ArrayList<>();
|
||||||
|
|
||||||
for (IRecipe recipe : recipes) {
|
for (IRecipe recipe : recipes) {
|
||||||
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
|
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
|
||||||
@@ -64,204 +109,60 @@ public class MCRecipeManager implements IRecipeManager {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ICraftingRecipe> getAll() {
|
|
||||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
|
||||||
|
|
||||||
for (IRecipe recipe : recipes) {
|
|
||||||
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
|
|
||||||
results.add(converted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int remove(IIngredient output, @Optional boolean nbtMatch) {
|
public int remove(IIngredient output, @Optional boolean nbtMatch) {
|
||||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
if(output == null) {
|
||||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
MineTweakerAPI.logError("Cannot remove recipes for a null item!");
|
||||||
for (int i = 0; i < recipes.size(); i++) {
|
return 0;
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
// certain special recipes have no predefined output. ignore those
|
|
||||||
// since these cannot be removed with MineTweaker scripts
|
|
||||||
if (recipe.getRecipeOutput() != null) {
|
|
||||||
if (nbtMatch ? output.matchesExact(getIItemStack(recipe.getRecipeOutput())) : output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
actionRemoveRecipesNoIngredients.addOutput(output, nbtMatch);
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
return 1;
|
||||||
return toRemove.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||||
addShaped(output, ingredients, function, action, false);
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||||
addShaped(output, ingredients, function, action, true);
|
recipesToAdd.add(new ActionAddShapedRecipe(output, ingredients, function, action, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
|
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||||
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function, action);
|
if(checkShapelessNulls(output, ingredients))
|
||||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
return;
|
||||||
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
|
|
||||||
|
recipesToAdd.add(new ActionAddShapelessRecipe(output, ingredients, function, action));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkShapelessNulls(IItemStack output, IIngredient[] ingredients) {
|
||||||
|
if(output != null && Arrays.stream(ingredients).allMatch(Objects::isNull)) {
|
||||||
|
MineTweakerAPI.logError("Null not allowed in shapeless recipes! Recipe for: " + output + " not created!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
||||||
int ingredientsWidth = 0;
|
if(output == null) {
|
||||||
int ingredientsHeight = 0;
|
MineTweakerAPI.logError("Cannot remove recipes for a null item!");
|
||||||
|
return 0;
|
||||||
if (ingredients != null) {
|
|
||||||
ingredientsHeight = ingredients.length;
|
|
||||||
|
|
||||||
for (int i = 0; i < ingredients.length; i++) {
|
|
||||||
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
recipesToRemove.add(new ActionRemoveShapedRecipes(output, ingredients));
|
||||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
return 1;
|
||||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
|
||||||
outer:
|
|
||||||
for (int i = 0; i < recipes.size(); i++) {
|
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ingredients != null) {
|
|
||||||
if (recipe instanceof ShapedRecipes) {
|
|
||||||
ShapedRecipes srecipe = (ShapedRecipes) recipe;
|
|
||||||
if (ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < ingredientsHeight; j++) {
|
|
||||||
IIngredient[] row = ingredients[j];
|
|
||||||
for (int k = 0; k < ingredientsWidth; k++) {
|
|
||||||
IIngredient ingredient = k > row.length ? null : row[k];
|
|
||||||
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
|
|
||||||
|
|
||||||
if (!matches(recipeIngredient, ingredient)) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (recipe instanceof ShapedOreRecipe) {
|
|
||||||
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
|
|
||||||
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
|
|
||||||
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
|
|
||||||
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < ingredientsHeight; j++) {
|
|
||||||
IIngredient[] row = ingredients[j];
|
|
||||||
for (int k = 0; k < ingredientsWidth; k++) {
|
|
||||||
IIngredient ingredient = k > row.length ? null : row[k];
|
|
||||||
Object input = srecipe.getInput()[j * recipeWidth + k];
|
|
||||||
if (!matches(input, ingredient)) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (recipe instanceof ShapedRecipes) {
|
|
||||||
|
|
||||||
} else if (recipe instanceof ShapedOreRecipe) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
|
||||||
return toRemove.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
if(output == null) {
|
||||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
MineTweakerAPI.logError("Cannot remove recipes for a null item!");
|
||||||
outer:
|
return 0;
|
||||||
for (int i = 0; i < recipes.size(); i++) {
|
|
||||||
IRecipe recipe = recipes.get(i);
|
|
||||||
|
|
||||||
if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ingredients != null) {
|
|
||||||
if (recipe instanceof ShapelessRecipes) {
|
|
||||||
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
|
||||||
|
|
||||||
if (ingredients.length > srecipe.getRecipeSize()) {
|
|
||||||
continue;
|
|
||||||
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIngredient:
|
|
||||||
for (int j = 0; j < ingredients.length; j++) {
|
|
||||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
|
||||||
if (matches(srecipe.recipeItems.get(k), ingredients[j])) {
|
|
||||||
continue checkIngredient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
|
||||||
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
|
|
||||||
ArrayList<Object> inputs = srecipe.getInput();
|
|
||||||
|
|
||||||
if (inputs.size() < ingredients.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!wildcard && inputs.size() > ingredients.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIngredient:
|
|
||||||
for (int j = 0; j < ingredients.length; j++) {
|
|
||||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
|
||||||
if (matches(inputs.get(k), ingredients[j])) {
|
|
||||||
continue checkIngredient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (recipe instanceof ShapelessRecipes) {
|
|
||||||
|
|
||||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemove.add(recipe);
|
|
||||||
removeIndex.add(i);
|
|
||||||
}
|
}
|
||||||
|
recipesToRemove.add(new ActionRemoveShapelessRecipes(output, ingredients, wildcard));
|
||||||
MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
return 1;
|
||||||
return toRemove.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -295,6 +196,352 @@ public class MCRecipeManager implements IRecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract static class ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
|
public void removeRecipes(Set<IRecipe> toRemove ) {
|
||||||
|
recipes.removeIf(toRemove::contains);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ActionRemoveRecipesNoIngredients extends ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
|
// pair of output, nbtMatch
|
||||||
|
private final List<Pair<IIngredient, Boolean>> outputs = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addOutput(IIngredient output, @Optional boolean nbtMatch) {
|
||||||
|
outputs.add(Pair.of(output, nbtMatch));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() {
|
||||||
|
Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
|
for (final IRecipe recipe : recipes) {
|
||||||
|
final ItemStack recipeOutput = recipe.getRecipeOutput();
|
||||||
|
if (recipeOutput != null) {
|
||||||
|
final IItemStack stack = getIItemStack(recipeOutput);
|
||||||
|
if (matches(stack)) {
|
||||||
|
toRemove.add(recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.removeRecipes(toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
return "Removing recipes for various outputs";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matches(IItemStack stack) {
|
||||||
|
for(Pair<IIngredient, Boolean> entry : outputs) {
|
||||||
|
IIngredient output = entry.getKey();
|
||||||
|
Boolean nbtMatch = entry.getValue();
|
||||||
|
if(nbtMatch ? output.matchesExact(stack) : output.matches(stack)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ActionRemoveShapelessRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
|
final IIngredient output;
|
||||||
|
final IIngredient[] ingredients;
|
||||||
|
final boolean wildcard;
|
||||||
|
|
||||||
|
public ActionRemoveShapelessRecipes(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||||
|
this.output = output;
|
||||||
|
this.ingredients = ingredients;
|
||||||
|
this.wildcard = wildcard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() {
|
||||||
|
Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
|
outer:
|
||||||
|
for (IRecipe recipe : recipes) {
|
||||||
|
if (recipe.getRecipeOutput() == null || !output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (recipe instanceof ShapedRecipes) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(recipe instanceof ShapelessRecipes) && !(recipe instanceof ShapelessOreRecipe)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ingredients != null) {
|
||||||
|
if (recipe instanceof ShapelessRecipes) {
|
||||||
|
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
||||||
|
|
||||||
|
if (ingredients.length > srecipe.getRecipeSize()) {
|
||||||
|
continue;
|
||||||
|
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIngredient:
|
||||||
|
for (IIngredient ingredient : ingredients) {
|
||||||
|
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||||
|
if (matches(srecipe.recipeItems.get(k), ingredient)) {
|
||||||
|
continue checkIngredient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||||
|
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
|
||||||
|
ArrayList<Object> inputs = srecipe.getInput();
|
||||||
|
|
||||||
|
if (inputs.size() < ingredients.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!wildcard && inputs.size() > ingredients.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIngredient:
|
||||||
|
for (IIngredient ingredient : ingredients) {
|
||||||
|
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||||
|
if (matches(inputs.get(k), ingredient)) {
|
||||||
|
continue checkIngredient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toRemove.add(recipe);
|
||||||
|
}
|
||||||
|
MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes.");
|
||||||
|
super.removeRecipes(toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
if(output != null) {
|
||||||
|
return "Removing Shapeless recipes for " + output.toString();
|
||||||
|
} else {
|
||||||
|
return "Trying to remove recipes for invalid output";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ActionRemoveShapedRecipes extends ActionBaseRemoveRecipes implements IUndoableAction {
|
||||||
|
final IIngredient output;
|
||||||
|
final IIngredient[][] ingredients;
|
||||||
|
|
||||||
|
|
||||||
|
public ActionRemoveShapedRecipes(IIngredient output, IIngredient[][] ingredients) {
|
||||||
|
this.output = output;
|
||||||
|
this.ingredients = ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() {
|
||||||
|
int ingredientsWidth = 0;
|
||||||
|
int ingredientsHeight = 0;
|
||||||
|
|
||||||
|
if (ingredients != null) {
|
||||||
|
ingredientsHeight = ingredients.length;
|
||||||
|
|
||||||
|
for (IIngredient[] ingredient : ingredients) {
|
||||||
|
ingredientsWidth = Math.max(ingredientsWidth, ingredient.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<IRecipe> toRemove = new HashSet<>();
|
||||||
|
|
||||||
|
outer:
|
||||||
|
for (final IRecipe recipe : recipes) {
|
||||||
|
final ItemStack output = recipe.getRecipeOutput();
|
||||||
|
if (output == null || !this.output.matches(new MCItemStack(output))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(recipe instanceof ShapedRecipes || recipe instanceof ShapedOreRecipe))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ingredients != null) {
|
||||||
|
boolean ore = recipe instanceof ShapedOreRecipe;
|
||||||
|
final ShapedRecipes shapedRecipe = !ore ? (ShapedRecipes) recipe : null;
|
||||||
|
final ShapedOreRecipe shapedOreRecipe = ore ? (ShapedOreRecipe) recipe : null;
|
||||||
|
|
||||||
|
final int recipeWidth = ore ? MineTweakerHacks.getShapedOreRecipeWidth(shapedOreRecipe) : shapedRecipe.recipeWidth;
|
||||||
|
final int recipeHeight = ore ? shapedOreRecipe.getRecipeSize() / recipeWidth : shapedRecipe.recipeHeight;
|
||||||
|
|
||||||
|
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < ingredientsHeight; j++) {
|
||||||
|
final IIngredient[] row = ingredients[j];
|
||||||
|
for (int k = 0; k < ingredientsWidth; k++) {
|
||||||
|
final IIngredient ingredient = k > row.length ? null : row[k];
|
||||||
|
final Object input = (ore ? shapedOreRecipe.getInput() : shapedRecipe.recipeItems)[j * recipeWidth + k];
|
||||||
|
|
||||||
|
if (!matches(input, ingredient)) {
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If null ingredient list given, remove all ShapedRecipes with the given output
|
||||||
|
toRemove.add(recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
MineTweakerAPI.logInfo(toRemove.size() + " removed");
|
||||||
|
super.removeRecipes(toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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;
|
||||||
|
|
||||||
|
private ActionBaseAddRecipe(ICraftingRecipe craftingRecipe, IItemStack output, boolean isShaped) {
|
||||||
|
this.iRecipe = RecipeConverter.convert(craftingRecipe);
|
||||||
|
this.craftingRecipe = craftingRecipe;
|
||||||
|
|
||||||
|
this.output = output;
|
||||||
|
this.isShaped = isShaped;
|
||||||
|
|
||||||
|
// if(craftingRecipe.hasTransformers())
|
||||||
|
// transformerRecipes.add(craftingRecipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() {
|
||||||
|
recipes.add(iRecipe);
|
||||||
|
if (craftingRecipe.hasTransformers())
|
||||||
|
transformerRecipes.add(craftingRecipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
if(output != null) {
|
||||||
|
return "Adding " + (isShaped ? "shaped" : "shapeless") + " recipe for " + output.getDisplayName();
|
||||||
|
} else {
|
||||||
|
return "Trying to add " + (isShaped ? "shaped" : "shapeless") + "recipe without correct output";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ActionAddShapedRecipe extends ActionBaseAddRecipe {
|
||||||
|
public ActionAddShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HandlePostReload implements IEventHandler<MineTweakerImplementationAPI.ReloadEvent>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(MineTweakerImplementationAPI.ReloadEvent event)
|
||||||
|
{
|
||||||
|
System.out.println("MineTweaker: Applying additions and removals");
|
||||||
|
MineTweakerAPI.apply(MCRecipeManager.actionRemoveRecipesNoIngredients);
|
||||||
|
MCRecipeManager.recipesToRemove.forEach(MineTweakerAPI::apply);
|
||||||
|
MCRecipeManager.recipesToAdd.forEach(MineTweakerAPI::apply);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ContainerVirtual extends Container {
|
private class ContainerVirtual extends Container {
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer var1) {
|
public boolean canInteractWith(EntityPlayer var1) {
|
||||||
@@ -302,118 +549,4 @@ public class MCRecipeManager implements IRecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ActionRemoveRecipes implements IUndoableAction {
|
|
||||||
private final List<Integer> removingIndices;
|
|
||||||
private final List<IRecipe> removingRecipes;
|
|
||||||
|
|
||||||
public ActionRemoveRecipes(List<IRecipe> recipes, List<Integer> indices) {
|
|
||||||
this.removingIndices = indices;
|
|
||||||
this.removingRecipes = recipes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
for (int i = removingIndices.size() - 1; i >= 0; i--) {
|
|
||||||
recipes.remove((int) removingIndices.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
for (int i = 0; i < removingIndices.size(); i++) {
|
|
||||||
int index = Math.min(recipes.size(), removingIndices.get(i));
|
|
||||||
recipes.add(index, removingRecipes.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Removing " + removingIndices.size() + " recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Restoring " + removingIndices.size() + " recipes";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActionAddRecipe implements IUndoableAction {
|
|
||||||
private final IRecipe recipe;
|
|
||||||
private final ICraftingRecipe craftingRecipe;
|
|
||||||
|
|
||||||
public ActionAddRecipe(IRecipe recipe, ICraftingRecipe craftingRecipe) {
|
|
||||||
this.recipe = recipe;
|
|
||||||
this.craftingRecipe = craftingRecipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply() {
|
|
||||||
recipes.add(recipe);
|
|
||||||
if (craftingRecipe.hasTransformers()) {
|
|
||||||
transformerRecipes.add(craftingRecipe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUndo() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undo() {
|
|
||||||
recipes.remove(recipe);
|
|
||||||
if (craftingRecipe.hasTransformers()) {
|
|
||||||
transformerRecipes.remove(craftingRecipe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describe() {
|
|
||||||
return "Adding recipe for " + recipe.getRecipeOutput().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String describeUndo() {
|
|
||||||
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getOverrideKey() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, action, mirrored);
|
|
||||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
|
||||||
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean matches(Object input, IIngredient ingredient) {
|
|
||||||
if ((input == null) != (ingredient == null)) {
|
|
||||||
return false;
|
|
||||||
} else if (ingredient != null) {
|
|
||||||
if (input instanceof ItemStack) {
|
|
||||||
if (!ingredient.matches(getIItemStack((ItemStack) input))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (input instanceof String) {
|
|
||||||
if (!ingredient.contains(getOreDict((String) input))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,12 @@ public class RecipeConverter {
|
|||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
public static IRecipe convert(ICraftingRecipe recipe) {
|
||||||
|
if (recipe instanceof ShapedRecipe)
|
||||||
|
return RecipeConverter.convert((ShapedRecipe)recipe);
|
||||||
|
else
|
||||||
|
return RecipeConverter.convert((ShapelessRecipe) recipe);
|
||||||
|
}
|
||||||
|
|
||||||
public static IRecipe convert(ShapelessRecipe recipe) {
|
public static IRecipe convert(ShapelessRecipe recipe) {
|
||||||
IIngredient[] ingredients = recipe.getIngredients();
|
IIngredient[] ingredients = recipe.getIngredients();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import javax.tools.ToolProvider
|
|||||||
// ### Global settings ###
|
// ### Global settings ###
|
||||||
// #######################
|
// #######################
|
||||||
|
|
||||||
ext.mineTweakerVersion = "3.2.0-GTNH"
|
ext.mineTweakerVersion = "3.2.1-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