Implemented Global NPC Events!

All NPCs activate these scripts. If a player wants to create a script that's universally used by all NPCs, this allows for that to happen with a lot of ease!
This commit is contained in:
Luis C.M committed 2022-03-23 03:54:06 -05:00
1 parent 092592bd27
commit 18ff2bff78
15 files changed
+562 -38

No files matched your search

@@ -29,6 +29,7 @@ import net.minecraftforge.event.world.WorldEvent;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.controllers.data.ForgeDataScript;
import noppes.npcs.controllers.data.NPCDataScript;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.entity.*;
@@ -56,6 +57,8 @@ public class ScriptController {
public ForgeDataScript forgeScripts = new ForgeDataScript();
public NPCDataScript npcScripts = new NPCDataScript((EntityNPCInterface) null);
public ScriptController(){
loaded = false;
Instance = this;
@@ -111,6 +114,10 @@ public class ScriptController {
return new File(dir, "player_scripts.json");
}
private File npcScriptsFile() {
return new File(dir, "npc_scripts.json");
}
public boolean loadPlayerScripts() {
this.playerScripts.clear();
File file = this.playerScriptsFile();
@@ -143,6 +150,37 @@ public class ScriptController {
}
}
public boolean loadNPCScripts() {
this.npcScripts.clear();
File file = this.npcScriptsFile();
try {
if(!file.exists()) {
return false;
} else {
this.npcScripts.readFromNBT(NBTJsonUtil.LoadFile(file));
shouldSave = false;
return true;
}
} catch (Exception var3) {
LogWriter.error("Error loading: " + file.getAbsolutePath(), var3);
return false;
}
}
public void setNPCScripts(NBTTagCompound compound) {
this.npcScripts.readFromNBT(compound);
File file = this.npcScriptsFile();
try {
NBTJsonUtil.SaveFile(file, compound);
} catch (IOException var4) {
var4.printStackTrace();
} catch (JsonException var5) {
var5.printStackTrace();
}
}
private void loadCategories(){
dir = new File(CustomNpcs.getWorldSaveDirectory(), "scripts");
if(!dir.exists())