diff --git a/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderCustom.java b/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderCustom.java new file mode 100644 index 0000000..1315236 --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderCustom.java @@ -0,0 +1,89 @@ +/* + * 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.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import minetweaker.runtime.IScriptIterator; +import minetweaker.runtime.IScriptProvider; + +/** + * + * @author Stan + */ +public class ScriptProviderCustom implements IScriptProvider { + private static final Charset UTF8 = Charset.forName("UTF-8"); + + private final String moduleName; + private final List scripts; + + public ScriptProviderCustom(String moduleName) { + this.moduleName = moduleName; + scripts = new ArrayList(); + } + + public void add(String name, byte[] content) { + scripts.add(new CustomScript(name, content)); + } + + public void add(String name, String content) { + add(name, content.getBytes(UTF8)); + } + + @Override + public Iterator getScripts() { + return Collections.singleton(new CustomScriptIterator()).iterator(); + } + + private class CustomScript { + private final String name; + private final byte[] content; + + public CustomScript(String name, byte[] content) { + this.name = name; + this.content = content; + } + } + + private class CustomScriptIterator implements IScriptIterator { + private CustomScript current; + private final Iterator iterator = scripts.iterator(); + + @Override + public String getGroupName() { + return moduleName; + } + + @Override + public boolean next() { + if (iterator.hasNext()) { + current = iterator.next(); + return true; + } else { + return false; + } + } + + @Override + public String getName() { + return current.name; + } + + @Override + public InputStream open() throws IOException { + return new ByteArrayInputStream(current.content); + } + } +} diff --git a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java index e3d9ec9..3aadf5b 100644 --- a/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java +++ b/MineTweaker3-MC164-Main/src/main/java/minetweaker/mc164/MineTweakerMod.java @@ -8,6 +8,7 @@ package minetweaker.mc164; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; @@ -39,7 +40,9 @@ import minetweaker.mc164.server.MCServer; import minetweaker.mc164.util.MineTweakerHacks; import minetweaker.runtime.IScriptProvider; import minetweaker.runtime.providers.ScriptProviderCascade; +import minetweaker.runtime.providers.ScriptProviderCustom; import minetweaker.runtime.providers.ScriptProviderDirectory; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.Packet250CustomPayload; @@ -75,6 +78,8 @@ public class MineTweakerMod { public final MCRecipeManager recipes; private final IScriptProvider scriptsGlobal; + private final ScriptProviderCustom scriptsIMC; + private final Map networkByUser = new HashMap(); private final Map userByNetwork = new HashMap(); @@ -96,6 +101,7 @@ public class MineTweakerMod { } scriptsGlobal = new ScriptProviderDirectory(globalDir); + scriptsIMC = new ScriptProviderCustom("intermod"); MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal); } @@ -132,6 +138,20 @@ public class MineTweakerMod { // ### FML Event Handlers ### // ########################## + @EventHandler + public void onIMCEvent(FMLInterModComms.IMCEvent event) { + for (final FMLInterModComms.IMCMessage imcMessage : event.getMessages()) { + if (imcMessage.key.equalsIgnoreCase("addMineTweakerScript")) { + if (imcMessage.isStringMessage()) { + scriptsIMC.add("imc", imcMessage.getStringValue()); + } else if (imcMessage.isNBTMessage()) { + NBTTagCompound message = imcMessage.getNBTValue(); + scriptsIMC.add(message.getString("name"), message.getString("content")); + } + } + } + } + @EventHandler public void onLoad(FMLPreInitializationEvent ev) { @@ -163,7 +183,7 @@ public class MineTweakerMod { } IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir); - IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal); + IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal); MineTweakerImplementationAPI.setScriptProvider(cascaded); MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer())); diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java index 00ee698..67b4dd3 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java @@ -9,6 +9,7 @@ package minetweaker.mc1710; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; @@ -36,7 +37,9 @@ import minetweaker.mc1710.server.MCServer; import minetweaker.mc1710.util.MineTweakerHacks; import minetweaker.runtime.IScriptProvider; import minetweaker.runtime.providers.ScriptProviderCascade; +import minetweaker.runtime.providers.ScriptProviderCustom; import minetweaker.runtime.providers.ScriptProviderDirectory; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; /** @@ -75,6 +78,7 @@ public class MineTweakerMod { public final MCRecipeManager recipes; private final IScriptProvider scriptsGlobal; + private final ScriptProviderCustom scriptsIMC; public MineTweakerMod() { MineTweakerImplementationAPI.init( @@ -93,6 +97,14 @@ public class MineTweakerMod { globalDir.mkdirs(); } + /*try { + String data = Resources.toString(Resources.getResource(MineTweakerMod.class, "/minetweaker/myscript.zs"), Charsets.UTF_8); + + } catch (IOException ex) { + ex.printStackTrace(); + }*/ + + scriptsIMC = new ScriptProviderCustom("intermod"); scriptsGlobal = new ScriptProviderDirectory(globalDir); MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal); } @@ -101,6 +113,20 @@ public class MineTweakerMod { // ### FML Event Handlers ### // ########################## + @EventHandler + public void onIMCEvent(FMLInterModComms.IMCEvent event) { + for (final FMLInterModComms.IMCMessage imcMessage : event.getMessages()) { + if (imcMessage.key.equalsIgnoreCase("addMineTweakerScript")) { + if (imcMessage.isStringMessage()) { + scriptsIMC.add("imc", imcMessage.getStringValue()); + } else if (imcMessage.isNBTMessage()) { + NBTTagCompound message = imcMessage.getNBTValue(); + scriptsIMC.add(message.getString("name"), message.getString("content")); + } + } + } + } + @EventHandler public void onLoad(FMLPreInitializationEvent ev) { MinecraftForge.EVENT_BUS.register(new ForgeEventHandler()); @@ -129,7 +155,7 @@ public class MineTweakerMod { } IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir); - IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal); + IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal); MineTweakerImplementationAPI.setScriptProvider(cascaded); MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer())); diff --git a/MineTweaker3-MC1710-Mod-NEI/build.gradle b/MineTweaker3-MC1710-Mod-NEI/build.gradle index aa6fbae..c9e46a8 100644 --- a/MineTweaker3-MC1710-Mod-NEI/build.gradle +++ b/MineTweaker3-MC1710-Mod-NEI/build.gradle @@ -25,7 +25,7 @@ archivesBaseName = project.projectDir.name dependencies { compile project(':ZenScript') compile project(':MineTweaker3-API') - compile project(':MineTweaker3-MC172-Main') + compile project(':MineTweaker3-MC1710-Main') compile files('libs/NotEnoughItems-1.7.10-1.0.2.15-dev.jar') } diff --git a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java index 562cbd9..cca1ec8 100644 --- a/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java +++ b/MineTweaker3-MC172-Main/src/main/java/minetweaker/mc172/MineTweakerMod.java @@ -9,6 +9,7 @@ package minetweaker.mc172; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; @@ -36,7 +37,9 @@ import minetweaker.mc172.server.MCServer; import minetweaker.mc172.util.MineTweakerHacks; import minetweaker.runtime.IScriptProvider; import minetweaker.runtime.providers.ScriptProviderCascade; +import minetweaker.runtime.providers.ScriptProviderCustom; import minetweaker.runtime.providers.ScriptProviderDirectory; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; /** @@ -73,6 +76,7 @@ public class MineTweakerMod { public final MCRecipeManager recipes; private final IScriptProvider scriptsGlobal; + private final ScriptProviderCustom scriptsIMC; public MineTweakerMod() { MineTweakerImplementationAPI.init( @@ -91,6 +95,7 @@ public class MineTweakerMod { globalDir.mkdirs(); } + scriptsIMC = new ScriptProviderCustom("intermod"); scriptsGlobal = new ScriptProviderDirectory(globalDir); MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal); } @@ -99,6 +104,20 @@ public class MineTweakerMod { // ### FML Event Handlers ### // ########################## + @EventHandler + public void onIMCEvent(FMLInterModComms.IMCEvent event) { + for (final FMLInterModComms.IMCMessage imcMessage : event.getMessages()) { + if (imcMessage.key.equalsIgnoreCase("addMineTweakerScript")) { + if (imcMessage.isStringMessage()) { + scriptsIMC.add("imc", imcMessage.getStringValue()); + } else if (imcMessage.isNBTMessage()) { + NBTTagCompound message = imcMessage.getNBTValue(); + scriptsIMC.add(message.getString("name"), message.getString("content")); + } + } + } + } + @EventHandler public void onLoad(FMLPreInitializationEvent ev) { MinecraftForge.EVENT_BUS.register(new ForgeEventHandler()); @@ -127,7 +146,7 @@ public class MineTweakerMod { } IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir); - IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal); + IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal); MineTweakerImplementationAPI.setScriptProvider(cascaded); MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer())); } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java b/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java index 50627ea..dfe148c 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java @@ -77,7 +77,7 @@ public class ZenModule { clsScript.visitSource(script.getFileName(), null); EnvironmentClass environmentScript = new EnvironmentClass(clsScript, script.getEnvironment()); - clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName(), null, internal(Object.class), new String[] {internal(Runnable.class)}); + clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName().replace('.', '/'), null, internal(Object.class), new String[] {internal(Runnable.class)}); for (Map.Entry function : script.getFunctions().entrySet()) { ParsedFunction fn = function.getValue(); @@ -126,7 +126,7 @@ public class ZenModule { scriptOutput.ret(); scriptOutput.end(); - mainRun.invokeStatic(script.getClassName(), "__script__", "()V"); + mainRun.invokeStatic(script.getClassName().replace('.', '/'), "__script__", "()V"); } clsScript.visitEnd(); diff --git a/ZenScript/src/main/java/stanhebben/zenscript/parser/expression/ParsedExpressionArray.java b/ZenScript/src/main/java/stanhebben/zenscript/parser/expression/ParsedExpressionArray.java index 6796f5f..aad6ebe 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/parser/expression/ParsedExpressionArray.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/parser/expression/ParsedExpressionArray.java @@ -61,9 +61,6 @@ public class ParsedExpressionArray extends ParsedExpression { } } - System.out.println("Predicted array base type " + (predictedBaseType == null ? "none" : predictedBaseType.getName())); - System.out.println("Contents are: " + contents); - Expression[] cContents = new Expression[contents.size()]; for (int i = 0; i < contents.size(); i++) { cContents[i] = contents.get(i).compile(environment, predictedBaseType).eval(environment); diff --git a/build.gradle b/build.gradle index 216af0b..9bb250d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,13 @@ import org.gradle.api.artifacts.* apply plugin: 'base' // To add "clean" task to the root project. +apply from: 'configuration.gradle' subprojects { apply from: rootProject.file('common.gradle') } + task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') { title = 'All modules' destinationDir = new File(project.buildDir, 'merged-javadoc') @@ -33,6 +35,7 @@ task assembleMC1710(type: Jar, dependsOn: [\ ':MineTweaker3-MC1710-Mod-NEI:build', ':MineTweaker3-MC1710-Mod-MFR:build', ':MineTweaker3-MC1710-Mod-GregTech:build']) { + archiveName="MineTweaker3-1.7.10-${mineTweakerVersion}.jar" from zipTree(project(":ZenScript").jar.archivePath) from zipTree(project(':MineTweaker3-API').jar.archivePath) from zipTree(project(':MineTweaker3-MC1710-Main').jar.archivePath) @@ -49,6 +52,7 @@ task assembleMC172(type: Jar, dependsOn: [\ ':MineTweaker3-MC172-Mod-IC2:build', ':MineTweaker3-MC172-Mod-NEI:build', ':MineTweaker3-MC172-Mod-GregTech:build']) { + archiveName="MineTweaker3-1.7.2-${mineTweakerVersion}.jar" from zipTree(project(":ZenScript").jar.archivePath) from zipTree(project(':MineTweaker3-API').jar.archivePath) from zipTree(project(':MineTweaker3-MC172-Main').jar.archivePath) @@ -65,6 +69,7 @@ task assembleMC164(type: Jar, dependsOn: [\ ':MineTweaker3-MC164-Mod-NEI:build', ':MineTweaker3-MC164-Mod-GregTech:build', ':MineTweaker3-MC164-Mod-MFR:build']) { + archiveName="MineTweaker3-1.6.4-${mineTweakerVersion}.jar" from zipTree(project(":ZenScript").jar.archivePath) from zipTree(project(':MineTweaker3-API').jar.archivePath) from zipTree(project(':MineTweaker3-MC164-Main').jar.archivePath) @@ -74,6 +79,12 @@ task assembleMC164(type: Jar, dependsOn: [\ from zipTree(project(':MineTweaker3-MC164-Mod-MFR').jar.archivePath) } +task assembleAll(dependsOn: [ + assembleMC164, + assembleMC172, + assembleMC1710]) { +} + task zendoc164(type: Javadoc) { source = files(\ 'MineTweaker3-API/src/main/java', diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 46dfa2e..10d2e7b 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,4 +1,7 @@ +import java.io.File + apply plugin: 'java' +apply from: new File('../configuration.gradle') repositories { mavenCentral(); @@ -7,5 +10,5 @@ repositories { dependencies { compile gradleApi() compile 'org.ow2.asm:asm-debug-all:4.1' - compile files("libs/tools.jar") + compile files(javaToolsJar) } diff --git a/common.gradle b/common.gradle index 2e54632..1d2d272 100644 --- a/common.gradle +++ b/common.gradle @@ -2,8 +2,7 @@ // configurable properties // ----------------------- -ext.mineTweakerVersion="3.0.7" -ext.mineTweakerDebug="true" +apply from: rootProject.file('configuration.gradle') // -- end of configurable properties diff --git a/configuration.gradle b/configuration.gradle new file mode 100644 index 0000000..cd99bd8 --- /dev/null +++ b/configuration.gradle @@ -0,0 +1,4 @@ + +ext.mineTweakerVersion="3.0.8" +ext.mineTweakerDebug="false" +ext.javaToolsJar=new File("C:/Program Files/Java/jdk1.8.0_05/lib/tools.jar")