Skip to content

Commit

Permalink
Change default name renderer to interaction instead of text displays
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 20, 2024
1 parent 3370fdd commit c9696cc
Showing 1 changed file with 8 additions and 38 deletions.
46 changes: 8 additions & 38 deletions main/src/main/java/net/citizensnpcs/trait/HologramTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ private HologramRenderer createNameRenderer() {
HologramRenderer renderer;
String setting = Setting.DEFAULT_NAME_HOLOGRAM_RENDERER.asString();
if (setting.isEmpty()) {
if (SpigotUtil.getVersion()[1] >= 20) {
setting = "display_vehicle";
} else if (SpigotUtil.getVersion()[1] == 19) {
if (SpigotUtil.getVersion()[1] >= 19) {
setting = "interaction";
} else {
setting = "armorstand";
Expand Down Expand Up @@ -546,14 +544,14 @@ public static interface HologramRenderer {
* sees the NPC (i.e. not proactively).Note: this should be async-safe. This method is fragile and may be moved
* elsewhere.
*
* @param hologram
* the <em>hologram</em> NPC
* @param npc
* the NPC
* @param player
* the viewing Player
* @return whether the NPC is sneaking
*/
default boolean isSneaking(NPC hologram, Player player) {
return NMS.isSneaking(player);
default boolean isSneaking(NPC npc, Player player) {
return NMS.isSneaking(npc.getEntity());
}

/**
Expand Down Expand Up @@ -895,46 +893,18 @@ public void updateText(NPC npc, String raw) {
}
}

public static class TextDisplayVehicleRenderer extends SingleEntityHologramRenderer {
private Color color;

@Override
protected NPC createNPC(Entity base, String name, Vector3d offset) {
NPC hologram = registry().createNPC(EntityType.TEXT_DISPLAY, "");
hologram.data().set(NPC.Metadata.NAMEPLATE_VISIBLE, false);
hologram.data().set(NPC.Metadata.TEXT_DISPLAY_COMPONENT, Messaging.minecraftComponentFromRawMessage(name));
return hologram;
}

public static class TextDisplayVehicleRenderer extends TextDisplayRenderer {
@Override
public void render0(NPC npc, Vector3d offset) {
super.render0(npc, offset);
TextDisplay disp = (TextDisplay) hologram.getEntity();
disp.setInterpolationDelay(0);
disp.setInterpolationDuration(0);
disp.setBillboard(Billboard.CENTER);
Transformation tf = disp.getTransformation();
tf.getTranslation().y = (float) offset.y + 0.34f;
tf.getTranslation().y = (float) offset.y + 0.2f;
disp.setTransformation(tf);
if (color != null) {
disp.setBackgroundColor(color);
}
if (hologram.getEntity().getVehicle() == null) {
NMS.mount(npc.getEntity(), hologram.getEntity());
}
}

@Override
public void setBackgroundColor(Color color) {
this.color = color;
}

@Override
public void updateText(NPC npc, String raw) {
this.text = Placeholders.replace(raw, null, npc);
if (hologram == null)
return;
hologram.data().set(NPC.Metadata.TEXT_DISPLAY_COMPONENT, Messaging.minecraftComponentFromRawMessage(text));
}
}

private static final Pattern ITEM_MATCHER = Pattern.compile("<item:([a-zA-Z0-9_ ]*?)([:].*?)?>");
Expand Down

0 comments on commit c9696cc

Please sign in to comment.