mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-26 23:03:12 +00:00
- Continued writing on the IC2 integration code
- Implemented advanced recipes on <*> values - Removed unused ZenScript classes - Continued work on any values - Moved documentation generation to buildSrc - Started work on a jar merging task - Added toString implementation to ingredients - Added stack count to ICraftingInventory - Fixed imports - Added logCommand to the logger to log command output - Implemented memory script provider to load scripts received from the server - Added exception handling for script execution - First attempt at creating a transformer to generate a list of ZenClass and ZenExpansion classes - Added console commands (reload, names, liquids, inventory, hand, oredict) - Added general logic - Fixed item ingredients for wildcard sizes - Implemented selective recipe removal - Fixed null recipe results - Started implementation of player-specific recipes - Removed redundant IC2 mod copy - Other minor fixes
This commit is contained in:
1 parent
f3ea7f7831
commit
489347558f
124 files changed
+3942
-419
No files matched your search
@@ -18,7 +18,21 @@ import java.util.logging.Logger;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.IRecipeRemover;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import minetweaker.minecraft.item.Condition;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.item.IItemCondition;
|
||||
import minetweaker.minecraft.item.IItemDefinition;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import minetweaker.minecraft.item.IItemTransformer;
|
||||
import minetweaker.minecraft.item.Transform;
|
||||
import minetweaker.minecraft.liquid.ILiquidDefinition;
|
||||
import minetweaker.minecraft.liquid.ILiquidStack;
|
||||
import minetweaker.minecraft.oredict.IOreDict;
|
||||
import minetweaker.minecraft.oredict.IOreDictEntry;
|
||||
import minetweaker.minecraft.recipes.ICraftingInventory;
|
||||
import minetweaker.minecraft.recipes.IFurnaceManager;
|
||||
import minetweaker.minecraft.recipes.IRecipeFunction;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
@@ -27,11 +41,12 @@ import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
|
||||
import stanhebben.zenscript.symbols.SymbolPackage;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeNative;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
@@ -46,7 +61,7 @@ public class GlobalRegistry {
|
||||
private static final List<IRecipeRemover> removers = new ArrayList<IRecipeRemover>();
|
||||
private static final List<IBracketHandler> bracketHandlers = new ArrayList<IBracketHandler>();
|
||||
private static final TypeRegistry types = new TypeRegistry();
|
||||
private static final SymbolPackage root = new SymbolPackage();
|
||||
private static final SymbolPackage root = new SymbolPackage("<root>");
|
||||
private static final IZenErrorLogger errors = new MyErrorLogger();
|
||||
private static final IZenCompileEnvironment environment = new MyCompileEnvironment();
|
||||
private static final Map<String, TypeExpansion> expansions = new HashMap<String, TypeExpansion>();
|
||||
@@ -73,7 +88,7 @@ public class GlobalRegistry {
|
||||
registerExpansion(ExpandShort.class);
|
||||
registerExpansion(ExpandString.class);*/
|
||||
|
||||
/*registerNativeClass(IData.class);
|
||||
registerNativeClass(IData.class);
|
||||
|
||||
registerNativeClass(IIngredient.class);
|
||||
registerNativeClass(IItemCondition.class);
|
||||
@@ -91,7 +106,7 @@ public class GlobalRegistry {
|
||||
|
||||
registerNativeClass(ICraftingInventory.class);
|
||||
registerNativeClass(IFurnaceManager.class);
|
||||
registerNativeClass(IRecipeFunction.class);*/
|
||||
registerNativeClass(IRecipeFunction.class);
|
||||
}
|
||||
|
||||
private GlobalRegistry() {}
|
||||
@@ -126,7 +141,7 @@ public class GlobalRegistry {
|
||||
ZenTypeNative type = new ZenTypeNative(cls);
|
||||
type.complete(types);
|
||||
|
||||
root.put(type.getName(), root, errors);
|
||||
root.put(type.getName(), new SymbolType(type), errors);
|
||||
}
|
||||
|
||||
public static TypeRegistry getTypeRegistry() {
|
||||
@@ -285,12 +300,12 @@ public class GlobalRegistry {
|
||||
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logError("[" + position.getFile() + ":" + position.getLine() + "] Error: " + message);
|
||||
MineTweakerAPI.logger.logError(position.toString() + " > " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logWarning("[" + position.getFile() + ":" + position.getLine() + "] Warning: " + message);
|
||||
MineTweakerAPI.logger.logWarning(position.toString() + " > " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
* @author Stan
|
||||
*/
|
||||
public interface ILogger {
|
||||
@ZenMethod
|
||||
public void logCommand(String message);
|
||||
|
||||
@ZenMethod
|
||||
public void logInfo(String message);
|
||||
|
||||
|
||||
@@ -45,12 +45,22 @@ public interface IMineTweaker {
|
||||
public List<IUndoableAction> rollback();
|
||||
|
||||
/**
|
||||
* Registers a script provider.
|
||||
* Sets the script provider.
|
||||
*
|
||||
* @param provider
|
||||
* @return
|
||||
*/
|
||||
public Closeable registerScriptProvider(IScriptProvider provider);
|
||||
public void setScriptProvider(IScriptProvider provider);
|
||||
|
||||
/**
|
||||
* Executes all scripts provided by the script provider.
|
||||
*/
|
||||
public void load();
|
||||
|
||||
/**
|
||||
* Retrieves the data from the scripts that were loaded last.
|
||||
*
|
||||
* @return scripts data
|
||||
*/
|
||||
public byte[] getScriptData();
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
package minetweaker.runtime;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
@@ -21,13 +20,14 @@ import java.util.Set;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.util.CloseablePriorityList;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
import stanhebben.zenscript.ZenModule;
|
||||
import static stanhebben.zenscript.ZenModule.compileScripts;
|
||||
import static stanhebben.zenscript.ZenModule.extractClassName;
|
||||
import stanhebben.zenscript.ZenParsedFile;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.parser.ParseException;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -35,14 +35,17 @@ import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class Tweaker implements IMineTweaker {
|
||||
private final CloseablePriorityList<IScriptProvider> scriptProviders = new CloseablePriorityList<IScriptProvider>();
|
||||
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
|
||||
private final Set<IUndoableAction> wereStuck = new HashSet<IUndoableAction>();
|
||||
|
||||
private IScriptProvider scriptProvider;
|
||||
private byte[] scriptData;
|
||||
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logger.logInfo(action.describe());
|
||||
action.apply();
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,49 +71,65 @@ public class Tweaker implements IMineTweaker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Closeable registerScriptProvider(IScriptProvider provider) {
|
||||
return scriptProviders.add(provider);
|
||||
public void setScriptProvider(IScriptProvider provider) {
|
||||
scriptProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||
Set<String> executed = new HashSet<String>();
|
||||
|
||||
for (IScriptProvider provider : scriptProviders) {
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
|
||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
||||
|
||||
while (script.next()) {
|
||||
try {
|
||||
String filename = script.getName();
|
||||
|
||||
String className = extractClassName(filename);
|
||||
|
||||
Reader reader = new InputStreamReader(new BufferedInputStream(script.open()));
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment());
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
}
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
|
||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
||||
|
||||
while (script.next()) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new InputStreamReader(new BufferedInputStream(script.open()));
|
||||
|
||||
String filename = script.getName();
|
||||
String className = extractClassName(filename);
|
||||
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment());
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
} catch (ParseException ex) {
|
||||
MineTweakerAPI.logger.logError("Error parsing " + ex.getFile() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error loading " + script.getName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String filename = script.getGroupName();
|
||||
System.out.println("MineTweaker: Loading " + filename);
|
||||
compileScripts(filename, files, environmentGlobal);
|
||||
|
||||
|
||||
// execute scripts
|
||||
ZenModule module = new ZenModule(classes);
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,4 +141,9 @@ public class Tweaker implements IMineTweaker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getScriptData() {
|
||||
return scriptData;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.runtime.providers;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import minetweaker.runtime.IScriptIterator;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class ScriptProviderCascade implements IScriptProvider {
|
||||
private final IScriptProvider[] providers;
|
||||
|
||||
public ScriptProviderCascade(IScriptProvider... providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IScriptIterator> getScripts() {
|
||||
return new MyScripterator();
|
||||
}
|
||||
|
||||
private class MyScripterator implements Iterator<IScriptIterator> {
|
||||
private final Set<String> executed = new HashSet<String>();
|
||||
|
||||
private int currentIndex = providers.length - 1;
|
||||
private Iterator<IScriptIterator> current;
|
||||
private IScriptIterator currentValue;
|
||||
|
||||
public MyScripterator() {
|
||||
currentIndex = providers.length - 1;
|
||||
current = providers[currentIndex].getScripts();
|
||||
|
||||
advance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptIterator next() {
|
||||
IScriptIterator result = currentValue;
|
||||
executed.add(result.getGroupName());
|
||||
|
||||
advance();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void advance() {
|
||||
do {
|
||||
while (!current.hasNext()) {
|
||||
currentIndex--;
|
||||
if (currentIndex < 0) return;
|
||||
|
||||
current = providers[currentIndex].getScripts();
|
||||
}
|
||||
if (currentIndex < 0) break;
|
||||
|
||||
currentValue = current.next();
|
||||
} while (executed.contains(currentValue.getGroupName()) && hasNext());
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-20
@@ -31,33 +31,31 @@ import minetweaker.runtime.IScriptProvider;
|
||||
* @author Stan
|
||||
*/
|
||||
public class ScriptProviderMemory implements IScriptProvider {
|
||||
public static byte[] collect(Iterable<IScriptProvider> providers) {
|
||||
public static byte[] collect(IScriptProvider provider) {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try {
|
||||
DeflaterOutputStream deflater = new DeflaterOutputStream(output);
|
||||
DataOutputStream deflaterData = new DataOutputStream(deflater);
|
||||
Set<String> executed = new HashSet<String>();
|
||||
|
||||
for (IScriptProvider provider : providers) {
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
deflaterData.writeUTF(script.getGroupName());
|
||||
|
||||
while (script.next()) {
|
||||
String name = script.getName();
|
||||
byte[] data = FileUtil.read(script.open());
|
||||
deflaterData.writeUTF(name);
|
||||
deflaterData.writeInt(data.length);
|
||||
deflaterData.write(data);
|
||||
}
|
||||
|
||||
deflaterData.writeUTF("");
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
deflaterData.writeUTF(script.getGroupName());
|
||||
|
||||
while (script.next()) {
|
||||
String name = script.getName();
|
||||
byte[] data = FileUtil.read(script.open());
|
||||
deflaterData.writeUTF(name);
|
||||
deflaterData.writeInt(data.length);
|
||||
deflaterData.write(data);
|
||||
}
|
||||
|
||||
deflaterData.writeUTF("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user