Files
CustomNPC-Plus/src/main/java/noppes/npcs/controllers/data/RecipeScript.java
T

66 lines
2.3 KiB
Java
Raw Normal View History

2025-07-09 15:40:31 -04: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;
import java.io.IOException;
public class RecipeScript extends ScriptHandler {
2025-07-09 15:40:31 -04: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;
}
public RecipeScript readFromNBT(NBTTagCompound compound) {
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
container = IScriptUnit.createFromNBT(compound.getCompoundTag("ScriptContent"), this);
2025-07-09 15:40:31 -04:00
}
return this;
}
@Override
public String noticeString() {
return "RecipeScript";
}
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);
this.container = IScriptUnit.createFromNBT(tabCompound, this);
2025-07-09 15:40:31 -04: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 {
PRE("pre"),
POST("post");
public final String function;
2025-07-23 14:22:52 -04:00
2025-07-09 15:40:31 -04:00
ScriptType(String functionName) {
this.function = functionName;
}
}
}