Files
CustomNPC-Plus/src/main/java/noppes/npcs/DataAdvanced.java
T

249 lines
10 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
2018-09-13 12:03:28 -04:00
import noppes.npcs.constants.EnumJobType;
import noppes.npcs.constants.EnumRoleType;
2022-06-12 01:26:23 -05:00
import noppes.npcs.controllers.GlobalDataController;
import noppes.npcs.controllers.data.DialogOption;
import noppes.npcs.controllers.data.FactionOptions;
import noppes.npcs.controllers.data.Line;
import noppes.npcs.controllers.data.Lines;
2018-09-13 12:03:28 -04:00
import noppes.npcs.entity.EntityNPCInterface;
2023-01-12 21:33:06 -05:00
import noppes.npcs.roles.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
2018-09-13 12:03:28 -04:00
public class DataAdvanced {
public Lines interactLines = new Lines();
public Lines worldLines = new Lines();
public Lines attackLines = new Lines();
public Lines killedLines = new Lines();
public Lines killLines = new Lines();
public boolean orderedLines = false;
public String idleSound = "";
public String angrySound = "";
public String hurtSound = "minecraft:game.player.hurt";
public String deathSound = "minecraft:game.player.hurt";
public String stepSound = "";
private EntityNPCInterface npc;
public FactionOptions factions = new FactionOptions();
public HashSet<UUID> tagUUIDs = new HashSet<>();
2018-09-13 12:03:28 -04:00
public EnumRoleType role = EnumRoleType.None;
public EnumJobType job = EnumJobType.None;
public boolean attackOtherFactions = false;
public boolean defendFaction = false;
public boolean disablePitch = false;
2022-05-29 14:42:28 -05:00
public String soulStonePlayerName = "";
2022-06-07 12:31:49 -05:00
public boolean refuseSoulStone = false;
public boolean soulStoneInit = false;
2022-06-08 22:13:30 -05:00
public int minFactionPointsToSoulStone = -1;
2018-09-13 12:03:28 -04:00
public DataAdvanced(EntityNPCInterface npc) {
this.npc = npc;
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setTag("NpcLines", worldLines.writeToNBT());
compound.setTag("NpcKilledLines", killedLines.writeToNBT());
compound.setTag("NpcInteractLines", interactLines.writeToNBT());
compound.setTag("NpcAttackLines", attackLines.writeToNBT());
compound.setTag("NpcKillLines", killLines.writeToNBT());
compound.setString("NpcIdleSound", idleSound);
compound.setString("NpcAngrySound", angrySound);
compound.setString("NpcHurtSound", hurtSound);
compound.setString("NpcDeathSound", deathSound);
compound.setString("NpcStepSound", stepSound);
compound.setBoolean("OrderedLines", orderedLines);
compound.setInteger("FactionID", npc.getFaction().id);
compound.setBoolean("AttackOtherFactions", attackOtherFactions);
compound.setBoolean("DefendFaction", defendFaction);
compound.setBoolean("DisablePitch", disablePitch);
compound.setInteger("Role", role.ordinal());
compound.setInteger("NpcJob", job.ordinal());
compound.setTag("FactionPoints", factions.writeToNBT(new NBTTagCompound()));
compound.setTag("NPCDialogOptions", nbtDialogs(npc.dialogs));
2022-05-29 02:46:24 -05:00
compound.setBoolean("RefuseSoulStone", refuseSoulStone);
compound.setString("SoulStonePlayerName", soulStonePlayerName);
2022-06-08 22:13:30 -05:00
compound.setInteger("MinFactionPointsToSoulStone", minFactionPointsToSoulStone);
2023-05-08 23:47:28 -04:00
if(tagUUIDs.size() > 0){
NBTTagList nbtTagList = new NBTTagList();
for (UUID uuid : tagUUIDs) {
nbtTagList.appendTag(new NBTTagString(uuid.toString()));
}
compound.setTag("TagUUIDs", nbtTagList);
}
2018-09-13 12:03:28 -04:00
return compound;
}
public void readToNBT(NBTTagCompound compound) {
interactLines.readNBT(compound.getCompoundTag("NpcInteractLines"));
worldLines.readNBT(compound.getCompoundTag("NpcLines"));
attackLines.readNBT(compound.getCompoundTag("NpcAttackLines"));
killedLines.readNBT(compound.getCompoundTag("NpcKilledLines"));
killLines.readNBT(compound.getCompoundTag("NpcKillLines"));
idleSound = compound.getString("NpcIdleSound");
angrySound = compound.getString("NpcAngrySound");
hurtSound = compound.getString("NpcHurtSound");
deathSound = compound.getString("NpcDeathSound");
stepSound = compound.getString("NpcStepSound");
orderedLines = compound.getBoolean("OrderedLines");
npc.setFaction(compound.getInteger("FactionID"));
npc.faction = npc.getFaction();
attackOtherFactions = compound.getBoolean("AttackOtherFactions");
defendFaction = compound.getBoolean("DefendFaction");
disablePitch = compound.getBoolean("DisablePitch");
setRole(compound.getInteger("Role"));
setJob(compound.getInteger("NpcJob"));
factions.readFromNBT(compound.getCompoundTag("FactionPoints"));
npc.dialogs = getDialogs(compound.getTagList("NPCDialogOptions", 10));
2022-05-29 02:46:24 -05:00
refuseSoulStone = compound.getBoolean("RefuseSoulStone");
soulStonePlayerName = compound.getString("SoulStonePlayerName");
2022-06-08 22:13:30 -05:00
minFactionPointsToSoulStone = compound.getInteger("MinFactionPointsToSoulStone");
2023-05-08 23:47:28 -04:00
if(compound.hasKey("TagUUIDs")){
NBTTagList nbtTagList = compound.getTagList("TagUUIDs",8);
for (int i = 0; i < nbtTagList.tagCount(); i++) {
tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i)));
}
}
2018-09-13 12:03:28 -04:00
}
private HashMap<Integer, DialogOption> getDialogs(NBTTagList tagList) {
HashMap<Integer, DialogOption> map = new HashMap<Integer, DialogOption>();
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i);
int slot = nbttagcompound.getInteger("DialogSlot");
DialogOption option = new DialogOption();
option.readNBT(nbttagcompound.getCompoundTag("NPCDialog"));
map.put(slot, option);
}
return map;
}
private NBTTagList nbtDialogs(HashMap<Integer, DialogOption> dialogs2) {
NBTTagList nbttaglist = new NBTTagList();
for (int slot : dialogs2.keySet()) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger("DialogSlot", slot);
nbttagcompound.setTag("NPCDialog", dialogs2.get(slot)
.writeNBT());
nbttaglist.appendTag(nbttagcompound);
}
return nbttaglist;
}
public Line getInteractLine() {
2023-12-03 20:48:37 -06:00
return (Line) interactLines.getLine(!orderedLines);
2018-09-13 12:03:28 -04:00
}
public Line getAttackLine() {
2023-12-03 20:48:37 -06:00
return (Line) attackLines.getLine(!orderedLines);
2018-09-13 12:03:28 -04:00
}
public Line getKilledLine() {
2023-12-03 20:48:37 -06:00
return (Line) killedLines.getLine(!orderedLines);
2018-09-13 12:03:28 -04:00
}
public Line getKillLine() {
2023-12-03 20:48:37 -06:00
return (Line) killLines.getLine(!orderedLines);
2018-09-13 12:03:28 -04:00
}
public Line getWorldLine() {
2023-12-03 20:48:37 -06:00
return (Line) worldLines.getLine(!orderedLines);
2018-09-13 12:03:28 -04:00
}
public void setRole(int i) {
if (EnumRoleType.values().length <= i) {
i -= 2;
}
role = EnumRoleType.values()[i];
if(role == EnumRoleType.None)
npc.roleInterface = null;
else if(role == EnumRoleType.Bank && !(npc.roleInterface instanceof RoleBank))
npc.roleInterface = new RoleBank(npc);
else if(role == EnumRoleType.Follower && !(npc.roleInterface instanceof RoleFollower))
npc.roleInterface = new RoleFollower(npc);
else if(role == EnumRoleType.Postman && !(npc.roleInterface instanceof RolePostman))
npc.roleInterface = new RolePostman(npc);
else if(role == EnumRoleType.Trader && !(npc.roleInterface instanceof RoleTrader))
npc.roleInterface = new RoleTrader(npc);
else if(role == EnumRoleType.Transporter && !(npc.roleInterface instanceof RoleTransporter))
npc.roleInterface = new RoleTransporter(npc);
else if(role == EnumRoleType.Companion && !(npc.roleInterface instanceof RoleCompanion))
npc.roleInterface = new RoleCompanion(npc);
}
public void setJob(int i) {
if(npc.jobInterface != null && !npc.worldObj.isRemote)
npc.jobInterface.reset();
job = EnumJobType.values()[i % EnumJobType.values().length];
if (job == EnumJobType.None)
npc.jobInterface = null;
else if (job == EnumJobType.Bard && !(npc.jobInterface instanceof JobBard))
npc.jobInterface = new JobBard(npc);
else if (job == EnumJobType.Healer && !(npc.jobInterface instanceof JobHealer))
npc.jobInterface = new JobHealer(npc);
else if (job == EnumJobType.Guard && !(npc.jobInterface instanceof JobGuard))
npc.jobInterface = new JobGuard(npc);
2022-06-12 01:26:23 -05:00
else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) {
if (!npc.isRemote()) {
2023-06-05 19:35:06 -04:00
if (npc.itemGiverId > 0 && GlobalDataController.Instance.itemGivers.containsKey(npc.itemGiverId)) {
GlobalDataController.Instance.itemGivers.get(npc.itemGiverId).npc = npc;
npc.jobInterface = GlobalDataController.Instance.itemGivers.get(npc.itemGiverId);
2022-06-12 01:26:23 -05:00
} else {
npc.jobInterface = new JobItemGiver(npc);
if (npc.itemGiverId == -1) {
2023-06-05 19:35:06 -04:00
((JobItemGiver) npc.jobInterface).itemGiverId = GlobalDataController.Instance.incrementItemGiverId();
2022-06-12 01:26:23 -05:00
} else {
((JobItemGiver) npc.jobInterface).itemGiverId = npc.itemGiverId;
}
2023-06-05 19:35:06 -04:00
GlobalDataController.Instance.itemGivers.put(((JobItemGiver) npc.jobInterface).itemGiverId, (JobItemGiver) npc.jobInterface);
2022-06-12 01:26:23 -05:00
npc.itemGiverId = ((JobItemGiver) npc.jobInterface).itemGiverId;
}
} else {
npc.jobInterface = new JobItemGiver(npc);
}
}
2018-09-13 12:03:28 -04:00
else if (job == EnumJobType.Follower && !(npc.jobInterface instanceof JobFollower))
npc.jobInterface = new JobFollower(npc);
else if (job == EnumJobType.Spawner && !(npc.jobInterface instanceof JobSpawner))
npc.jobInterface = new JobSpawner(npc);
else if (job == EnumJobType.Conversation && !(npc.jobInterface instanceof JobConversation))
npc.jobInterface = new JobConversation(npc);
else if (job == EnumJobType.ChunkLoader && !(npc.jobInterface instanceof JobChunkLoader))
npc.jobInterface = new JobChunkLoader(npc);
}
public boolean hasWorldLines() {
return !worldLines.isEmpty();
}
}