Skip to content

Commit d2ba24f

Browse files
committed
Misc fixes
1 parent 8fdf1ec commit d2ba24f

19 files changed

Lines changed: 3082 additions & 441 deletions

api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323

2424
public class EntityMeta implements EntityMetadataProvider {
2525

26-
private static final MetaConverterRegistry registry = new MetaConverterRegistry();
26+
static final MetaConverterRegistry META_CONVERTER_REGISTRY = new MetaConverterRegistry();
2727

2828
public static @NotNull BiFunction<Integer, Metadata, EntityMeta> getConverter(EntityType entityType) {
29-
return registry.get(entityType);
29+
return META_CONVERTER_REGISTRY.get(entityType);
3030
}
3131

3232
public static @NotNull Class<? extends EntityMeta> getMetaClass(EntityType entityType) {
33-
return registry.getMetaClass(entityType);
33+
return META_CONVERTER_REGISTRY.getMetaClass(entityType);
34+
}
35+
36+
public static boolean isLivingEntity(EntityType type) {
37+
return META_CONVERTER_REGISTRY.isLivingEntity(type);
3438
}
3539

3640
public static @NotNull EntityMeta createMeta(int entityId, EntityType entityType) {

api/src/main/java/me/tofaa/entitylib/meta/MetaConverterRegistry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ final class MetaConverterRegistry {
9999
put(GLOW_SQUID, GlowSquidMeta.class, GlowSquidMeta::new);
100100
put(GOAT, GoatMeta.class, GoatMeta::new);
101101
put(GUARDIAN, GuardianMeta.class, GuardianMeta::new);
102-
put(HAPPY_GHAST, GhastMeta.class, GhastMeta::new); // TODO: Implement
103102
put(HOGLIN, HoglinMeta.class, HoglinMeta::new);
104103
put(HOPPER_MINECART, FurnaceMinecartMeta.class, FurnaceMinecartMeta::new);
105104
put(HORSE, HorseMeta.class, HorseMeta::new);
@@ -191,4 +190,9 @@ public Class<? extends EntityMeta> getMetaClass(EntityType entityType) {
191190
return converters.getOrDefault(entityType, EntityMeta::new);
192191
}
193192

193+
public boolean isLivingEntity(EntityType type) {
194+
Class<? extends EntityMeta> m = getMetaClass(type);
195+
return LivingEntityMeta.class.isAssignableFrom(m);
196+
}
197+
194198
}

api/src/main/java/me/tofaa/entitylib/wrapper/hologram/Hologram.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public interface Hologram {
4343

4444
@Nullable Component getLine(int index);
4545

46+
boolean updateLineContent(int idx, @NotNull Component line);
47+
48+
void setLines(List<Component> lines);
49+
4650
int length();
4751

4852
void setLine(int index, @Nullable Component line);

api/src/main/java/me/tofaa/entitylib/wrapper/hologram/LegacyHologram.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class LegacyHologram implements Hologram.Legacy {
2121
private float lineOffset = -0.9875f;
2222
private float markerOffset = -0.40625f;
2323
private boolean marker;
24+
private boolean spawned = false;
2425

2526
LegacyHologram(@NotNull Location location) {
2627
this.location = location;
@@ -40,6 +41,59 @@ public void addViewer(@NotNull UUID viewer) {
4041
}
4142
}
4243

44+
@Override
45+
public boolean updateLineContent(int index, @NotNull Component line) {
46+
if (index < 0 || index >= lines.size()) {
47+
return false;
48+
}
49+
ArmorStandMeta meta = (ArmorStandMeta) lines.get(index).getEntityMeta();
50+
meta.setCustomName(line);
51+
return true;
52+
}
53+
54+
@Override
55+
public void setLines(List<Component> newLines) {
56+
int existingCount = lines.size();
57+
int newCount = newLines.size();
58+
59+
if (newCount == 0) {
60+
for (WrapperEntity line : lines) {
61+
line.remove();
62+
}
63+
lines.clear();
64+
return;
65+
}
66+
67+
for (int i = 0; i < Math.min(existingCount, newCount); i++) {
68+
ArmorStandMeta meta = (ArmorStandMeta) lines.get(i).getEntityMeta();
69+
meta.setCustomName(newLines.get(i));
70+
}
71+
72+
for (int i = existingCount - 1; i >= newCount; i--) {
73+
lines.get(i).remove();
74+
lines.remove(i);
75+
}
76+
77+
for (int i = existingCount; i < newCount; i++) {
78+
WrapperEntity e = new WrapperEntity(EntityTypes.ARMOR_STAND);
79+
ArmorStandMeta meta = (ArmorStandMeta) e.getEntityMeta();
80+
meta.setCustomName(newLines.get(i));
81+
meta.setCustomNameVisible(true);
82+
meta.setInvisible(true);
83+
meta.setHasNoGravity(true);
84+
meta.setSmall(true);
85+
meta.setMarker(marker);
86+
if (spawned) {
87+
e.spawn(location);
88+
}
89+
lines.add(e);
90+
}
91+
92+
if (spawned) {
93+
teleport(location);
94+
}
95+
}
96+
4397
@Override
4498
public void removeViewer(@NotNull UUID viewer) {
4599
for (WrapperEntity line : lines) {
@@ -73,13 +127,15 @@ public void show() {
73127
line.spawn(location);
74128
}
75129
teleport(location);
130+
spawned = true;
76131
}
77132

78133
@Override
79134
public void hide() {
80135
for (WrapperEntity line : lines) {
81136
line.despawn();
82137
}
138+
spawned = false;
83139
}
84140

85141
@Override

api/src/main/java/me/tofaa/entitylib/wrapper/hologram/ModernHologram.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,67 @@ public void setParent(@NotNull WrapperEntity parent) {
8686
} catch (Exception ignored) {}
8787
}
8888

89+
@Override
90+
public boolean updateLineContent(int index, @NotNull Component line) {
91+
if (index < 0 || index >= lines.size()) {
92+
return false;
93+
}
94+
TextDisplayMeta meta = (TextDisplayMeta) lines.get(index).getEntityMeta();
95+
meta.setText(line);
96+
return true;
97+
}
98+
99+
@Override
100+
public void setLines(List<Component> newLines) {
101+
int existingCount = lines.size();
102+
int newCount = newLines.size();
103+
104+
if (newCount == 0) {
105+
for (WrapperEntity line : lines) {
106+
line.remove();
107+
}
108+
lines.clear();
109+
return;
110+
}
111+
112+
for (int i = 0; i < Math.min(existingCount, newCount); i++) {
113+
TextDisplayMeta meta = (TextDisplayMeta) lines.get(i).getEntityMeta();
114+
meta.setText(newLines.get(i));
115+
}
116+
117+
for (int i = existingCount - 1; i >= newCount; i--) {
118+
lines.get(i).remove();
119+
lines.remove(i);
120+
}
121+
122+
for (int i = existingCount; i < newCount; i++) {
123+
WrapperEntity e = new WrapperEntity(EntityTypes.TEXT_DISPLAY);
124+
TextDisplayMeta meta = (TextDisplayMeta) e.getEntityMeta();
125+
meta.setInvisible(true);
126+
meta.setHasNoGravity(true);
127+
meta.setText(newLines.get(i));
128+
meta.setBillboardConstraints(me.tofaa.entitylib.meta.display.AbstractDisplayMeta.BillboardConstraints.CENTER);
129+
if (this.modifier != null) {
130+
this.modifier.accept(meta);
131+
}
132+
if (spawned) {
133+
e.spawn(location);
134+
}
135+
lines.add(e);
136+
}
137+
138+
if (spawned && parent == null) {
139+
teleport(location);
140+
}
141+
}
142+
89143
@Override
90144
public @Nullable Component getLine(int index) {
91145
if (index < 0 || index >= lines.size()) {
92146
return null;
93147
}
94-
return lines.get(index).getEntityMeta().getCustomName();
148+
TextDisplayMeta meta = (TextDisplayMeta) lines.get(index).getEntityMeta();
149+
return meta.getText();
95150
}
96151

97152
@Override

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val fullVersion = "3.2.0"
1+
val fullVersion = "3.2.1"
22
val snapshot = true
33

44
group = "io.github.tofaa2"

spaceNPC/build.gradle.kts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
plugins {
22
id("java")
33
entitylib.`shadow-conventions`
4+
5+
entitylib.`library-conventions`
46
alias(libs.plugins.run.paper)
57
}
68

@@ -17,7 +19,7 @@ repositories {
1719

1820
dependencies {
1921
compileOnly(libs.paper)
20-
implementation(libs.packetevents.spigot)
22+
compileOnly(libs.packetevents.spigot)
2123
compileOnly(libs.adventure.api)
2224
implementation(project(":platforms:spigot"))
2325
implementation(project(":movement-engine"))
@@ -28,6 +30,12 @@ tasks {
2830
val version = "1.21.3"
2931
val javaVersion = JavaLanguageVersion.of(21)
3032

33+
// shadowJar {
34+
// relocate("io.github.retrooper", "me.tofaa.npc.thirdparty.retrooper")
35+
// relocate("com.github.retrooper", "me.tofaa.npc.thirdparty.retrooper")
36+
// mergeServiceFiles()
37+
// }
38+
3139
val packetEvents = runPaper.downloadPluginsSpec {
3240
modrinth("packetevents", "3Jr8ovul")
3341
}
@@ -43,10 +51,3 @@ tasks {
4351
}
4452
}
4553
}
46-
47-
//tasks {
48-
// shadowJar {
49-
// relocate("io.github.retrooper", "me.tofaa.npc.thirdparty.retrooper")
50-
// relocate("com.github.retrooper", "me.tofaa.npc.thirdparty.retrooper")
51-
// }
52-
//}

0 commit comments

Comments
 (0)