2023-03-16 04:27:19 -05:00
|
|
|
package noppes.npcs.client.gui.script;
|
|
|
|
|
|
2025-02-02 23:15:53 -05:00
|
|
|
import kamkeel.npcs.network.packets.request.script.EventScriptPacket;
|
2023-03-16 04:27:19 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.NBTTags;
|
|
|
|
|
import noppes.npcs.controllers.ScriptContainer;
|
|
|
|
|
import noppes.npcs.controllers.data.DataScript;
|
|
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class GuiNPCEventScripts extends GuiScriptInterface {
|
|
|
|
|
private final DataScript script;
|
|
|
|
|
|
|
|
|
|
public GuiNPCEventScripts(EntityNPCInterface npc) {
|
|
|
|
|
this.hookList = new ArrayList<>();
|
|
|
|
|
hookList.add("init");
|
|
|
|
|
hookList.add("tick");
|
|
|
|
|
hookList.add("interact");
|
|
|
|
|
hookList.add("dialog");
|
|
|
|
|
hookList.add("damaged");
|
|
|
|
|
hookList.add("killed");
|
|
|
|
|
hookList.add("meleeAttack");
|
2024-02-12 02:56:11 -05:00
|
|
|
hookList.add("meleeSwing");
|
2023-03-16 04:27:19 -05:00
|
|
|
hookList.add("rangedLaunched");
|
|
|
|
|
hookList.add("target");
|
|
|
|
|
hookList.add("collide");
|
|
|
|
|
hookList.add("kills");
|
|
|
|
|
hookList.add("dialogClose");
|
|
|
|
|
hookList.add("timer");
|
2023-03-16 04:56:33 -05:00
|
|
|
hookList.add("targetLost");
|
|
|
|
|
hookList.add("projectileTick");
|
|
|
|
|
hookList.add("projectileImpact");
|
2023-03-16 04:27:19 -05:00
|
|
|
|
|
|
|
|
this.script = new DataScript(npc);
|
|
|
|
|
this.handler = this.script;
|
2025-02-02 23:15:53 -05:00
|
|
|
EventScriptPacket.Get();
|
2023-03-16 04:27:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setGuiData(NBTTagCompound compound) {
|
|
|
|
|
if (!compound.hasKey("Tab")) {
|
|
|
|
|
script.setLanguage(compound.getString("ScriptLanguage"));
|
|
|
|
|
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
|
|
|
|
super.setGuiData(compound);
|
|
|
|
|
} else {
|
|
|
|
|
int tab = compound.getInteger("Tab");
|
|
|
|
|
ScriptContainer container = new ScriptContainer(script);
|
|
|
|
|
container.readFromNBT(compound.getCompoundTag("Script"));
|
|
|
|
|
if (script.getScripts().isEmpty()) {
|
|
|
|
|
for (int i = 0; i < compound.getInteger("TotalScripts"); i++) {
|
|
|
|
|
script.getScripts().add(new ScriptContainer(script));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
script.getScripts().set(tab, container);
|
2023-03-16 04:27:19 -05:00
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
|
super.save();
|
|
|
|
|
List<ScriptContainer> containers = this.script.getScripts();
|
|
|
|
|
for (int i = 0; i < containers.size(); i++) {
|
|
|
|
|
ScriptContainer container = containers.get(i);
|
2025-02-02 23:15:53 -05:00
|
|
|
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
2023-03-16 04:27:19 -05:00
|
|
|
}
|
|
|
|
|
NBTTagCompound scriptData = new NBTTagCompound();
|
|
|
|
|
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
|
|
|
|
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
|
|
|
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
2025-02-02 23:15:53 -05:00
|
|
|
EventScriptPacket.Save(-1, containers.size(), scriptData);
|
2023-03-16 04:27:19 -05:00
|
|
|
}
|
|
|
|
|
}
|