Skip to content

Commit dba8bde

Browse files
committed
feat: use HologramEntity in GlassDisplay
1 parent caa3618 commit dba8bde

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

type.generic/src/main/java/net/swofty/type/generic/entity/hologram/HologramEntity.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99

1010
@Getter
1111
public class HologramEntity extends Entity {
12-
private String text;
12+
private Component text;
1313

14-
public HologramEntity(String text) {
14+
public HologramEntity(Component text) {
1515
super(EntityType.ARMOR_STAND);
16-
17-
text = text.replace("&", "§");
1816
this.text = text;
1917

2018
setInvisible(true);
2119
ArmorStandMeta meta = (ArmorStandMeta) this.getEntityMeta();
2220
meta.setNotifyAboutChanges(false);
23-
set(DataComponents.CUSTOM_NAME, Component.text(this.text));
21+
set(DataComponents.CUSTOM_NAME, text);
2422
meta.setNotifyAboutChanges(true);
2523

2624
editEntityMeta(ArmorStandMeta.class, m -> {
@@ -31,14 +29,21 @@ public HologramEntity(String text) {
3129
});
3230
}
3331

34-
public void setText(String text) {
35-
text = text.replace("&", "§");
32+
public HologramEntity(String text) {
33+
this(Component.text(text.replace("&", "§")));
34+
}
35+
36+
public void setText(Component text) {
3637
this.text = text;
3738

3839
ArmorStandMeta meta = (ArmorStandMeta) this.getEntityMeta();
3940

4041
meta.setNotifyAboutChanges(false);
41-
set(DataComponents.CUSTOM_NAME, Component.text(this.text));
42+
set(DataComponents.CUSTOM_NAME, text);
4243
meta.setNotifyAboutChanges(true);
4344
}
45+
46+
public void setText(String text) {
47+
setText(Component.text(text.replace("&", "§")));
48+
}
4449
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/entity/GlassDisplay.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minestom.server.instance.Instance;
1212
import net.minestom.server.instance.block.Block;
1313
import net.swofty.type.generic.entity.InteractionEntity;
14+
import net.swofty.type.generic.entity.hologram.HologramEntity;
1415
import net.swofty.type.generic.user.HypixelPlayer;
1516
import net.swofty.type.skyblockgeneric.item.SkyBlockItem;
1617
import net.swofty.type.skyblockgeneric.item.updater.NonPlayerItemUpdater;
@@ -27,7 +28,7 @@ public class GlassDisplay extends LivingEntity {
2728

2829
// Child entities that need to be removed when this display is removed
2930
private LivingEntity itemEntity;
30-
private TextDisplayEntity nameDisplay;
31+
private HologramEntity nameDisplay;
3132
private InteractionEntity interactionEntity;
3233

3334
public GlassDisplay(SkyBlockItem item, BiConsumer<HypixelPlayer, PlayerEntityInteractEvent> onClick) {
@@ -60,10 +61,8 @@ public void spawn() {
6061
itemEntity.setNoGravity(true);
6162
itemEntity.setInstance(getInstance(), getPosition().add(0.5, -0.1, 0.5));
6263

63-
nameDisplay = new TextDisplayEntity(Component.text(item.getDisplayName()), textDisplayMeta -> {
64-
textDisplayMeta.setTranslation(new Vec(0, 0.8, 0));
65-
});
66-
nameDisplay.setInstance(getInstance(), getPosition().add(0.5, 0, 0.5));
64+
nameDisplay = new HologramEntity(Component.text(item.getDisplayName()));
65+
nameDisplay.setInstance(getInstance(), getPosition().add(0.5, 0.5, 0.5));
6766

6867
interactionEntity = new InteractionEntity(scale, scale, onClick);
6968
interactionEntity.setInstance(getInstance(), getPosition().add(offset + (scale / 2), 0, offset + (scale / 2)));

0 commit comments

Comments
 (0)