Compare commits

...
Author SHA1 Message Date
kuba6000 8fcb36d394 Fix shaped recipe 2023-05-07 20:33:59 +02:00
kuba6000 f9db90268e Forgot about quotes 2023-05-07 20:17:11 +02:00
kuba6000 e7cd5e602d Fix error stacks 2023-05-07 20:15:22 +02:00
kuba6000 65e1f469ae Force normal parsing 2023-05-07 20:07:19 +02:00
kuba6000 7fe4150afc magic 2023-04-30 23:06:42 +02:00
8 changed files with 335 additions and 39 deletions

No files matched your search

+197 -22
View File
@@ -6,10 +6,20 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import org.apache.logging.log4j.LogManager;
import cpw.mods.fml.common.registry.GameRegistry;
import minetweaker.annotations.BracketHandler; import minetweaker.annotations.BracketHandler;
import minetweaker.annotations.ModOnly; import minetweaker.annotations.ModOnly;
import minetweaker.api.client.IClient; import minetweaker.api.client.IClient;
@@ -17,8 +27,13 @@ import minetweaker.api.compat.*;
import minetweaker.api.event.IEventManager; import minetweaker.api.event.IEventManager;
import minetweaker.api.formatting.IFormatter; import minetweaker.api.formatting.IFormatter;
import minetweaker.api.game.IGame; import minetweaker.api.game.IGame;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.item.IngredientItem;
import minetweaker.api.mods.ILoadedMods; import minetweaker.api.mods.ILoadedMods;
import minetweaker.api.oredict.IOreDict; import minetweaker.api.oredict.IOreDict;
import minetweaker.api.oredict.IOreDictEntry;
import minetweaker.api.oredict.IngredientOreDict;
import minetweaker.api.recipes.IFurnaceManager; import minetweaker.api.recipes.IFurnaceManager;
import minetweaker.api.recipes.IRecipeManager; import minetweaker.api.recipes.IRecipeManager;
import minetweaker.api.server.IServer; import minetweaker.api.server.IServer;
@@ -38,18 +53,178 @@ import stanhebben.zenscript.type.natives.JavaMethod;
/** /**
* Provides access to the MineTweaker API. * Provides access to the MineTweaker API.
* *
* An implementing platform needs to do the following: - Set a logger - Set the ore dictionary - Set the recipe manager * An implementing platform needs to do the following: - Set a logger - Set the ore dictionary - Set the recipe manager
* - Set the furnace manager - Set event manager - Set resource manager * - Set the furnace manager - Set event manager - Set resource manager
* *
* - Register additional global symbols to the GlobalRegistry (recipes, minetweaker, oreDict, logger, as well as the * - Register additional global symbols to the GlobalRegistry (recipes, minetweaker, oreDict, logger, as well as the
* official set of functions) - Register native classes using the GlobalRegistry - Register bracket handlers to resolve * official set of functions) - Register native classes using the GlobalRegistry - Register bracket handlers to resolve
* block/item/... references using the bracket syntax * block/item/... references using the bracket syntax
* *
* @author Stan Hebben * @author Stan Hebben
*/ */
public class MineTweakerAPI { public class MineTweakerAPI {
private static final org.apache.logging.log4j.Logger TRANSLATORLOGGER = LogManager
.getLogger("[SCRIPTS TO CODE TRANSLATOR]");
public static void info(String log) {
TRANSLATORLOGGER.info(log);
}
public static String convertStack(ItemStack stack) {
if (stack == null) return "null";
GameRegistry.UniqueIdentifier itemIdentifier = GameRegistry.findUniqueIdentifierFor(stack.getItem());
int meta = stack.getItemDamage();
int size = stack.stackSize;
NBTTagCompound tagCompound = stack.stackTagCompound;
if (tagCompound == null || tagCompound.hasNoTags()) {
return "getModItem(\"" + itemIdentifier.modId
+ "\", \""
+ itemIdentifier.name
+ "\", "
+ size
+ ", "
+ meta
+ ", missing)";
} else {
return "createItemStack(\"" + itemIdentifier.modId
+ "\", \""
+ itemIdentifier.name
+ "\", "
+ size
+ ", "
+ meta
+ ", "
+ "\""
+ tagCompound.toString().replace("\"", "\\\"")
+ "\""
+ ", missing)";
}
}
public static String convertStack(IIngredient ingredient) {
Object internal = ingredient.getInternal();
if (internal instanceof ItemStack) return convertStack((ItemStack) internal);
else return "ERRORSTACK";
}
public static String convertStackOrOre(IIngredient ingredient) {
Object internal = ingredient.getInternal();
if (internal instanceof ItemStack) return convertStack((ItemStack) internal);
else if (internal instanceof String) return "\"" + (String) internal + "\"";
else return "ERRORSTACK";
}
public static String convertArrayInLine(Object[] arr) {
StringBuilder arrayString = new StringBuilder();
for (int i = 0, arrLength = arr.length; i < arrLength; i++) {
Object o = arr[i];
if (o instanceof String) arrayString.append("\"").append((String) o).append("\"");
else if (o instanceof Character) arrayString.append("'").append((char) o).append("'");
else if (o instanceof ItemStack) arrayString.append(convertStack((ItemStack) o));
else if (o instanceof IItemStack || o instanceof IngredientItem)
arrayString.append(convertStack((IIngredient) o));
else if (o instanceof IOreDictEntry)
arrayString.append("\"").append((String) ((IOreDictEntry) o).getInternal()).append("\"");
else if (o instanceof IngredientOreDict)
arrayString.append("\"").append((String) ((IngredientOreDict) o).getInternal()).append("\"");
else if (o == null) arrayString.append("null");
else arrayString.append(o);
if (i + 1 < arrLength) arrayString.append(", ");
}
return arrayString.toString();
}
public static String convert2DArrayInLine(Object[][] arr) {
StringBuilder arrayString = new StringBuilder();
for (int i = 0, arrLength = arr.length; i < arrLength; i++) {
for (int j = 0, jarrLength = arr[i].length; j < jarrLength; j++) {
Object o = arr[i][j];
if (o instanceof String) arrayString.append("\"").append((String) o).append("\"");
else if (o instanceof Character) arrayString.append("'").append((char) o).append("'");
else if (o instanceof ItemStack) arrayString.append(convertStack((ItemStack) o));
else if (o instanceof IItemStack || o instanceof IngredientItem)
arrayString.append(convertStack((IIngredient) o));
else if (o instanceof IOreDictEntry)
arrayString.append("\"").append((String) ((IOreDictEntry) o).getInternal()).append("\"");
else if (o instanceof IngredientOreDict)
arrayString.append("\"").append((String) ((IngredientOreDict) o).getInternal()).append("\"");
else if (o == null) arrayString.append("null");
else arrayString.append(o);
if (i + 1 < arrLength || j + 1 < jarrLength) arrayString.append(", ");
}
}
return arrayString.toString();
}
public static void logGTRecipe(ItemStack[] itemInputs, ItemStack[] itemOutputs, int[] chances,
FluidStack[] fluidInputs, FluidStack[] fluidOutputs, int duration, int eut, Integer specialValue,
String recipeMapVariable) {
StringBuilder builder = new StringBuilder("GT_Values.RA.stdBuilder()");
Function<ItemStack[], ItemStack[]> isAllObjectsNullItemStack = arr -> {
if (arr == null || arr.length == 0 || Arrays.stream(arr).allMatch(Objects::isNull)) return null;
return Arrays.stream(arr).filter(Objects::nonNull).toArray(ItemStack[]::new);
};
Function<FluidStack[], FluidStack[]> isAllObjectsNullFluidStack = arr -> {
if (arr == null || arr.length == 0 || Arrays.stream(arr).allMatch(Objects::isNull)) return null;
return Arrays.stream(arr).filter(Objects::nonNull).toArray(FluidStack[]::new);
};
itemInputs = isAllObjectsNullItemStack.apply(itemInputs);
itemOutputs = isAllObjectsNullItemStack.apply(itemOutputs);
fluidInputs = isAllObjectsNullFluidStack.apply(fluidInputs);
fluidOutputs = isAllObjectsNullFluidStack.apply(fluidOutputs);
if (itemInputs == null || itemInputs.length == 0) builder.append(".noItemInputs()");
else builder.append(".itemInputs(").append(convertArrayInLine(itemInputs)).append(")");
if (itemOutputs == null || itemOutputs.length == 0) builder.append(".noItemOutputs()");
else builder.append(".itemOutputs(").append(convertArrayInLine(itemOutputs)).append(")");
if (chances != null && chances.length > 0) builder.append(".outputChances(")
.append(convertArrayInLine(Arrays.stream(chances).boxed().toArray(Integer[]::new))).append(")");
if (fluidInputs == null || fluidInputs.length == 0) builder.append(".noFluidInputs()");
else builder.append(".fluidInputs(").append(convertArrayInLine(fluidInputs)).append(")");
if (fluidOutputs == null || fluidOutputs.length == 0) builder.append(".noFluidOutputs()");
else builder.append(".fluidOutputs(").append(convertArrayInLine(fluidOutputs)).append(")");
builder.append(".duration(").append(duration).append(")");
builder.append(".eut(").append(eut).append(")");
if (specialValue != null) builder.append(".specialValue(").append(specialValue.intValue()).append(")");
builder.append(".addTo(").append(recipeMapVariable).append(");");
info(builder.toString());
}
public static void logGTRecipe(ItemStack[] itemInputs, ItemStack[] itemOutputs, FluidStack[] fluidInputs,
FluidStack[] fluidOutputs, int duration, int eut, String recipeMapVariable) {
logGTRecipe(itemInputs, itemOutputs, null, fluidInputs, fluidOutputs, duration, eut, null, recipeMapVariable);
}
public static void logGTRecipe(ItemStack[] itemInputs, ItemStack[] itemOutputs, int[] chances,
FluidStack[] fluidInputs, FluidStack[] fluidOutputs, int duration, int eut, String recipeMapVariable) {
logGTRecipe(
itemInputs,
itemOutputs,
chances,
fluidInputs,
fluidOutputs,
duration,
eut,
null,
recipeMapVariable);
}
public static void logGTRecipe(ItemStack[] itemInputs, ItemStack[] itemOutputs, FluidStack[] fluidInputs,
FluidStack[] fluidOutputs, int duration, int eut, int specialValue, String recipeMapVariable) {
logGTRecipe(
itemInputs,
itemOutputs,
null,
fluidInputs,
fluidOutputs,
duration,
eut,
specialValue,
recipeMapVariable);
}
public static final String[] COLOR_NAMES = { "White", "Orange", "Magenta", "Light Blue", "Yellow", "Lime", "Pink", public static final String[] COLOR_NAMES = { "White", "Orange", "Magenta", "Light Blue", "Yellow", "Lime", "Pink",
"Gray", "Light Gray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black" }; "Gray", "Light Gray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black" };
private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry(); private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry();
@@ -85,7 +260,7 @@ public class MineTweakerAPI {
/** /**
* The logger can be used to write logging messages to the client. Error and warning messages should be relayed to * The logger can be used to write logging messages to the client. Error and warning messages should be relayed to
* admins for further handling. * admins for further handling.
* *
* @return * @return
*/ */
public static final ILogger getLogger() { public static final ILogger getLogger() {
@@ -149,7 +324,7 @@ public class MineTweakerAPI {
/** /**
* Applies this given action. * Applies this given action.
* *
* @param action action object * @param action action object
*/ */
public static void apply(IUndoableAction action) { public static void apply(IUndoableAction action) {
@@ -158,7 +333,7 @@ public class MineTweakerAPI {
/** /**
* Logs a command message. Commands messages are those generated as output in response to a command. * Logs a command message. Commands messages are those generated as output in response to a command.
* *
* @param message command message * @param message command message
*/ */
public static void logCommand(String message) { public static void logCommand(String message) {
@@ -168,7 +343,7 @@ public class MineTweakerAPI {
/** /**
* Logs an info message. Info messages have low priority and will only be displayed in the log files, but not * Logs an info message. Info messages have low priority and will only be displayed in the log files, but not
* directly to players in-game. * directly to players in-game.
* *
* @param message info message * @param message info message
*/ */
public static void logInfo(String message) { public static void logInfo(String message) {
@@ -179,7 +354,7 @@ public class MineTweakerAPI {
* Logs a warning message. Warning messages are displayed to admins and indicate that there is an issue. However, * Logs a warning message. Warning messages are displayed to admins and indicate that there is an issue. However,
* the issue is not a large problem, and everything should run fine - besides perhaps a few things not entirely * the issue is not a large problem, and everything should run fine - besides perhaps a few things not entirely
* working as expected. * working as expected.
* *
* @param message warning message * @param message warning message
*/ */
public static void logWarning(String message) { public static void logWarning(String message) {
@@ -190,7 +365,7 @@ public class MineTweakerAPI {
* Logs an error message. Error messages indicate a real problem and indicate that things won't run properly. The * Logs an error message. Error messages indicate a real problem and indicate that things won't run properly. The
* scripting system will still make a best-effort attempt at executing the rest of the scripts, but that might cause * scripting system will still make a best-effort attempt at executing the rest of the scripts, but that might cause
* additional errors and issues. * additional errors and issues.
* *
* @param message error message * @param message error message
*/ */
public static void logError(String message) { public static void logError(String message) {
@@ -201,7 +376,7 @@ public class MineTweakerAPI {
* Logs an error message. Error messages indicate a real problem and indicate that things won't run properly. The * Logs an error message. Error messages indicate a real problem and indicate that things won't run properly. The
* scripting system will still make a best-effort attempt at executing the rest of the scripts, but that might cause * scripting system will still make a best-effort attempt at executing the rest of the scripts, but that might cause
* additional errors and issues. * additional errors and issues.
* *
* @param message error message * @param message error message
* @param exception exception that was caught related to the error * @param exception exception that was caught related to the error
*/ */
@@ -216,7 +391,7 @@ public class MineTweakerAPI {
/** /**
* Register a class registry class. Such class must have (at least) a public static method called "getClasses" with * Register a class registry class. Such class must have (at least) a public static method called "getClasses" with
* accepts a List of classes and which stores its classes into that list. * accepts a List of classes and which stores its classes into that list.
* *
* @param registryClass * @param registryClass
*/ */
public static void registerClassRegistry(Class registryClass) { public static void registerClassRegistry(Class registryClass) {
@@ -226,7 +401,7 @@ public class MineTweakerAPI {
/** /**
* Register a class registry class. Such class must have (at least) a public static method called "getClasses" with * Register a class registry class. Such class must have (at least) a public static method called "getClasses" with
* accepts a List of classes and which stores its classes into that list. * accepts a List of classes and which stores its classes into that list.
* *
* @param registryClass * @param registryClass
* @param description * @param description
*/ */
@@ -270,7 +445,7 @@ public class MineTweakerAPI {
/** /**
* Registers a class registry. Will attempt to resolve the given class name. Does nothing if the class could not be * Registers a class registry. Will attempt to resolve the given class name. Does nothing if the class could not be
* loaded. * loaded.
* *
* @param className class name to be loaded * @param className class name to be loaded
* @return true if registration was successful * @return true if registration was successful
*/ */
@@ -281,7 +456,7 @@ public class MineTweakerAPI {
/** /**
* Registers a class registry. Will attempt to resolve the given class name. Does nothing if the class could not be * Registers a class registry. Will attempt to resolve the given class name. Does nothing if the class could not be
* loaded. * loaded.
* *
* @param className class name to be loaded * @param className class name to be loaded
* @param description * @param description
* @return true if registration was successful * @return true if registration was successful
@@ -298,7 +473,7 @@ public class MineTweakerAPI {
/** /**
* Registers an annotated class. A class is annotated with either @ZenClass or @ZenExpansion. Classes not annotated * Registers an annotated class. A class is annotated with either @ZenClass or @ZenExpansion. Classes not annotated
* with either of these will be ignored. * with either of these will be ignored.
* *
* @param annotatedClass * @param annotatedClass
*/ */
public static void registerClass(Class annotatedClass) { public static void registerClass(Class annotatedClass) {
@@ -327,7 +502,7 @@ public class MineTweakerAPI {
/** /**
* Registers a global symbol. Global symbols are immediately accessible from anywhere in the scripts. * Registers a global symbol. Global symbols are immediately accessible from anywhere in the scripts.
* *
* @param name symbol name * @param name symbol name
* @param symbol symbol * @param symbol symbol
*/ */
@@ -337,7 +512,7 @@ public class MineTweakerAPI {
/** /**
* Registers a recipe remover. Removers are called when the global minetweaker.remove() function is called. * Registers a recipe remover. Removers are called when the global minetweaker.remove() function is called.
* *
* @param remover recipe remover * @param remover recipe remover
*/ */
public static void registerRemover(IRecipeRemover remover) { public static void registerRemover(IRecipeRemover remover) {
@@ -347,7 +522,7 @@ public class MineTweakerAPI {
/** /**
* Registers a bracket handler. Is capable of converting the bracket syntax to an actual value. This new handler * Registers a bracket handler. Is capable of converting the bracket syntax to an actual value. This new handler
* will be added last - it can thus not intercept values that are already handled by the system. * will be added last - it can thus not intercept values that are already handled by the system.
* *
* @param handler bracket handler to be added * @param handler bracket handler to be added
*/ */
public static void registerBracketHandler(IBracketHandler handler) { public static void registerBracketHandler(IBracketHandler handler) {
@@ -356,7 +531,7 @@ public class MineTweakerAPI {
/** /**
* Creates a symbol that refers to a java method. * Creates a symbol that refers to a java method.
* *
* @param cls class that contains the method * @param cls class that contains the method
* @param name method name * @param name method name
* @param arguments method argument types * @param arguments method argument types
@@ -370,7 +545,7 @@ public class MineTweakerAPI {
/** /**
* Creates a symbol that refers to a java getter. The getter must be a method with no arguments. The given symbol * Creates a symbol that refers to a java getter. The getter must be a method with no arguments. The given symbol
* will act as a variable of which the value can be retrieved but not set. * will act as a variable of which the value can be retrieved but not set.
* *
* @param cls class that contains the getter method * @param cls class that contains the getter method
* @param name name of the method * @param name name of the method
* @return corresponding symbol * @return corresponding symbol
@@ -383,7 +558,7 @@ public class MineTweakerAPI {
/** /**
* Creates a symbol that refers to a static field. The field must be an existing public field in the given class. * Creates a symbol that refers to a static field. The field must be an existing public field in the given class.
* The field will act as a variable that can be retrieved but not set. * The field will act as a variable that can be retrieved but not set.
* *
* @param cls class that contains the field * @param cls class that contains the field
* @param name field name (must be public) * @param name field name (must be public)
* @return corresponding symbol * @return corresponding symbol
@@ -401,7 +576,7 @@ public class MineTweakerAPI {
/** /**
* Loads a Java method from an existing class. * Loads a Java method from an existing class.
* *
* @param cls method class * @param cls method class
* @param name method name * @param name method name
* @param arguments argument types * @param arguments argument types
@@ -112,6 +112,7 @@ public class MCFurnaceManager implements IFurnaceManager {
public void apply() { public void apply() {
for (ItemStack item : items) { for (ItemStack item : items) {
FurnaceRecipes.smelting().getSmeltingList().remove(item); FurnaceRecipes.smelting().getSmeltingList().remove(item);
MineTweakerAPI.info("GT_ModHandler.removeFurnaceSmelting(" + MineTweakerAPI.convertStack(item) + ");");
} }
} }
@@ -161,6 +162,11 @@ public class MCFurnaceManager implements IFurnaceManager {
public void apply() { public void apply() {
for (ItemStack inputStack : input) { for (ItemStack inputStack : input) {
FurnaceRecipes.smelting().func_151394_a(inputStack, output, (float) xp); FurnaceRecipes.smelting().func_151394_a(inputStack, output, (float) xp);
MineTweakerAPI.info(
"GT_ModHandler.addSmeltingRecipe(" + MineTweakerAPI.convertStack(inputStack)
+ ", "
+ MineTweakerAPI.convertStack(output)
+ ");");
} }
} }
@@ -203,6 +209,11 @@ public class MCFurnaceManager implements IFurnaceManager {
@Override @Override
public void apply() { public void apply() {
FuelTweaker.INSTANCE.addFuelPattern(pattern); FuelTweaker.INSTANCE.addFuelPattern(pattern);
MineTweakerAPI.info(
"GT_ModHandler.setFuelValue(" + MineTweakerAPI.convertStack(pattern.getPattern())
+ ", "
+ pattern.getValue()
+ ");");
} }
@Override @Override
@@ -182,7 +182,7 @@ public class MCGame implements IGame {
/** /**
* Ported from ModTweaker. * Ported from ModTweaker.
* *
* @author Joshiejack * @author Joshiejack
*/ */
private static class SetTranslation implements IUndoableAction { private static class SetTranslation implements IUndoableAction {
@@ -208,6 +208,7 @@ public class MCGame implements IGame {
} else { } else {
added = false; added = false;
} }
MineTweakerAPI.info(key + "=" + text);
} }
@Override @Override
@@ -271,6 +271,11 @@ public class MCOreDictEntry implements IOreDictEntry {
@Override @Override
public void apply() { public void apply() {
OreDictionary.registerOre(id, item); OreDictionary.registerOre(id, item);
MineTweakerAPI.info(
"OreDictionary.registerOre(\"" + OreDictionary.getOreName(id)
+ "\", "
+ MineTweakerAPI.convertStack(item)
+ ");");
} }
@Override @Override
@@ -316,6 +316,17 @@ public final class MCRecipeManager implements IRecipeManager {
toRemove = find(); toRemove = find();
removeRecipes(toRemove); removeRecipes(toRemove);
for (Pair<IIngredient, Boolean> output : outputs) {
if (output.getKey().getInternal() instanceof String) MineTweakerAPI
.info("removeRecipeByOreOutputDelayed(\"" + ((String) output.getKey().getInternal()) + "\")");
else MineTweakerAPI.info(
"GT_ModHandler.removeRecipeByOutputDelayed(" + MineTweakerAPI.convertStack(output.getKey())
+ ", "
+ (output.getValue() ? "false" : "true")
+ ", false, true);");
}
} }
@Override @Override
@@ -440,6 +451,14 @@ public final class MCRecipeManager implements IRecipeManager {
toRemove = find(); toRemove = find();
MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes."); MineTweakerAPI.logInfo("Removing " + toRemove.size() + " Shapeless recipes.");
super.removeRecipes(toRemove); super.removeRecipes(toRemove);
if (ingredients == null || ingredients.length == 0)
MineTweakerAPI.info("removeRecipeShapeless(" + MineTweakerAPI.convertStackOrOre(output) + ");");
else MineTweakerAPI.info(
"removeRecipeShapeless(" + MineTweakerAPI.convertStackOrOre(output)
+ ", "
+ MineTweakerAPI.convertArrayInLine(ingredients)
+ ");");
} }
@Override @Override
@@ -554,6 +573,21 @@ public final class MCRecipeManager implements IRecipeManager {
MineTweakerAPI.logInfo(toRemove.size() + " removed"); MineTweakerAPI.logInfo(toRemove.size() + " removed");
super.removeRecipes(toRemove); super.removeRecipes(toRemove);
if (ingredients == null || ingredients.length == 0)
MineTweakerAPI.info("removeRecipeShaped(" + MineTweakerAPI.convertStackOrOre(output) + ");");
else MineTweakerAPI.info(
"removeRecipeShaped(" + MineTweakerAPI.convertStackOrOre(output)
+ ", new Object[]{"
+ MineTweakerAPI.convertArrayInLine(ingredients[0])
+ "}"
+ (ingredients.length >= 2
? (", new Object[]{" + MineTweakerAPI.convertArrayInLine(ingredients[1]) + "}")
: ", new Object[0]")
+ (ingredients.length >= 3
? (", new Object[]{" + MineTweakerAPI.convertArrayInLine(ingredients[2]) + "}")
: ", new Object[0]")
+ ");");
} }
@Override @Override
@@ -658,17 +692,50 @@ public final class MCRecipeManager implements IRecipeManager {
private static class ActionAddShapedRecipe extends ActionBaseAddRecipe { private static class ActionAddShapedRecipe extends ActionBaseAddRecipe {
IItemStack aOutput;
IIngredient[][] aIngredients;
boolean aMirrored;
public ActionAddShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, public ActionAddShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function,
IRecipeAction action, boolean mirrored) { IRecipeAction action, boolean mirrored) {
super(new ShapedRecipe(output, ingredients, function, action, mirrored), output, true); super(new ShapedRecipe(output, ingredients, function, action, mirrored), output, true);
aOutput = output;
aIngredients = ingredients;
aMirrored = mirrored;
}
@Override
public void apply() {
super.apply();
MineTweakerAPI.info(
"addShapedRecipe(" + MineTweakerAPI.convertStack(aOutput)
+ ", new Object[] {"
+ MineTweakerAPI.convert2DArrayInLine(aIngredients)
+ "});");
} }
} }
private static class ActionAddShapelessRecipe extends ActionBaseAddRecipe { private static class ActionAddShapelessRecipe extends ActionBaseAddRecipe {
IItemStack aOutput;
IIngredient[] aIngredients;
public ActionAddShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, public ActionAddShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function,
IRecipeAction action) { IRecipeAction action) {
super(new ShapelessRecipe(output, ingredients, function, action), output, false); super(new ShapelessRecipe(output, ingredients, function, action), output, false);
aOutput = output;
aIngredients = ingredients;
}
@Override
public void apply() {
super.apply();
MineTweakerAPI.info(
"addShapelessCraftingRecipe(" + MineTweakerAPI.convertStack(aOutput)
+ ", new Object[] { "
+ MineTweakerAPI.convertArrayInLine(aIngredients)
+ " });");
} }
} }
@@ -719,7 +786,7 @@ public final class MCRecipeManager implements IRecipeManager {
recipes.removeIf(recipesToUndo::contains); recipes.removeIf(recipesToUndo::contains);
} }
int commonPoolParallelism = getCommonPoolParallelism(); int commonPoolParallelism = getCommonPoolParallelism();
if (commonPoolParallelism <= 1) { if (true) {
// if thread == 1, then we have parallel overhead but doesn't have parallel speedup. // if thread == 1, then we have parallel overhead but doesn't have parallel speedup.
// never do this // never do this
recipesToRemove.forEach(ActionBaseRemoveRecipes::apply); recipesToRemove.forEach(ActionBaseRemoveRecipes::apply);
@@ -4,6 +4,8 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
import net.minecraft.item.ItemStack;
import ic2.api.recipe.RecipeOutput; import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes; import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI; import minetweaker.MineTweakerAPI;
@@ -18,7 +20,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
/** /**
* Provides access to the IC2 compressor recipes. Recipes can be added but not removed, due to IC2 API restrictions. * Provides access to the IC2 compressor recipes. Recipes can be added but not removed, due to IC2 API restrictions.
* *
* @author Stan Hebben * @author Stan Hebben
*/ */
@ZenClass("mods.ic2.Compressor") @ZenClass("mods.ic2.Compressor")
@@ -27,9 +29,9 @@ public class Compressor {
/** /**
* Adds a new recipe to the compressor. * Adds a new recipe to the compressor.
* *
* The recipe input can be any pattern, as long as the stack size is determined. The output can be any item stack. * The recipe input can be any pattern, as long as the stack size is determined. The output can be any item stack.
* *
* @param output recipe output * @param output recipe output
* @param ingredient recipe input * @param ingredient recipe input
*/ */
@@ -44,14 +46,29 @@ public class Compressor {
Recipes.compressor, Recipes.compressor,
getItemStacks(output), getItemStacks(output),
null, null,
new IC2RecipeInput(ingredient))); new IC2RecipeInput(ingredient)) {
@Override
public void apply() {
super.apply();
MineTweakerAPI.logGTRecipe(
new ItemStack[] { new IC2RecipeInput(ingredient).getInputs().get(0) },
new ItemStack[] { getItemStack(output) },
null,
null,
300,
2,
"sCompressorRecipes");
}
});
} }
} }
/** /**
* Determines the recipe output for the given input. Will return the output of a single item, even if the stack * Determines the recipe output for the given input. Will return the output of a single item, even if the stack
* contains multiple items. * contains multiple items.
* *
* @param input recipe input * @param input recipe input
* @return recipe output * @return recipe output
*/ */
@@ -9,6 +9,8 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
import net.minecraft.item.ItemStack;
import ic2.api.recipe.RecipeOutput; import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes; import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI; import minetweaker.MineTweakerAPI;
@@ -23,7 +25,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
/** /**
* Provides access to the IC2 Extractor recipes. * Provides access to the IC2 Extractor recipes.
* *
* @author Stan Hebben * @author Stan Hebben
*/ */
@ZenClass("mods.ic2.Extractor") @ZenClass("mods.ic2.Extractor")
@@ -32,9 +34,9 @@ public class Extractor {
/** /**
* Adds a new recipe to the extractor. * Adds a new recipe to the extractor.
* *
* The recipe input can be any pattern, as long as the stack size is determined. The output can be any item stack. * The recipe input can be any pattern, as long as the stack size is determined. The output can be any item stack.
* *
* @param output recipe output * @param output recipe output
* @param ingredient recipe input * @param ingredient recipe input
*/ */
@@ -49,14 +51,29 @@ public class Extractor {
Recipes.extractor, Recipes.extractor,
getItemStacks(output), getItemStacks(output),
null, null,
new IC2RecipeInput(ingredient))); new IC2RecipeInput(ingredient)) {
@Override
public void apply() {
super.apply();
MineTweakerAPI.logGTRecipe(
new ItemStack[] { new IC2RecipeInput(ingredient).getInputs().get(0) },
new ItemStack[] { getItemStack(output) },
null,
null,
300,
2,
"sExtractorRecipes");
}
});
} }
} }
/** /**
* Determines the recipe output for the given input. Will return the output of a single item, even if the stack * Determines the recipe output for the given input. Will return the output of a single item, even if the stack
* contains multiple items. * contains multiple items.
* *
* @param input recipe input * @param input recipe input
* @return recipe output * @return recipe output
*/ */
+8 -5
View File
@@ -16,11 +16,11 @@ import stanhebben.zenscript.annotations.ZenMethod;
/** /**
* MineTweaker NEI support. * MineTweaker NEI support.
* *
* Enables hiding NEI items as well as adding new item stacks. These item stacks can then show a custom message or * Enables hiding NEI items as well as adding new item stacks. These item stacks can then show a custom message or
* contain NBT data. Can be used to show a custom message or lore with certain items, or to provide spawnable items with * contain NBT data. Can be used to show a custom message or lore with certain items, or to provide spawnable items with
* specific NBT tags. * specific NBT tags.
* *
* @author Stan Hebben * @author Stan Hebben
*/ */
@ZenClass("mods.nei.NEI") @ZenClass("mods.nei.NEI")
@@ -29,7 +29,7 @@ public class NEI {
/** /**
* Hides a specific item in NEI. Will take into account metadata values, if any. * Hides a specific item in NEI. Will take into account metadata values, if any.
* *
* @param item item to be hidden * @param item item to be hidden
*/ */
@ZenMethod @ZenMethod
@@ -39,7 +39,7 @@ public class NEI {
/** /**
* Adds a NEI entry. The item stack can contain damage values and NBT tags. * Adds a NEI entry. The item stack can contain damage values and NBT tags.
* *
* @param stack item stack to be added * @param stack item stack to be added
*/ */
@ZenMethod @ZenMethod
@@ -50,7 +50,7 @@ public class NEI {
/** /**
* Overrides a name in NEI. Note that this will not change the original display name, but it will change the way it * Overrides a name in NEI. Note that this will not change the original display name, but it will change the way it
* is displayed in NEI. * is displayed in NEI.
* *
* @param item item * @param item item
* @param name item name * @param name item name
*/ */
@@ -74,6 +74,7 @@ public class NEI {
@Override @Override
public void apply() { public void apply() {
API.addItemListEntry(item); API.addItemListEntry(item);
MineTweakerAPI.info("API.addItemListEntry(" + MineTweakerAPI.convertStack(item) + ");");
} }
@Override @Override
@@ -113,6 +114,7 @@ public class NEI {
@Override @Override
public void apply() { public void apply() {
API.hideItem(stack); API.hideItem(stack);
MineTweakerAPI.info("API.hideItem(" + MineTweakerAPI.convertStack(stack) + ");");
} }
@Override @Override
@@ -154,6 +156,7 @@ public class NEI {
@Override @Override
public void apply() { public void apply() {
API.setOverrideName(item, name); API.setOverrideName(item, name);
MineTweakerAPI.info("API.setOverrideName(" + MineTweakerAPI.convertStack(item) + ", \"" + name + "\");");
} }
@Override @Override