2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import com.google.common.collect.Iterables;
|
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
|
import com.mojang.authlib.properties.Property;
|
2024-08-22 21:26:54 +02:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
import cpw.mods.fml.common.Loader;
|
|
|
|
|
import cpw.mods.fml.common.LoaderState;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2021-11-22 23:34:02 -06:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.nbt.NBTUtil;
|
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
|
import net.minecraft.util.StringUtils;
|
2023-01-07 00:21:08 -05:00
|
|
|
import noppes.npcs.config.ConfigMain;
|
2023-07-27 17:19:15 -05:00
|
|
|
import noppes.npcs.controllers.data.AnimationData;
|
2024-02-29 22:20:35 -05:00
|
|
|
import noppes.npcs.controllers.data.HitboxData;
|
2022-05-23 20:47:32 -05:00
|
|
|
import noppes.npcs.controllers.data.SkinOverlay;
|
2024-03-17 23:15:11 -04:00
|
|
|
import noppes.npcs.controllers.data.TintData;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2022-05-23 20:41:32 -05:00
|
|
|
import noppes.npcs.entity.data.DataSkinOverlays;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.util.ValueUtil;
|
|
|
|
|
|
2024-08-22 21:26:54 +02:00
|
|
|
import java.util.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public class DataDisplay {
|
2024-02-29 22:20:35 -05:00
|
|
|
public EntityNPCInterface npc;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public String name;
|
|
|
|
|
public String title = "";
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
private int markovGeneratorId = 8; //roman,japanese,slavic,welsh,sami,oldnorse,ancientgreek,aztec,classic,spanish (0 - 9 inclusively)
|
|
|
|
|
private int markovGender = 0; //0:random, 1:male, 2:female
|
2021-06-13 19:26:00 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public byte skinType = 0; //0:normal, 1:player, 2:url, 3:url64
|
2021-05-06 01:27:24 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public String url = "";
|
2021-05-06 01:27:24 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public GameProfile playerProfile;
|
|
|
|
|
public String texture = "customnpcs:textures/entity/humanmale/Steve.png";
|
|
|
|
|
public String cloakTexture = "";
|
2022-05-15 16:47:48 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public DataSkinOverlays skinOverlayData;
|
|
|
|
|
public long overlayRenderTicks = 0;
|
2022-05-15 16:47:48 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public AnimationData animationData;
|
|
|
|
|
public HitboxData hitboxData;
|
|
|
|
|
public TintData tintData;
|
2023-01-11 19:12:53 -06:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public String glowTexture = "";
|
2022-05-15 16:47:48 -05:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public int visible = 0; //0:visible 1:Invisible 2:semi-invisible
|
2024-02-29 22:20:35 -05:00
|
|
|
public int modelSize = 5;
|
|
|
|
|
public int showName = 0;
|
|
|
|
|
public int modelType = 0;
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public boolean disableLivingAnimation = false;
|
|
|
|
|
public byte showBossBar = 0;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public ArrayList<UUID> invisibleToList = new ArrayList<>();
|
2021-04-29 20:42:52 -04:00
|
|
|
|
2024-08-22 21:26:54 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public boolean isInvisibleToMe;
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public HashSet<Integer> tempInvisIds;
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public DataDisplay(EntityNPCInterface npc) {
|
2024-02-29 22:20:35 -05:00
|
|
|
this.npc = npc;
|
2025-03-12 20:12:01 -04:00
|
|
|
markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length - 1);
|
2024-02-29 22:20:35 -05:00
|
|
|
skinOverlayData = new DataSkinOverlays(npc);
|
|
|
|
|
name = getRandomName();
|
|
|
|
|
animationData = new AnimationData(this);
|
|
|
|
|
hitboxData = new HitboxData();
|
|
|
|
|
tintData = new TintData();
|
|
|
|
|
}
|
2021-06-13 19:26:00 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public String getRandomName() {
|
|
|
|
|
return CustomNpcs.MARKOV_GENERATOR[markovGeneratorId].fetch(markovGender);
|
|
|
|
|
}
|
2021-06-13 19:26:00 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
|
nbttagcompound.setString("Name", name);
|
|
|
|
|
nbttagcompound.setInteger("MarkovGeneratorId", markovGeneratorId);
|
|
|
|
|
nbttagcompound.setInteger("MarkovGender", markovGender);
|
|
|
|
|
nbttagcompound.setString("Title", title);
|
|
|
|
|
nbttagcompound.setString("SkinUrl", url);
|
|
|
|
|
nbttagcompound.setString("Texture", texture);
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound.setString("CloakTexture", cloakTexture);
|
|
|
|
|
nbttagcompound.setByte("UsingSkinUrl", skinType);
|
|
|
|
|
nbttagcompound.setString("GlowTexture", glowTexture);
|
2022-05-15 16:47:48 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound = skinOverlayData.writeToNBT(nbttagcompound);
|
2022-05-15 16:47:48 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound = animationData.writeToNBT(nbttagcompound);
|
|
|
|
|
nbttagcompound = hitboxData.writeToNBT(nbttagcompound);
|
|
|
|
|
nbttagcompound = tintData.writeToNBT(nbttagcompound);
|
2024-02-18 17:26:31 +03:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (this.playerProfile != null) {
|
2018-09-13 12:03:28 -04:00
|
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
|
|
|
NBTUtil.func_152460_a(nbttagcompound1, this.playerProfile);
|
|
|
|
|
nbttagcompound.setTag("SkinUsername", nbttagcompound1);
|
|
|
|
|
}
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound.setInteger("Size", modelSize);
|
|
|
|
|
nbttagcompound.setInteger("modelType", modelType);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound.setInteger("ShowName", showName);
|
|
|
|
|
nbttagcompound.setInteger("NpcVisible", visible);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound.setBoolean("NoLivingAnimation", disableLivingAnimation);
|
|
|
|
|
nbttagcompound.setByte("BossBar", showBossBar);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-08-22 21:26:54 +02:00
|
|
|
boolean saveNonPersistendIDs = Loader.instance().isInState(LoaderState.SERVER_STARTED);
|
|
|
|
|
ArrayList<Integer> nonPersistedIDs = new ArrayList<>();
|
|
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
NBTTagList list = new NBTTagList();
|
2025-03-12 20:12:01 -04:00
|
|
|
for (UUID uuid : invisibleToList) {
|
|
|
|
|
if (saveNonPersistendIDs) {
|
2024-08-22 21:26:54 +02:00
|
|
|
EntityPlayer p = NoppesUtilServer.getPlayer(uuid);
|
2025-03-12 20:12:01 -04:00
|
|
|
if (p != null)
|
2024-08-22 21:26:54 +02:00
|
|
|
nonPersistedIDs.add(p.getEntityId());
|
|
|
|
|
}
|
2024-02-29 22:20:35 -05:00
|
|
|
list.appendTag(new NBTTagString(uuid.toString()));
|
|
|
|
|
}
|
2021-11-22 23:34:02 -06:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (!nonPersistedIDs.isEmpty()) {
|
2024-08-22 21:26:54 +02:00
|
|
|
int[] tempIDArr = nonPersistedIDs.stream().filter(Objects::nonNull).mapToInt(i -> i).toArray();
|
|
|
|
|
nbttagcompound.setIntArray("InvisibleToNonPersistentID", tempIDArr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
nbttagcompound.setTag("InvisibleToList", list);
|
|
|
|
|
return nbttagcompound;
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public void readToNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
|
setName(nbttagcompound.getString("Name"));
|
|
|
|
|
setMarkovGeneratorId(nbttagcompound.getInteger("MarkovGeneratorId"));
|
|
|
|
|
setMarkovGender(nbttagcompound.getInteger("MarkovGender"));
|
2021-06-13 19:26:00 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
title = nbttagcompound.getString("Title");
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-03-29 17:04:10 -04:00
|
|
|
String prevUrl = url;
|
2024-02-29 22:20:35 -05:00
|
|
|
url = nbttagcompound.getString("SkinUrl");
|
2021-05-06 01:27:24 -04:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
int prevSkinType = skinType;
|
|
|
|
|
skinType = nbttagcompound.getByte("UsingSkinUrl");
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
this.playerProfile = null;
|
2025-03-12 20:12:01 -04:00
|
|
|
if (skinType == 1) {
|
|
|
|
|
if (nbttagcompound.hasKey("SkinUsername", 10)) {
|
2024-02-29 22:20:35 -05:00
|
|
|
this.playerProfile = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("SkinUsername"));
|
2025-03-12 20:12:01 -04:00
|
|
|
} else if (nbttagcompound.hasKey("SkinUsername", 8) && !StringUtils.isNullOrEmpty(nbttagcompound.getString("SkinUsername"))) {
|
2024-02-29 22:20:35 -05:00
|
|
|
this.playerProfile = new GameProfile(null, nbttagcompound.getString("SkinUsername"));
|
|
|
|
|
}
|
|
|
|
|
this.loadProfile();
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
String prevTexture = texture;
|
2024-02-29 22:20:35 -05:00
|
|
|
texture = nbttagcompound.getString("Texture");
|
|
|
|
|
|
|
|
|
|
cloakTexture = nbttagcompound.getString("CloakTexture");
|
|
|
|
|
glowTexture = nbttagcompound.getString("GlowTexture");
|
|
|
|
|
|
|
|
|
|
if (!nbttagcompound.hasKey("SkinOverlayData") && !glowTexture.isEmpty()) {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
compound.setInteger("SkinOverlayID", 0); //unique glow texture ID
|
|
|
|
|
|
|
|
|
|
(new SkinOverlay(glowTexture)).writeToNBT(compound);
|
|
|
|
|
|
|
|
|
|
if (!nbttagcompound.hasKey("SkinOverlayData")) {
|
|
|
|
|
NBTTagList tagList = new NBTTagList();
|
|
|
|
|
tagList.appendTag(compound);
|
|
|
|
|
nbttagcompound.setTag("SkinOverlayData", tagList);
|
|
|
|
|
} else if (!glowTexture.isEmpty()) {
|
|
|
|
|
nbttagcompound.getTagList("SkinOverlayData", 10).appendTag(compound);
|
|
|
|
|
glowTexture = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
skinOverlayData.readFromNBT(nbttagcompound);
|
|
|
|
|
|
|
|
|
|
animationData.readFromNBT(nbttagcompound);
|
|
|
|
|
hitboxData.readFromNBT(nbttagcompound);
|
|
|
|
|
tintData.readFromNBT(nbttagcompound);
|
|
|
|
|
|
|
|
|
|
modelSize = ValueUtil.clamp(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
|
2025-03-12 20:12:01 -04:00
|
|
|
if (modelSize > ConfigMain.NpcSizeLimit)
|
2024-02-29 22:20:35 -05:00
|
|
|
modelSize = ConfigMain.NpcSizeLimit;
|
|
|
|
|
|
|
|
|
|
modelType = nbttagcompound.getInteger("modelType");
|
|
|
|
|
|
|
|
|
|
showName = nbttagcompound.getInteger("ShowName");
|
|
|
|
|
visible = nbttagcompound.getInteger("NpcVisible");
|
|
|
|
|
|
|
|
|
|
disableLivingAnimation = nbttagcompound.getBoolean("NoLivingAnimation");
|
|
|
|
|
showBossBar = nbttagcompound.getByte("BossBar");
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
NBTTagList tagList = (NBTTagList) nbttagcompound.getTag("InvisibleToList");
|
|
|
|
|
if (tagList != null) {
|
2024-02-29 22:20:35 -05:00
|
|
|
invisibleToList.clear();
|
|
|
|
|
for (int i = 0; i < tagList.tagCount(); i++) {
|
|
|
|
|
String nbtTagString = tagList.getStringTagAt(i);
|
|
|
|
|
invisibleToList.add(UUID.fromString(nbtTagString));
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
} else {
|
2024-02-29 22:20:35 -05:00
|
|
|
invisibleToList = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
|
2024-08-22 21:26:54 +02:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (tempInvisIds == null) {
|
2024-08-22 21:26:54 +02:00
|
|
|
tempInvisIds = new HashSet<>();
|
|
|
|
|
} else {
|
|
|
|
|
tempInvisIds.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int[] tempEntityIDList = nbttagcompound.getIntArray("InvisibleToNonPersistentID");
|
|
|
|
|
final int playerID = Minecraft.getMinecraft().thePlayer.getEntityId();
|
2025-03-12 20:12:01 -04:00
|
|
|
for (int i : tempEntityIDList) {
|
|
|
|
|
if (i == playerID) {
|
2024-08-22 21:26:54 +02:00
|
|
|
isInvisibleToMe = true;
|
|
|
|
|
}
|
|
|
|
|
tempInvisIds.add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (prevSkinType != skinType || !texture.equals(prevTexture) || !url.equals(prevUrl))
|
2024-02-29 22:20:35 -05:00
|
|
|
npc.textureLocation = null;
|
|
|
|
|
npc.updateHitbox();
|
|
|
|
|
}
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void loadProfile() {
|
|
|
|
|
if (this.playerProfile != null && !StringUtils.isNullOrEmpty(this.playerProfile.getName()) && MinecraftServer.getServer() != null) {
|
|
|
|
|
if (!this.playerProfile.isComplete() || !this.playerProfile.getProperties().containsKey("textures")) {
|
2018-09-13 12:03:28 -04:00
|
|
|
GameProfile gameprofile = MinecraftServer.getServer().func_152358_ax().func_152655_a(this.playerProfile.getName());
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (gameprofile != null) {
|
|
|
|
|
Property property = (Property) Iterables.getFirst(gameprofile.getProperties().get("textures"), (Object) null);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (property == null) {
|
2018-09-13 12:03:28 -04:00
|
|
|
gameprofile = MinecraftServer.getServer().func_147130_as().fillProfileProperties(gameprofile, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.playerProfile = gameprofile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-16 16:01:32 -05:00
|
|
|
|
2024-02-29 22:20:35 -05:00
|
|
|
public boolean showName() {
|
2025-03-12 20:12:01 -04:00
|
|
|
if (npc.isKilled())
|
2024-02-29 22:20:35 -05:00
|
|
|
return false;
|
|
|
|
|
return showName == 0 || (showName == 2 && npc.isAttacking());
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public String getSkinTexture() {
|
2024-02-29 22:20:35 -05:00
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void setSkinTexture(String texture) {
|
|
|
|
|
if (this.texture.equals(texture))
|
2024-02-29 22:20:35 -05:00
|
|
|
return;
|
|
|
|
|
this.texture = texture;
|
|
|
|
|
npc.textureLocation = null;
|
|
|
|
|
skinType = 0;
|
|
|
|
|
npc.updateClient = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public String getName() {
|
2024-02-29 22:20:35 -05:00
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public void setName(String name) {
|
|
|
|
|
if (this.name.equals(name))
|
2024-02-29 22:20:35 -05:00
|
|
|
return;
|
|
|
|
|
this.name = name;
|
|
|
|
|
npc.updateClient = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public int getMarkovGender() {
|
2024-02-29 22:20:35 -05:00
|
|
|
return markovGender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMarkovGender(int gender) {
|
2025-03-12 20:12:01 -04:00
|
|
|
if (markovGender == gender)
|
2024-02-29 22:20:35 -05:00
|
|
|
return;
|
|
|
|
|
this.markovGender = ValueUtil.clamp(gender, 0, 2);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public int getMarkovGeneratorId() {
|
2024-02-29 22:20:35 -05:00
|
|
|
return markovGeneratorId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMarkovGeneratorId(int id) {
|
2025-03-12 20:12:01 -04:00
|
|
|
if (markovGeneratorId == id)
|
2024-02-29 22:20:35 -05:00
|
|
|
return;
|
2025-03-12 20:12:01 -04:00
|
|
|
this.markovGeneratorId = ValueUtil.clamp(id, 0, CustomNpcs.MARKOV_GENERATOR.length - 1);
|
2024-02-29 22:20:35 -05:00
|
|
|
}
|
2024-08-22 21:26:54 +02:00
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public boolean getTempScriptInvisible(int entityId) {
|
|
|
|
|
return tempInvisIds.contains(entityId);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|