2022-05-24 01:07:50 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import noppes.npcs.NBTTags;
|
|
|
|
|
import noppes.npcs.constants.EnumAnimation;
|
|
|
|
|
import noppes.npcs.constants.EnumJobType;
|
|
|
|
|
import noppes.npcs.constants.EnumRoleType;
|
|
|
|
|
import noppes.npcs.entity.EntityCustomNpc;
|
|
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
2022-05-24 01:08:23 -05:00
|
|
|
public class DataTransform {
|
2025-03-13 17:14:45 -04:00
|
|
|
public NBTTagCompound display;
|
|
|
|
|
public NBTTagCompound ai;
|
|
|
|
|
public NBTTagCompound advanced;
|
|
|
|
|
public NBTTagCompound inv;
|
|
|
|
|
public NBTTagCompound stats;
|
|
|
|
|
public NBTTagCompound role;
|
|
|
|
|
public NBTTagCompound job;
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean hasDisplay, hasAi, hasAdvanced, hasInv, hasStats, hasRole, hasJob, isActive;
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private EntityNPCInterface npc;
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean editingModus = false;
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public DataTransform(EntityNPCInterface npc) {
|
|
|
|
|
this.npc = npc;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
2025-03-13 17:14:45 -04:00
|
|
|
compound.setBoolean("TransformIsActive", isActive);
|
|
|
|
|
writeOptions(compound);
|
|
|
|
|
if (hasDisplay)
|
|
|
|
|
compound.setTag("TransformDisplay", display);
|
|
|
|
|
if (hasAi)
|
|
|
|
|
compound.setTag("TransformAI", ai);
|
|
|
|
|
if (hasAdvanced)
|
|
|
|
|
compound.setTag("TransformAdvanced", advanced);
|
|
|
|
|
if (hasInv)
|
|
|
|
|
compound.setTag("TransformInv", inv);
|
|
|
|
|
if (hasStats)
|
|
|
|
|
compound.setTag("TransformStats", stats);
|
|
|
|
|
if (hasRole)
|
|
|
|
|
compound.setTag("TransformRole", role);
|
|
|
|
|
if (hasJob)
|
|
|
|
|
compound.setTag("TransformJob", job);
|
|
|
|
|
|
|
|
|
|
return compound;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public NBTTagCompound writeOptions(NBTTagCompound compound) {
|
|
|
|
|
compound.setBoolean("TransformHasDisplay", hasDisplay);
|
|
|
|
|
compound.setBoolean("TransformHasAI", hasAi);
|
|
|
|
|
compound.setBoolean("TransformHasAdvanced", hasAdvanced);
|
|
|
|
|
compound.setBoolean("TransformHasInv", hasInv);
|
|
|
|
|
compound.setBoolean("TransformHasStats", hasStats);
|
|
|
|
|
compound.setBoolean("TransformHasRole", hasRole);
|
|
|
|
|
compound.setBoolean("TransformHasJob", hasJob);
|
|
|
|
|
compound.setBoolean("TransformEditingModus", editingModus);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public void readToNBT(NBTTagCompound compound) {
|
2025-03-13 17:14:45 -04:00
|
|
|
isActive = compound.getBoolean("TransformIsActive");
|
|
|
|
|
readOptions(compound);
|
|
|
|
|
display = hasDisplay ? compound.getCompoundTag("TransformDisplay") : getDisplay();
|
|
|
|
|
ai = hasAi ? compound.getCompoundTag("TransformAI") : npc.ais.writeToNBT(new NBTTagCompound());
|
|
|
|
|
advanced = hasAdvanced ? compound.getCompoundTag("TransformAdvanced") : getAdvanced();
|
|
|
|
|
inv = hasInv ? compound.getCompoundTag("TransformInv") : npc.inventory.writeEntityToNBT(new NBTTagCompound());
|
|
|
|
|
stats = hasStats ? compound.getCompoundTag("TransformStats") : npc.stats.writeToNBT(new NBTTagCompound());
|
|
|
|
|
job = hasJob ? compound.getCompoundTag("TransformJob") : getJob();
|
|
|
|
|
role = hasRole ? compound.getCompoundTag("TransformRole") : getRole();
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public NBTTagCompound getJob() {
|
2025-03-13 17:14:45 -04:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
compound.setInteger("NpcJob", npc.advanced.job.ordinal());
|
|
|
|
|
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null) {
|
|
|
|
|
npc.jobInterface.writeToNBT(compound);
|
|
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public NBTTagCompound getRole() {
|
2025-03-13 17:14:45 -04:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-01-30 12:16:11 -05:00
|
|
|
compound.setInteger("Role", npc.advanced.role.ordinal());
|
2018-09-13 12:03:28 -04:00
|
|
|
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null) {
|
|
|
|
|
npc.roleInterface.writeToNBT(compound);
|
|
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return compound;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public NBTTagCompound getDisplay() {
|
2025-03-13 17:14:45 -04:00
|
|
|
NBTTagCompound compound = npc.display.writeToNBT(new NBTTagCompound());
|
|
|
|
|
if (npc instanceof EntityCustomNpc) {
|
|
|
|
|
compound.setTag("ModelData", ((EntityCustomNpc) npc).modelData.writeToNBT());
|
|
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
return compound;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound getAdvanced() {
|
2025-03-13 17:14:45 -04:00
|
|
|
EnumJobType jopType = npc.advanced.job;
|
|
|
|
|
EnumRoleType roleType = npc.advanced.role;
|
|
|
|
|
|
|
|
|
|
npc.advanced.job = EnumJobType.None;
|
|
|
|
|
npc.advanced.role = EnumRoleType.None;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = npc.advanced.writeToNBT(new NBTTagCompound());
|
|
|
|
|
compound.removeTag("Role");
|
|
|
|
|
compound.removeTag("NpcJob");
|
|
|
|
|
|
|
|
|
|
npc.advanced.job = jopType;
|
|
|
|
|
npc.advanced.role = roleType;
|
|
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void readOptions(NBTTagCompound compound) {
|
|
|
|
|
boolean hadDisplay = hasDisplay;
|
|
|
|
|
boolean hadAI = hasAi;
|
|
|
|
|
boolean hadAdvanced = hasAdvanced;
|
|
|
|
|
boolean hadInv = hasInv;
|
|
|
|
|
boolean hadStats = hasStats;
|
|
|
|
|
boolean hadRole = hasRole;
|
|
|
|
|
boolean hadJob = hasJob;
|
|
|
|
|
|
|
|
|
|
hasDisplay = compound.getBoolean("TransformHasDisplay");
|
|
|
|
|
hasAi = compound.getBoolean("TransformHasAI");
|
|
|
|
|
hasAdvanced = compound.getBoolean("TransformHasAdvanced");
|
|
|
|
|
hasInv = compound.getBoolean("TransformHasInv");
|
|
|
|
|
hasStats = compound.getBoolean("TransformHasStats");
|
|
|
|
|
hasRole = compound.getBoolean("TransformHasRole");
|
|
|
|
|
hasJob = compound.getBoolean("TransformHasJob");
|
|
|
|
|
editingModus = compound.getBoolean("TransformEditingModus");
|
|
|
|
|
|
|
|
|
|
if (hasDisplay && !hadDisplay) {
|
|
|
|
|
display = getDisplay();
|
|
|
|
|
}
|
|
|
|
|
if (hasAi && !hadAI)
|
|
|
|
|
ai = npc.ais.writeToNBT(new NBTTagCompound());
|
|
|
|
|
if (hasStats && !hadStats)
|
|
|
|
|
stats = npc.stats.writeToNBT(new NBTTagCompound());
|
|
|
|
|
if (hasInv && !hadInv)
|
|
|
|
|
inv = npc.inventory.writeEntityToNBT(new NBTTagCompound());
|
|
|
|
|
if (hasAdvanced && !hadAdvanced)
|
|
|
|
|
advanced = getAdvanced();
|
|
|
|
|
if (hasJob && !hadJob)
|
|
|
|
|
job = getJob();
|
|
|
|
|
if (hasRole && !hadRole)
|
|
|
|
|
role = getRole();
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2025-01-30 12:16:11 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean isValid() {
|
|
|
|
|
return hasAdvanced || hasAi || hasDisplay || hasInv || hasStats || hasJob || hasRole;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public NBTTagCompound processAdvanced(NBTTagCompound compoundAdv,
|
|
|
|
|
NBTTagCompound compoundRole, NBTTagCompound compoundJob) {
|
|
|
|
|
|
|
|
|
|
if (hasAdvanced)
|
|
|
|
|
compoundAdv = advanced;
|
|
|
|
|
if (hasRole)
|
|
|
|
|
compoundRole = role;
|
|
|
|
|
if (hasJob)
|
|
|
|
|
compoundJob = job;
|
|
|
|
|
|
|
|
|
|
Set<String> names = compoundRole.func_150296_c();
|
|
|
|
|
for (String name : names)
|
|
|
|
|
compoundAdv.setTag(name, compoundRole.getTag(name));
|
|
|
|
|
|
|
|
|
|
names = compoundJob.func_150296_c();
|
|
|
|
|
for (String name : names)
|
|
|
|
|
compoundAdv.setTag(name, compoundJob.getTag(name));
|
|
|
|
|
|
|
|
|
|
return compoundAdv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void transform(boolean isActive) {
|
|
|
|
|
if (this.isActive == isActive)
|
|
|
|
|
return;
|
|
|
|
|
if (hasDisplay) {
|
|
|
|
|
NBTTagCompound compound = getDisplay();
|
|
|
|
|
npc.display.readToNBT(NBTTags.NBTMerge(compound, display));
|
|
|
|
|
if (npc instanceof EntityCustomNpc) {
|
|
|
|
|
((EntityCustomNpc) npc).modelData.readFromNBT(NBTTags.NBTMerge(compound.getCompoundTag("ModelData"), display.getCompoundTag("ModelData")));
|
|
|
|
|
}
|
|
|
|
|
display = compound;
|
|
|
|
|
}
|
|
|
|
|
if (hasStats) {
|
|
|
|
|
NBTTagCompound compound = npc.stats.writeToNBT(new NBTTagCompound());
|
|
|
|
|
npc.stats.readToNBT(NBTTags.NBTMerge(compound, stats));
|
|
|
|
|
stats = compound;
|
|
|
|
|
}
|
|
|
|
|
if (hasAdvanced || hasJob || hasRole) {
|
|
|
|
|
NBTTagCompound compoundAdv = getAdvanced();
|
|
|
|
|
NBTTagCompound compoundRole = getRole();
|
|
|
|
|
NBTTagCompound compoundJob = getJob();
|
|
|
|
|
|
|
|
|
|
NBTTagCompound compound = processAdvanced(compoundAdv, compoundRole, compoundJob);
|
|
|
|
|
npc.advanced.readToNBT(compound);
|
|
|
|
|
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null)
|
|
|
|
|
npc.roleInterface.readFromNBT(NBTTags.NBTMerge(compoundRole, compound));
|
|
|
|
|
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null)
|
|
|
|
|
npc.jobInterface.readFromNBT(NBTTags.NBTMerge(compoundJob, compound));
|
|
|
|
|
|
|
|
|
|
if (hasAdvanced)
|
|
|
|
|
advanced = compoundAdv;
|
|
|
|
|
if (hasRole)
|
|
|
|
|
role = compoundRole;
|
|
|
|
|
if (hasJob)
|
|
|
|
|
job = compoundJob;
|
|
|
|
|
}
|
|
|
|
|
if (hasAi) {
|
|
|
|
|
NBTTagCompound compound = npc.ais.writeToNBT(new NBTTagCompound());
|
|
|
|
|
npc.ais.readToNBT(NBTTags.NBTMerge(compound, ai));
|
|
|
|
|
ai = compound;
|
|
|
|
|
npc.setCurrentAnimation(EnumAnimation.NONE);
|
|
|
|
|
}
|
|
|
|
|
if (hasInv) {
|
|
|
|
|
NBTTagCompound compound = npc.inventory.writeEntityToNBT(new NBTTagCompound());
|
|
|
|
|
npc.inventory.readEntityFromNBT(NBTTags.NBTMerge(compound, inv));
|
|
|
|
|
inv = compound;
|
|
|
|
|
}
|
|
|
|
|
npc.updateHitbox();
|
|
|
|
|
npc.updateAI = true;
|
|
|
|
|
this.isActive = isActive;
|
|
|
|
|
npc.updateClient = true;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|