Fixed janino script handler serialization inconsistencies

This commit is contained in:
bigguy345 committed 2026-04-03 16:32:34 +02:00
1 parent 4c301b3c1c
commit 8e8ab06507
2 files changed
+11 -7

No files matched your search

@@ -56,11 +56,17 @@ public class JaninoScriptHandler<S extends JaninoScript<?>> extends ScriptHandle
public void readFromNBT(NBTTagCompound compound) {
// JaninoScriptable's helper generics assume JaninoScript<T>, but most of our scripts are JaninoScript<?>.
// Keep it simple and safe: treat it as raw.
script = (S) JaninoScript.readFromNBT(compound, (JaninoScript) script, (Supplier) factory);
NBTTagCompound tag = compound.getCompoundTag("Script");
enabled = tag.getBoolean("enabled");
script = (S) JaninoScript.readFromNBT(tag, (JaninoScript) script, (Supplier) factory);
}
public void writeToNBT(NBTTagCompound compound) {
JaninoScript.writeToNBT(compound, (JaninoScript) script);
NBTTagCompound tag = new NBTTagCompound();
tag.setBoolean("enabled", enabled);
JaninoScript.writeToNBT(tag, (JaninoScript) script);
compound.setTag("Script", tag);
}
// -------------------- IScriptHandler --------------------
@@ -544,15 +544,13 @@ public abstract class JaninoScript<T> implements IScriptUnit {
}
public static <T, S extends JaninoScript<T>> S readFromNBT(NBTTagCompound compound, S script, Supplier<S> factory) {
if (compound.hasKey("Script")) {
if (script == null) script = factory.get();
script.readFromNBT(compound.getCompoundTag("Script"));
}
if (script == null) script = factory.get();
script.readFromNBT(compound);
return script;
}
public static <T> NBTTagCompound writeToNBT(NBTTagCompound compound, JaninoScript<T> script) {
if (script != null) compound.setTag("Script", script.writeToNBT(new NBTTagCompound()));
if (script != null) script.writeToNBT(compound);
return compound;
}
}