2025-02-10 14:58:45 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import kamkeel.npcs.util.ByteBufUtils;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraftforge.common.util.Constants;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2025-04-08 22:37:26 -04:00
|
|
|
import noppes.npcs.scripted.event.player.PlayerEvent;
|
2025-02-10 14:58:45 -05:00
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
2026-01-18 03:19:30 +02:00
|
|
|
public class EffectScript extends ScriptHandler {
|
2025-02-10 14:58:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setString("ScriptLanguage", scriptLanguage);
|
|
|
|
|
compound.setBoolean("ScriptEnabled", enabled);
|
|
|
|
|
|
|
|
|
|
if (container != null)
|
|
|
|
|
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 13:56:28 -05:00
|
|
|
public EffectScript readFromNBT(NBTTagCompound compound) {
|
2025-02-10 14:58:45 -05:00
|
|
|
scriptLanguage = compound.getString("ScriptLanguage");
|
|
|
|
|
enabled = compound.getBoolean("ScriptEnabled");
|
|
|
|
|
|
|
|
|
|
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
|
2026-01-13 22:16:51 +02:00
|
|
|
container = IScriptUnit.createFromNBT(compound.getCompoundTag("ScriptContent"), this);
|
2025-02-10 14:58:45 -05:00
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void callScript(ScriptType type, PlayerEvent.EffectEvent event) {
|
|
|
|
|
callScript(type.function, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void saveScript(ByteBuf buffer) throws IOException {
|
|
|
|
|
int tab = buffer.readInt();
|
|
|
|
|
int totalScripts = buffer.readInt();
|
|
|
|
|
if (totalScripts == 0) {
|
|
|
|
|
this.container = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tab == 0) {
|
|
|
|
|
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
|
2026-01-13 22:16:51 +02:00
|
|
|
this.container = IScriptUnit.createFromNBT(tabCompound, this);
|
2025-02-10 14:58:45 -05:00
|
|
|
} else {
|
|
|
|
|
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
|
|
|
|
|
this.setLanguage(compound.getString("ScriptLanguage"));
|
|
|
|
|
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
|
|
|
|
|
if (!ScriptController.Instance.languages.isEmpty()) {
|
|
|
|
|
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
|
|
|
|
|
} else {
|
|
|
|
|
this.setLanguage("ECMAScript");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.setEnabled(compound.getBoolean("ScriptEnabled"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ScriptType {
|
2025-03-14 03:33:10 -04:00
|
|
|
OnEffectAdd("onEffectAdd"),
|
|
|
|
|
OnEffectTick("onEffectTick"),
|
|
|
|
|
OnEffectRemove("onEffectRemove");
|
2025-02-10 14:58:45 -05:00
|
|
|
|
|
|
|
|
public final String function;
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2025-02-10 14:58:45 -05:00
|
|
|
ScriptType(String functionName) {
|
|
|
|
|
this.function = functionName;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-13 17:34:14 +02:00
|
|
|
}
|