Add some hologram debugging to armorstand

This commit is contained in:
fullwall 2024-07-06 17:15:54 +08:00
parent 089ffe0dfe
commit 30fed567e9

View File

@ -57,11 +57,11 @@ import net.citizensnpcs.util.Util;
*/ */
@TraitName("hologramtrait") @TraitName("hologramtrait")
public class HologramTrait extends Trait { public class HologramTrait extends Trait {
private Location currentLoc;
@Persist @Persist
private Color defaultBackgroundColor = Setting.DEFAULT_HOLOGRAM_BACKGROUND_COLOR.asString().isEmpty() ? null private Color defaultBackgroundColor = Setting.DEFAULT_HOLOGRAM_BACKGROUND_COLOR.asString().isEmpty() ? null
: Util.parseColor(Setting.DEFAULT_HOLOGRAM_BACKGROUND_COLOR.asString()); : Util.parseColor(Setting.DEFAULT_HOLOGRAM_BACKGROUND_COLOR.asString());
private double lastEntityBbHeight = 0; private double lastEntityBbHeight = 0;
private Location lastLoc;
private boolean lastNameplateVisible; private boolean lastNameplateVisible;
@Persist @Persist
private double lineHeight = -1; private double lineHeight = -1;
@ -282,10 +282,10 @@ public class HologramTrait extends Trait {
nameLine = new HologramLine(npc.getRawName(), createNameRenderer()); nameLine = new HologramLine(npc.getRawName(), createNameRenderer());
} }
} }
Location npcLoc = npc.getStoredLocation(); Location npcLoc = npc.getEntity().getLocation();
Vector3d offset = new Vector3d(); Vector3d offset = new Vector3d();
boolean updatePosition = Setting.HOLOGRAM_ALWAYS_UPDATE_POSITION.asBoolean() || currentLoc == null boolean updatePosition = Setting.HOLOGRAM_ALWAYS_UPDATE_POSITION.asBoolean() || lastLoc == null
|| currentLoc.getWorld() != npcLoc.getWorld() || currentLoc.distance(npcLoc) >= 0.001 || lastLoc.getWorld() != npcLoc.getWorld() || lastLoc.distance(npcLoc) >= 0.001
|| lastNameplateVisible != nameplateVisible || lastNameplateVisible != nameplateVisible
|| Math.abs(lastEntityBbHeight - NMS.getBoundingBoxHeight(npc.getEntity())) >= 0.05; || Math.abs(lastEntityBbHeight - NMS.getBoundingBoxHeight(npc.getEntity())) >= 0.05;
boolean updateName = false; boolean updateName = false;
@ -297,7 +297,7 @@ public class HologramTrait extends Trait {
lastNameplateVisible = nameplateVisible; lastNameplateVisible = nameplateVisible;
if (updatePosition) { if (updatePosition) {
currentLoc = npcLoc.clone(); lastLoc = npcLoc.clone();
lastEntityBbHeight = NMS.getBoundingBoxHeight(npc.getEntity()); lastEntityBbHeight = NMS.getBoundingBoxHeight(npc.getEntity());
} }
if (nameLine != null) { if (nameLine != null) {
@ -372,8 +372,7 @@ public class HologramTrait extends Trait {
addLine(text); addLine(text);
return; return;
} }
HologramLine line = lines.get(idx); lines.get(idx).setText(text);
line.setText(text);
reloadLineHolograms(); reloadLineHolograms();
} }
@ -423,7 +422,8 @@ public class HologramTrait extends Trait {
@Override @Override
protected void render0(NPC npc, Vector3d offset) { protected void render0(NPC npc, Vector3d offset) {
hologram.getEntity().teleport(npc.getStoredLocation().clone().add(offset.x, Messaging.debug(npc, offset.y, NMS.getBoundingBoxHeight(npc.getEntity()));
hologram.getEntity().teleport(npc.getEntity().getLocation().clone().add(offset.x,
offset.y + NMS.getBoundingBoxHeight(npc.getEntity()), offset.z), TeleportCause.PLUGIN); offset.y + NMS.getBoundingBoxHeight(npc.getEntity()), offset.z), TeleportCause.PLUGIN);
} }
} }
@ -704,7 +704,7 @@ public class HologramTrait extends Trait {
@Override @Override
protected void render0(NPC npc, Vector3d offset) { protected void render0(NPC npc, Vector3d offset) {
hologram.getEntity().teleport(npc.getStoredLocation().clone().add(offset.x, hologram.getEntity().teleport(npc.getEntity().getLocation().clone().add(offset.x,
offset.y + NMS.getBoundingBoxHeight(npc.getEntity()), offset.z), TeleportCause.PLUGIN); offset.y + NMS.getBoundingBoxHeight(npc.getEntity()), offset.z), TeleportCause.PLUGIN);
} }
@ -843,8 +843,8 @@ public class HologramTrait extends Trait {
disp.setBackgroundColor(color); disp.setBackgroundColor(color);
} }
hologram.getEntity().teleport( hologram.getEntity().teleport(
base.getStoredLocation().clone().add(offset.x, base.getEntity().getLocation().clone().add(offset.x,
offset.y + NMS.getBoundingBoxHeight(base.getEntity()) + 0.1f, offset.z), offset.y + NMS.getBoundingBoxHeight(base.getEntity()) + 0.2f, offset.z),
TeleportCause.PLUGIN); TeleportCause.PLUGIN);
} }