mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 20:42:16 +00:00
- Implemented IMC scripts
- Improved build scripts somewhat - Added tools.jar dir to the configuration file
This commit is contained in:
1 parent
983de16ed9
commit
98d4932764
11 files changed
+180
-12
No files matched your search
+89
@@ -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<CustomScript> scripts;
|
||||
|
||||
public ScriptProviderCustom(String moduleName) {
|
||||
this.moduleName = moduleName;
|
||||
scripts = new ArrayList<CustomScript>();
|
||||
}
|
||||
|
||||
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<IScriptIterator> getScripts() {
|
||||
return Collections.<IScriptIterator>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<CustomScript> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String, INetworkManager> networkByUser = new HashMap<String, INetworkManager>();
|
||||
private final Map<INetworkManager, NetHandler> userByNetwork = new HashMap<INetworkManager, NetHandler>();
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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<String, ParsedFunction> 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();
|
||||
|
||||
-3
@@ -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);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
// configurable properties
|
||||
// -----------------------
|
||||
|
||||
ext.mineTweakerVersion="3.0.7"
|
||||
ext.mineTweakerDebug="true"
|
||||
apply from: rootProject.file('configuration.gradle')
|
||||
|
||||
// -- end of configurable properties
|
||||
|
||||
|
||||
@@ -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")
|
||||
Reference in new issue
Block a user