mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 15:24:46 +00:00
Consolidated EventScriptContainer and ScriptContainer into a single ScriptContainer class. NPCs are now able to fly when ai.movementType == 1.
This commit is contained in:
1 parent
f3ebf86b1e
commit
72869e6a78
14 files changed
+422
-457
No files matched your search
@@ -1,10 +1,10 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -24,8 +25,8 @@ import noppes.npcs.scripted.constants.RoleType;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
|
||||
|
||||
public class DataScript {
|
||||
public Map<Integer,ScriptContainer> scripts = new HashMap<Integer,ScriptContainer>();
|
||||
public class DataScript implements IScriptHandler {
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
private final static EntityType entities = new EntityType();
|
||||
private final static JobType jobs = new JobType();
|
||||
private final static RoleType roles = new RoleType();
|
||||
@@ -41,6 +42,10 @@ public class DataScript {
|
||||
public boolean hasInited = false;
|
||||
|
||||
public DataScript(EntityNPCInterface npc) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
scripts.add(new ScriptContainer(this));
|
||||
}
|
||||
|
||||
this.npc = npc;
|
||||
if(npc instanceof EntityCustomNpc)
|
||||
dummyNpc = new ScriptNpc((EntityCustomNpc) npc);
|
||||
@@ -61,21 +66,25 @@ public class DataScript {
|
||||
return compound;
|
||||
}
|
||||
|
||||
private Map<Integer,ScriptContainer> readScript(NBTTagList list){
|
||||
Map<Integer,ScriptContainer> scripts = new HashMap<Integer,ScriptContainer>();
|
||||
private List<ScriptContainer> readScript(NBTTagList list){
|
||||
List<ScriptContainer> scripts = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
scripts.add(new ScriptContainer(this));
|
||||
}
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++){
|
||||
NBTTagCompound compoundd = list.getCompoundTagAt(i);
|
||||
ScriptContainer script = new ScriptContainer();
|
||||
ScriptContainer script = new ScriptContainer(this);
|
||||
script.readFromNBT(compoundd);
|
||||
if(script.hasCode() || npc.isRemote())
|
||||
scripts.put(compoundd.getInteger("Type"), script);
|
||||
if(script.hasCode() || npc.isRemote())
|
||||
scripts.set(compoundd.getInteger("Type"), script);
|
||||
}
|
||||
return scripts;
|
||||
}
|
||||
|
||||
private NBTTagList writeScript(Map<Integer,ScriptContainer> scripts){
|
||||
private NBTTagList writeScript(List<ScriptContainer> scripts){
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(Integer type : scripts.keySet()){
|
||||
for(int type = 0; type < scripts.size(); type++){
|
||||
NBTTagCompound compoundd = new NBTTagCompound();
|
||||
compoundd.setInteger("Type", type);
|
||||
ScriptContainer script = scripts.get(type);
|
||||
@@ -144,6 +153,69 @@ public class DataScript {
|
||||
return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty();
|
||||
}
|
||||
|
||||
public void callScript(EnumScriptType var1, Event var2, Object... obs) {
|
||||
|
||||
}
|
||||
|
||||
public Map<Long, String> getConsoleText() {
|
||||
Map<Long, String> map = new TreeMap();
|
||||
int tab = 0;
|
||||
Iterator var3 = this.getScripts().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var3.next();
|
||||
++tab;
|
||||
Iterator var5 = script.console.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<Long, String> entry = (Map.Entry)var5.next();
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public void clearConsole() {
|
||||
Iterator var1 = this.getScripts().iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var1.next();
|
||||
script.console.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isClient() {
|
||||
return this.npc.isRemote();
|
||||
}
|
||||
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean bo) {
|
||||
this.enabled = bo;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return this.scriptLanguage;
|
||||
}
|
||||
|
||||
public void setLanguage(String lang) {
|
||||
this.scriptLanguage = lang;
|
||||
}
|
||||
|
||||
public List<ScriptContainer> getScripts() {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
public String noticeString() {
|
||||
//BlockPos pos = this.npc.func_180425_c();
|
||||
//return MoreObjects.toStringHelper(this.npc).add("x", pos.func_177958_n()).add("y", pos.func_177956_o()).add("z", pos.func_177952_p()).toString();
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
if(world instanceof WorldServer)
|
||||
dummyWorld = new ScriptWorld((WorldServer) world);
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
public class EventScriptContainer {
|
||||
public static EventScriptContainer Current;
|
||||
//public String type = "init";
|
||||
private static String CurrentType;
|
||||
public String fullscript = "";
|
||||
public String script = "";
|
||||
public TreeMap<Long, String> console = new TreeMap();
|
||||
private HashSet<String> unknownFunctions = new HashSet();
|
||||
public boolean errored = false;
|
||||
public List<String> scripts = new ArrayList();
|
||||
public long lastCreated = 0L;
|
||||
private String currentScriptLanguage = null;
|
||||
public ScriptEngine engine = null;
|
||||
private IScriptHandler handler = null;
|
||||
private CompiledScript compScript = null;
|
||||
private boolean init = false;
|
||||
|
||||
public EventScriptContainer(IScriptHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.script = compound.getString("Script");
|
||||
//this.type = compound.getString("Type");
|
||||
this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10));
|
||||
this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
|
||||
this.lastCreated = 0L;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Script", this.script);
|
||||
//compound.setString("Type", this.type);
|
||||
compound.setTag("Console", NBTTags.NBTLongStringMap(this.console));
|
||||
compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts));
|
||||
return compound;
|
||||
}
|
||||
|
||||
private String getFullCode() {
|
||||
if(!this.init) {
|
||||
this.fullscript = this.script;
|
||||
if(!this.fullscript.isEmpty()) {
|
||||
this.fullscript = this.fullscript + "\n";
|
||||
}
|
||||
|
||||
Iterator var1 = this.scripts.iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
String loc = (String)var1.next();
|
||||
String code = (String)ScriptController.Instance.scripts.get(loc);
|
||||
if(code != null && !code.isEmpty()) {
|
||||
this.fullscript = this.fullscript + code + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.fullscript;
|
||||
}
|
||||
|
||||
/*public void run(ScriptEngine engine){
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
engine.getContext().setWriter(pw);
|
||||
engine.getContext().setErrorWriter(pw);
|
||||
try {
|
||||
if(compScript == null && engine instanceof Compilable)
|
||||
compScript = ((Compilable)engine).compile(getFullCode());
|
||||
|
||||
if(compScript != null){
|
||||
compScript.eval(engine.getContext());
|
||||
}
|
||||
else
|
||||
engine.eval(getFullCode());
|
||||
|
||||
} catch (Exception e) {
|
||||
errored = true;
|
||||
appandConsole(e.getMessage());
|
||||
}
|
||||
appandConsole(sw.getBuffer().toString().trim());
|
||||
}*/
|
||||
|
||||
public void run(EnumScriptType type, Event event) {
|
||||
this.run((String)type.function, (Object)event);
|
||||
}
|
||||
|
||||
public void run(String type, Object event) {
|
||||
if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) {
|
||||
this.setEngine(this.handler.getLanguage());
|
||||
if (this.engine != null) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastCreated) {
|
||||
this.lastCreated = ScriptController.Instance.lastLoaded;
|
||||
this.init = false;
|
||||
}
|
||||
|
||||
String var3 = "lock";
|
||||
synchronized("lock") {
|
||||
Current = this;
|
||||
CurrentType = type;
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
this.engine.getContext().setWriter(pw);
|
||||
this.engine.getContext().setErrorWriter(pw);
|
||||
|
||||
try {
|
||||
if (!this.init) {
|
||||
this.engine.eval(this.getFullCode());
|
||||
this.init = true;
|
||||
}
|
||||
|
||||
((Invocable)this.engine).invokeFunction(type, new Object[]{event});
|
||||
} catch (NoSuchMethodException var13) {
|
||||
this.unknownFunctions.add(type);
|
||||
} catch (Throwable var14) {
|
||||
this.errored = true;
|
||||
var14.printStackTrace(pw);
|
||||
} finally {
|
||||
this.appandConsole(sw.getBuffer().toString().trim());
|
||||
pw.close();
|
||||
Current = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void appandConsole(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.console.containsKey(time)) {
|
||||
message = (String)this.console.get(time) + "\n" + message;
|
||||
}
|
||||
|
||||
this.console.put(time, message);
|
||||
|
||||
while(this.console.size() > 40) {
|
||||
this.console.remove(this.console.firstKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCode() {
|
||||
return !this.getFullCode().isEmpty();
|
||||
}
|
||||
|
||||
public void setEngine(String scriptLanguage) {
|
||||
if(currentScriptLanguage != null && currentScriptLanguage.equals(scriptLanguage))
|
||||
return;
|
||||
engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
|
||||
currentScriptLanguage = scriptLanguage;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
|
||||
public class NBTTags {
|
||||
@@ -408,12 +409,12 @@ public class NBTTags {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<EventScriptContainer> GetScript(NBTTagList list, IScriptHandler handler) {
|
||||
public static List<ScriptContainer> GetScript(NBTTagList list, IScriptHandler handler) {
|
||||
ArrayList scripts = new ArrayList();
|
||||
|
||||
for(int i = 0; i < list.tagCount(); ++i) {
|
||||
NBTTagCompound compoundd = list.getCompoundTagAt(i);
|
||||
EventScriptContainer script = new EventScriptContainer(handler);
|
||||
ScriptContainer script = new ScriptContainer(handler);
|
||||
script.readFromNBT(compoundd);
|
||||
scripts.add(script);
|
||||
}
|
||||
@@ -421,12 +422,12 @@ public class NBTTags {
|
||||
return scripts;
|
||||
}
|
||||
|
||||
public static NBTTagList NBTScript(List<EventScriptContainer> scripts) {
|
||||
public static NBTTagList NBTScript(List<ScriptContainer> scripts) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
Iterator var2 = scripts.iterator();
|
||||
|
||||
while(var2.hasNext()) {
|
||||
EventScriptContainer script = (EventScriptContainer)var2.next();
|
||||
ScriptContainer script = (ScriptContainer)var2.next();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
script.writeToNBT(compound);
|
||||
list.appendTag(compound);
|
||||
|
||||
@@ -453,25 +453,4 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*@SubscribeEvent
|
||||
public void forgeTick(TickEvent.ServerTickEvent event){
|
||||
if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
|
||||
EventHooks.onForgeEvent(new ForgeEvent(event), event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void forgeTick(TickEvent.WorldTickEvent event){
|
||||
if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
|
||||
EventHooks.onForgeEvent(new ForgeEvent(event), event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void forgeTick(TickEvent.PlayerTickEvent event){
|
||||
if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
|
||||
EventHooks.onForgeEvent(new ForgeEvent(event), event);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -13,10 +13,10 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
public class EventGuiScriptList extends SubGuiInterface{
|
||||
private GuiCustomScroll scroll1;
|
||||
private GuiCustomScroll scroll2;
|
||||
private EventScriptContainer container;
|
||||
private ScriptContainer container;
|
||||
private List<String> scripts;
|
||||
|
||||
public EventGuiScriptList(List<String> scripts, EventScriptContainer container){
|
||||
public EventGuiScriptList(List<String> scripts, ScriptContainer container){
|
||||
this.container = container;
|
||||
setBackground("menubg.png");
|
||||
xSize = 346;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiConfirmOpenLink;
|
||||
@@ -15,6 +12,7 @@ import noppes.npcs.DataScript;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.script.EventGuiScriptList;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
@@ -139,19 +137,16 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
}
|
||||
|
||||
private String getConsoleText() {
|
||||
String console = "";
|
||||
if(activeConsole == 0){
|
||||
for(ScriptContainer container : script.scripts.values()){
|
||||
if(!container.console.isEmpty())
|
||||
console += container.console + '\n';
|
||||
}
|
||||
Map<Long, String> map = this.script.getConsoleText();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator var3 = map.entrySet().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Map.Entry<Long, String> entry = (Map.Entry)var3.next();
|
||||
builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n");
|
||||
}
|
||||
else{
|
||||
ScriptContainer container = script.scripts.get(activeConsole - 1);
|
||||
if(container != null)
|
||||
console = container.console;
|
||||
}
|
||||
return console;
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,19 +177,16 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
if (guibutton.id == 101) {
|
||||
getTextField(2).setText(NoppesStringUtils.getClipboardContents());
|
||||
}
|
||||
if (guibutton.id == 102) {
|
||||
getTextField(2).setText("");
|
||||
if(!showScript){
|
||||
if(activeConsole == 0){
|
||||
for(ScriptContainer container : script.scripts.values())
|
||||
container.console = "";
|
||||
}
|
||||
else{
|
||||
ScriptContainer container = script.scripts.get(activeConsole - 1);
|
||||
if(container != null)
|
||||
container.console = "";
|
||||
}
|
||||
ScriptContainer container;
|
||||
if(guibutton.id == 102) {
|
||||
if(this.activeTab > 0) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
container.script = "";
|
||||
} else {
|
||||
this.script.clearConsole();
|
||||
}
|
||||
|
||||
this.initGui();
|
||||
}
|
||||
if (guibutton.id == 103) {
|
||||
script.scriptLanguage = ((GuiNpcButton)guibutton).displayString;
|
||||
@@ -209,31 +201,36 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
if (guibutton.id == 106) {
|
||||
NoppesUtil.openFolder(ScriptController.Instance.dir);
|
||||
}
|
||||
if (guibutton.id == 107) {
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container == null)
|
||||
script.scripts.put(activeTab, container = new ScriptContainer());
|
||||
setSubGui(new GuiScriptList(languages.get(script.scriptLanguage), container));
|
||||
if(guibutton.id == 107) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.script.getScripts().add(container = new ScriptContainer(this.script));
|
||||
}
|
||||
|
||||
this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.script.getLanguage()), container));
|
||||
}
|
||||
if (guibutton.id == 108) {
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container != null){
|
||||
setScript();
|
||||
if(guibutton.id == 108) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container != null) {
|
||||
this.setScript();
|
||||
this.AWTWindow = new GuiJTextArea(container.script).setListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setScript(){
|
||||
if(showScript){
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container == null)
|
||||
script.scripts.put(activeTab, container = new ScriptContainer());
|
||||
String text = getTextField(2).getText();
|
||||
|
||||
private void setScript() {
|
||||
if(this.activeTab > 0) {
|
||||
ScriptContainer container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.script.getScripts().add(container = new ScriptContainer(this.script));
|
||||
}
|
||||
|
||||
String text = (this.getTextField(2)).getText();
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = text.replace("\r", "\n");
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,7 +268,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
|
||||
@Override
|
||||
public void saveText(String text) {
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
ScriptContainer container = script.getScripts().get(activeTab);
|
||||
if(container != null)
|
||||
container.script = text;
|
||||
initGui();
|
||||
|
||||
@@ -4,14 +4,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class GuiScriptList extends SubGuiInterface{
|
||||
private GuiCustomScroll scroll1;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -18,10 +18,10 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
public class EventGuiScriptList extends SubGuiInterface {
|
||||
private GuiCustomScroll scroll1;
|
||||
private GuiCustomScroll scroll2;
|
||||
private EventScriptContainer container;
|
||||
private ScriptContainer container;
|
||||
private List<String> scripts;
|
||||
|
||||
public EventGuiScriptList(List<String> scripts, EventScriptContainer container) {
|
||||
public EventGuiScriptList(List<String> scripts, ScriptContainer container) {
|
||||
this.container = container;
|
||||
this.setBackground("menubg.png");
|
||||
this.xSize = 346;
|
||||
|
||||
@@ -6,15 +6,11 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
@@ -24,17 +20,15 @@ import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.PixelmonHelper;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
@@ -180,7 +174,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookLabel.color = 0xaaaaaa;
|
||||
addLabel(hookLabel);
|
||||
|
||||
EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
ScriptContainer var7 = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + yoffset, this.guiTop + yoffset, this.xSize - 110 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script);
|
||||
this.addTextField(left);
|
||||
int left1 = this.guiLeft + this.xSize - 104;
|
||||
@@ -307,7 +301,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
if(guibutton.id == scriptLimit) {
|
||||
this.handler.getScripts().add(new EventScriptContainer(this.handler));
|
||||
this.handler.getScripts().add(new ScriptContainer(this.handler));
|
||||
this.activeTab = this.handler.getScripts().size();
|
||||
this.initGui();
|
||||
}
|
||||
@@ -336,10 +330,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
(this.getTextField(2)).setText(NoppesStringUtils.getClipboardContents());
|
||||
}
|
||||
|
||||
EventScriptContainer container;
|
||||
ScriptContainer container;
|
||||
if(guibutton.id == 102) {
|
||||
if(this.activeTab > 0) {
|
||||
container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
container.script = "";
|
||||
} else {
|
||||
this.handler.clearConsole();
|
||||
@@ -366,16 +360,16 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
if(guibutton.id == 107) {
|
||||
container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.handler.getScripts().add(container = new EventScriptContainer(this.handler));
|
||||
this.handler.getScripts().add(container = new ScriptContainer(this.handler));
|
||||
}
|
||||
|
||||
this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.handler.getLanguage()), container));
|
||||
}
|
||||
|
||||
if(guibutton.id == 108) {
|
||||
container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
if(container != null) {
|
||||
this.setScript();
|
||||
this.AWTWindow = new GuiJTextArea(container.script).setListener(this);
|
||||
@@ -386,9 +380,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
private void setScript() {
|
||||
if(this.activeTab > 0) {
|
||||
EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
ScriptContainer container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.handler.getScripts().add(container = new EventScriptContainer(this.handler));
|
||||
this.handler.getScripts().add(container = new ScriptContainer(this.handler));
|
||||
}
|
||||
|
||||
String text = (this.getTextField(2)).getText();
|
||||
@@ -424,7 +418,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
ScriptContainer container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
if(container != null) {
|
||||
container.script = text;
|
||||
}
|
||||
@@ -433,7 +427,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
@Override
|
||||
public void saveText(String text) {
|
||||
EventScriptContainer container = handler.getScripts().get(activeTab);
|
||||
ScriptContainer container = handler.getScripts().get(activeTab);
|
||||
if(container != null)
|
||||
container.script = text;
|
||||
initGui();
|
||||
|
||||
@@ -8,7 +8,6 @@ package noppes.npcs.controllers;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public interface IScriptHandler {
|
||||
@@ -24,7 +23,7 @@ public interface IScriptHandler {
|
||||
|
||||
void setLanguage(String var1);
|
||||
|
||||
List<EventScriptContainer> getScripts();
|
||||
List<ScriptContainer> getScripts();
|
||||
|
||||
String noticeString();
|
||||
|
||||
|
||||
@@ -1,94 +1,225 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public class ScriptContainer {
|
||||
public String fullscript = "";
|
||||
public String script = "";
|
||||
public String console = "";
|
||||
public boolean errored = false;
|
||||
public List<String> scripts = new ArrayList<String>();
|
||||
private long lastCreated = 0;
|
||||
private CompiledScript compScript = null;
|
||||
private String currentScriptLanguage = null;
|
||||
public ScriptEngine engine = null;
|
||||
private static final String lock = "lock";
|
||||
public static ScriptContainer Current;
|
||||
private static String CurrentType;
|
||||
private static final HashMap<String, Object> Data = new HashMap();
|
||||
public String fullscript = "";
|
||||
public String script = "";
|
||||
public TreeMap<Long, String> console = new TreeMap();
|
||||
public boolean errored = false;
|
||||
public List<String> scripts = new ArrayList();
|
||||
private HashSet<String> unknownFunctions = new HashSet();
|
||||
public long lastCreated = 0L;
|
||||
private String currentScriptLanguage = null;
|
||||
public ScriptEngine engine = null;
|
||||
private IScriptHandler handler = null;
|
||||
private boolean init = false;
|
||||
private static Method luaCoerce;
|
||||
private static Method luaCall;
|
||||
private CompiledScript compScript = null;
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
script = compound.getString("Script");
|
||||
console = compound.getString("ScriptConsole");
|
||||
scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
|
||||
lastCreated = 0;
|
||||
}
|
||||
public ScriptContainer(IScriptHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Script", script);
|
||||
compound.setString("ScriptConsole", console);
|
||||
compound.setTag("ScriptList", NBTTags.nbtStringList(scripts));
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.script = compound.getString("Script");
|
||||
//this.type = compound.getString("Type");
|
||||
this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10));
|
||||
this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
|
||||
this.lastCreated = 0L;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
if(ScriptController.Instance.lastLoaded > lastCreated){
|
||||
lastCreated = ScriptController.Instance.lastLoaded;
|
||||
fullscript = script;
|
||||
if(!fullscript.isEmpty())
|
||||
fullscript += "\n";
|
||||
for(String loc : scripts){
|
||||
String code = ScriptController.Instance.scripts.get(loc);
|
||||
if(code != null && !code.isEmpty())
|
||||
fullscript += code + "\n";
|
||||
}
|
||||
compScript = null;
|
||||
}
|
||||
return fullscript;
|
||||
}
|
||||
|
||||
public void run(ScriptEngine engine){
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
engine.getContext().setWriter(pw);
|
||||
engine.getContext().setErrorWriter(pw);
|
||||
try {
|
||||
if(compScript == null && engine instanceof Compilable)
|
||||
compScript = ((Compilable)engine).compile(getCode());
|
||||
|
||||
if(compScript != null){
|
||||
compScript.eval(engine.getContext());
|
||||
}
|
||||
else
|
||||
engine.eval(getCode());
|
||||
|
||||
} catch (Exception e) {
|
||||
errored = true;
|
||||
appandConsole(e.getMessage());
|
||||
}
|
||||
appandConsole(sw.getBuffer().toString().trim());
|
||||
}
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Script", this.script);
|
||||
//compound.setString("Type", this.type);
|
||||
compound.setTag("Console", NBTTags.NBTLongStringMap(this.console));
|
||||
compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void appandConsole(String message) {
|
||||
if(message == null || message.isEmpty())
|
||||
return;
|
||||
console = message + "\n" + console;
|
||||
}
|
||||
private String getFullCode() {
|
||||
if(!this.init) {
|
||||
this.fullscript = this.script;
|
||||
if(!this.fullscript.isEmpty()) {
|
||||
this.fullscript = this.fullscript + "\n";
|
||||
}
|
||||
|
||||
public boolean hasCode() {
|
||||
return !getCode().isEmpty();
|
||||
}
|
||||
Iterator var1 = this.scripts.iterator();
|
||||
|
||||
public void setEngine(String scriptLanguage) {
|
||||
if(currentScriptLanguage != null && currentScriptLanguage.equals(scriptLanguage))
|
||||
return;
|
||||
engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
|
||||
currentScriptLanguage = scriptLanguage;
|
||||
}
|
||||
while(var1.hasNext()) {
|
||||
String loc = (String)var1.next();
|
||||
String code = (String)ScriptController.Instance.scripts.get(loc);
|
||||
if(code != null && !code.isEmpty()) {
|
||||
this.fullscript = this.fullscript + code + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.fullscript;
|
||||
}
|
||||
|
||||
public void run(ScriptEngine engine){
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
engine.getContext().setWriter(pw);
|
||||
engine.getContext().setErrorWriter(pw);
|
||||
try {
|
||||
if(compScript == null && engine instanceof Compilable)
|
||||
compScript = ((Compilable)engine).compile(getFullCode());
|
||||
|
||||
if(compScript != null){
|
||||
compScript.eval(engine.getContext());
|
||||
}
|
||||
else
|
||||
engine.eval(getFullCode());
|
||||
|
||||
} catch (Exception e) {
|
||||
errored = true;
|
||||
appandConsole(e.getMessage());
|
||||
}
|
||||
appandConsole(sw.getBuffer().toString().trim());
|
||||
}
|
||||
|
||||
public void run(EnumScriptType type, Event event) {
|
||||
this.run((String)type.function, (Object)event);
|
||||
}
|
||||
|
||||
public void run(String type, Object event) {
|
||||
if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) {
|
||||
this.setEngine(this.handler.getLanguage());
|
||||
if (this.engine != null) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastCreated) {
|
||||
this.lastCreated = ScriptController.Instance.lastLoaded;
|
||||
this.init = false;
|
||||
}
|
||||
|
||||
String var3 = "lock";
|
||||
synchronized("lock") {
|
||||
Current = this;
|
||||
CurrentType = type;
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
this.engine.getContext().setWriter(pw);
|
||||
this.engine.getContext().setErrorWriter(pw);
|
||||
|
||||
try {
|
||||
if (!this.init) {
|
||||
this.engine.eval(this.getFullCode());
|
||||
this.init = true;
|
||||
}
|
||||
|
||||
if (this.engine.getFactory().getLanguageName().equals("lua")) {
|
||||
Object ob = this.engine.get(type);
|
||||
if (ob == null) {
|
||||
this.unknownFunctions.add(type);
|
||||
}
|
||||
} else {
|
||||
((Invocable)this.engine).invokeFunction(type, new Object[]{event});
|
||||
}
|
||||
} catch (NoSuchMethodException var13) {
|
||||
this.unknownFunctions.add(type);
|
||||
} catch (Throwable var14) {
|
||||
this.errored = true;
|
||||
var14.printStackTrace(pw);
|
||||
} finally {
|
||||
this.appandConsole(sw.getBuffer().toString().trim());
|
||||
pw.close();
|
||||
Current = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public void run(String type, Object event) {
|
||||
if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) {
|
||||
this.setEngine(this.handler.getLanguage());
|
||||
if (this.engine != null) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastCreated) {
|
||||
this.lastCreated = ScriptController.Instance.lastLoaded;
|
||||
this.init = false;
|
||||
}
|
||||
|
||||
String var3 = "lock";
|
||||
synchronized("lock") {
|
||||
Current = this;
|
||||
CurrentType = type;
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
this.engine.getContext().setWriter(pw);
|
||||
this.engine.getContext().setErrorWriter(pw);
|
||||
|
||||
try {
|
||||
if (!this.init) {
|
||||
this.engine.eval(this.getFullCode());
|
||||
this.init = true;
|
||||
}
|
||||
|
||||
((Invocable)this.engine).invokeFunction(type, new Object[]{event});
|
||||
} catch (NoSuchMethodException var13) {
|
||||
this.unknownFunctions.add(type);
|
||||
} catch (Throwable var14) {
|
||||
this.errored = true;
|
||||
var14.printStackTrace(pw);
|
||||
} finally {
|
||||
this.appandConsole(sw.getBuffer().toString().trim());
|
||||
pw.close();
|
||||
Current = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public void appandConsole(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.console.containsKey(time)) {
|
||||
message = (String)this.console.get(time) + "\n" + message;
|
||||
}
|
||||
|
||||
this.console.put(time, message);
|
||||
|
||||
while(this.console.size() > 40) {
|
||||
this.console.remove(this.console.firstKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCode() {
|
||||
return !this.getFullCode().isEmpty();
|
||||
}
|
||||
|
||||
public void setEngine(String scriptLanguage) {
|
||||
if(currentScriptLanguage != null && currentScriptLanguage.equals(scriptLanguage))
|
||||
return;
|
||||
engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
|
||||
currentScriptLanguage = scriptLanguage;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,9 @@ import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
@@ -26,7 +25,7 @@ import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
public class ForgeDataScript implements IScriptHandler {
|
||||
private List<EventScriptContainer> scripts = new ArrayList();
|
||||
private List<ScriptContainer> scripts = new ArrayList();
|
||||
private String scriptLanguage = "ECMAScript";
|
||||
public long lastInited = -1L;
|
||||
private boolean enabled = false;
|
||||
@@ -69,7 +68,7 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
Iterator var3 = this.scripts.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
EventScriptContainer script = (EventScriptContainer) var3.next();
|
||||
ScriptContainer script = (ScriptContainer) var3.next();
|
||||
|
||||
script.setEngine(scriptLanguage);
|
||||
if(script.engine == null)
|
||||
@@ -80,8 +79,6 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
script.engine.put("event", event);
|
||||
script.engine.put("API", new WrapperNpcAPI());
|
||||
|
||||
ScriptEngine engine = script.engine;
|
||||
|
||||
script.run(type, event);
|
||||
}
|
||||
//});
|
||||
@@ -112,7 +109,7 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
this.scriptLanguage = lang;
|
||||
}
|
||||
|
||||
public List<EventScriptContainer> getScripts() {
|
||||
public List<ScriptContainer> getScripts() {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
@@ -126,7 +123,7 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
Iterator var3 = this.getScripts().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
EventScriptContainer script = (EventScriptContainer)var3.next();
|
||||
ScriptContainer script = (ScriptContainer)var3.next();
|
||||
++tab;
|
||||
Iterator var5 = script.console.entrySet().iterator();
|
||||
|
||||
@@ -143,7 +140,7 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
Iterator var1 = this.getScripts().iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
EventScriptContainer script = (EventScriptContainer)var1.next();
|
||||
ScriptContainer script = (ScriptContainer)var1.next();
|
||||
script.console.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,21 +12,17 @@ import java.util.Map.Entry;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.controllers.PlayerData;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.ScriptWorld;
|
||||
import noppes.npcs.scripted.event.PlayerEvent;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
@@ -36,7 +32,7 @@ import javax.annotation.CheckForNull;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
public class PlayerDataScript implements IScriptHandler {
|
||||
public List<EventScriptContainer> scripts = new ArrayList();
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityPlayer player;
|
||||
private IPlayer playerAPI;
|
||||
@@ -82,71 +78,50 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
public void callScript(EnumScriptType type, Event event, Object... obs) {
|
||||
if(this.isEnabled()) {
|
||||
EventScriptContainer script;
|
||||
if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
|
||||
if (this.isEnabled()) {
|
||||
ScriptContainer script;
|
||||
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
|
||||
this.lastInited = ScriptController.Instance.lastLoaded;
|
||||
//ScriptController.Instance.playerScripts.errored.clear();
|
||||
if(this.player != null) {
|
||||
errored.clear();
|
||||
if (this.player != null) {
|
||||
this.scripts.clear();
|
||||
Iterator i = ScriptController.Instance.playerScripts.scripts.iterator();
|
||||
Iterator var3 = ScriptController.Instance.playerScripts.scripts.iterator();
|
||||
|
||||
while(i.hasNext()) {
|
||||
script = (EventScriptContainer)i.next();
|
||||
EventScriptContainer s = new EventScriptContainer(this);
|
||||
while(var3.hasNext()) {
|
||||
script = (ScriptContainer)var3.next();
|
||||
ScriptContainer s = new ScriptContainer(this);
|
||||
s.readFromNBT(script.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
this.scripts.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate;
|
||||
if(type != EnumScriptType.INIT) {
|
||||
if (type != EnumScriptType.INIT) {
|
||||
EventHooks.onPlayerInit(this);
|
||||
}
|
||||
}
|
||||
|
||||
for(int var7 = 0; var7 < this.scripts.size(); ++var7) {
|
||||
script = (EventScriptContainer)this.scripts.get(var7);
|
||||
|
||||
if(!ScriptController.Instance.playerScripts.errored.contains(Integer.valueOf(var7))) {
|
||||
if(script == null || script.errored || !script.hasCode())
|
||||
return;
|
||||
script.setEngine(scriptLanguage);
|
||||
if(script.engine == null)
|
||||
return;
|
||||
for(int i = 0; i + 1 < obs.length; i += 2){
|
||||
Object ob = obs[i + 1];
|
||||
if(ob instanceof Entity)
|
||||
ob = ScriptController.Instance.getScriptForEntity((Entity)ob);
|
||||
script.engine.put(obs[i].toString(), ob);
|
||||
}
|
||||
|
||||
ScriptEngine engine = script.engine;
|
||||
engine.put("world", dummyWorld);
|
||||
engine.put("player", dummyPlayer);
|
||||
PlayerEvent result = (PlayerEvent) engine.get("event");
|
||||
if(result == null)
|
||||
engine.put("event", result = new PlayerEvent(this.getPlayer()));
|
||||
script.engine.put("API", new WrapperNpcAPI());
|
||||
for(int i = 0; i < this.scripts.size(); ++i) {
|
||||
script = (ScriptContainer)this.scripts.get(i);
|
||||
if (!errored.contains(i)) {
|
||||
script.run(type, event);
|
||||
|
||||
if (script.errored) {
|
||||
ScriptController.Instance.playerScripts.errored.add(var7);
|
||||
errored.add(i);
|
||||
}
|
||||
|
||||
Iterator var8 = script.console.entrySet().iterator();
|
||||
|
||||
while(var8.hasNext()) {
|
||||
Entry<Long, String> entry = (Entry)var8.next();
|
||||
if (!ScriptController.Instance.playerScripts.console.containsKey(entry.getKey())) {
|
||||
ScriptController.Instance.playerScripts.console.put(entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue());
|
||||
if (!console.containsKey(entry.getKey())) {
|
||||
console.put(entry.getKey(), " tab " + (i + 1) + ":\n" + (String)entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
script.console.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +150,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
this.scriptLanguage = lang;
|
||||
}
|
||||
|
||||
public List<EventScriptContainer> getScripts() {
|
||||
public List<ScriptContainer> getScripts() {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.entity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -35,59 +36,53 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
super.updateFallState(p_180433_1_, p_180433_3_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_){
|
||||
if(!canFly()){
|
||||
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isInWater()){
|
||||
this.moveFlying(p_70612_1_, p_70612_2_, 0.02F);
|
||||
this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
||||
this.motionX *= 0.800000011920929D;
|
||||
this.motionY *= 0.800000011920929D;
|
||||
this.motionZ *= 0.800000011920929D;
|
||||
public void onLivingUpdate()
|
||||
{
|
||||
if(!canFly()){
|
||||
super.onLivingUpdate();
|
||||
return;
|
||||
}
|
||||
else if (this.isInsideOfMaterial(Material.lava)){
|
||||
this.moveFlying(p_70612_1_, p_70612_2_, 0.02F);
|
||||
this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
||||
this.motionX *= 0.5D;
|
||||
this.motionY *= 0.5D;
|
||||
this.motionZ *= 0.5D;
|
||||
}
|
||||
else{
|
||||
float f2 = 0.91F;
|
||||
|
||||
if (this.onGround){
|
||||
f2 = this.worldObj.getBlock((int)this.posX, (int)this.boundingBox.minY - 1, (int)this.posZ).slipperiness * 0.91F;
|
||||
this.motionY *= 0.6000000238418579D;
|
||||
double d1;
|
||||
double d3;
|
||||
double d5;
|
||||
|
||||
if (!this.worldObj.isRemote && this.getAttackTarget() != null)
|
||||
{
|
||||
Entity entity = this.getAttackTarget();
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (this.posY < entity.posY)
|
||||
{
|
||||
if (this.motionY < 0.0D)
|
||||
{
|
||||
this.motionY = 0.0D;
|
||||
}
|
||||
|
||||
this.motionY += (0.5D - this.motionY) * 0.6000000238418579D;
|
||||
}
|
||||
|
||||
double d0 = entity.posX - this.posX;
|
||||
d1 = entity.posZ - this.posZ;
|
||||
d3 = d0 * d0 + d1 * d1;
|
||||
|
||||
if (d3 > 9.0D)
|
||||
{
|
||||
d5 = (double)MathHelper.sqrt_double(d3);
|
||||
this.motionX += (d0 / d5 * 0.5D - this.motionX) * 0.6000000238418579D;
|
||||
this.motionZ += (d1 / d5 * 0.5D - this.motionZ) * 0.6000000238418579D;
|
||||
}
|
||||
}
|
||||
|
||||
float f3 = 0.16277136F / (f2 * f2 * f2);
|
||||
this.moveFlying(p_70612_1_, p_70612_2_, this.onGround ? 0.1F * f3 : 0.02F);
|
||||
f2 = 0.91F;
|
||||
|
||||
if (this.onGround){
|
||||
f2 = this.worldObj.getBlock((int)this.posX, (int)this.boundingBox.minY - 1, (int)this.posZ).slipperiness * 0.91F;
|
||||
}
|
||||
|
||||
this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
||||
this.motionX *= (double)f2;
|
||||
this.motionY *= (double)f2;
|
||||
this.motionZ *= (double)f2;
|
||||
}
|
||||
|
||||
this.prevLimbSwingAmount = this.limbSwingAmount;
|
||||
double d1 = this.posX - this.prevPosX;
|
||||
double d0 = this.posZ - this.prevPosZ;
|
||||
float f4 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;
|
||||
|
||||
if (f4 > 1.0F){
|
||||
f4 = 1.0F;
|
||||
if (this.motionX * this.motionX + this.motionZ * this.motionZ > 0.05000000074505806D)
|
||||
{
|
||||
this.rotationYaw = (float)Math.atan2(this.motionZ, this.motionX) * (180F / (float)Math.PI) - 90.0F;
|
||||
}
|
||||
|
||||
this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F;
|
||||
this.limbSwing += this.limbSwingAmount;
|
||||
super.onLivingUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user