Skip to content

Commit 8fdf1ec

Browse files
committed
MOVEMENT ENGINE!!!!
1 parent 2df2a81 commit 8fdf1ec

File tree

32 files changed

+3517
-13
lines changed

32 files changed

+3517
-13
lines changed

api/src/main/java/me/tofaa/entitylib/extras/skin/SFUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public static ErroredTextureProperties getTextures(String username) {
2222
InputStream stream = url.openStream();
2323
InputStreamReader isr = new InputStreamReader(stream);
2424
JsonObject root = parse(isr);
25-
UUID uuid = UUID.fromString(root.get("id").getAsString());
25+
String uuidStr = root.get("id").getAsString();
26+
UUID uuid = UUID.fromString(uuidStr.substring(0, 8) + "-" + uuidStr.substring(8, 12) + "-" + uuidStr.substring(12, 16) + "-" + uuidStr.substring(16, 20) + "-" + uuidStr.substring(20));
2627
isr.close();
2728
stream.close();
2829
return getTextures(uuid);

api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public void setHasNoGravity(boolean hasNoGravity) {
548548
*/
549549
public void addPassenger(int passenger) {
550550
if (passengers.contains(passenger)) {
551-
throw new IllegalArgumentException("Passenger already exists");
551+
return;
552552
}
553553

554554
passengers.add(passenger);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public interface Hologram {
3232

3333
@NotNull Location getLocation();
3434

35+
@NotNull me.tofaa.entitylib.wrapper.WrapperEntity getEntity();
36+
3537

3638
void show();
3739

@@ -54,6 +56,13 @@ default void addViewer(@NotNull User user) {
5456
addViewer(user.getUUID());
5557
}
5658

59+
void removeViewer(@NotNull UUID viewer);
60+
default void removeViewer(@NotNull User user) {
61+
removeViewer(user.getUUID());
62+
}
63+
64+
void setParent(@NotNull me.tofaa.entitylib.wrapper.WrapperEntity parent);
65+
5766
interface Modern extends Hologram {
5867

5968
// I got too lazy

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,31 @@ public void addViewer(@NotNull UUID viewer) {
4040
}
4141
}
4242

43+
@Override
44+
public void removeViewer(@NotNull UUID viewer) {
45+
for (WrapperEntity line : lines) {
46+
line.removeViewer(viewer);
47+
}
48+
}
49+
50+
@Override
51+
public @NotNull Location getLocation() {
52+
return location;
53+
}
54+
55+
@Override
56+
public @NotNull WrapperEntity getEntity() {
57+
return lines.isEmpty() ? null : lines.get(0);
58+
}
59+
4360
@Override
4461
public boolean isMarker() {
4562
return marker;
4663
}
4764

4865
@Override
4966
public void setMarker(boolean marker) {
50-
this.marker = true;
51-
if (lines.isEmpty()) return;
52-
teleport(location); // refresh
67+
this.marker = marker;
5368
}
5469

5570
@Override
@@ -144,8 +159,19 @@ public void setLineOffset(boolean marker, float value) {
144159
}
145160

146161
@Override
147-
public @NotNull Location getLocation() {
148-
return location;
162+
public void setParent(@NotNull WrapperEntity parent) {
163+
if (lines.isEmpty()) return;
164+
165+
WrapperEntity first = lines.get(0);
166+
for (WrapperEntity e : lines) {
167+
if (e.getUuid().equals(first.getUuid())) continue;
168+
try {
169+
first.addPassenger(e);
170+
} catch (Exception ignored) {}
171+
}
172+
try {
173+
parent.addPassenger(first);
174+
} catch (Exception ignored) {}
149175
}
150176

151177
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class ModernHologram implements Hologram.Modern {
2222
private final List<WrapperEntity> lines = new ArrayList<>(3);
2323
private Consumer<TextDisplayMeta> modifier;
2424
private boolean spawned = false;
25+
private WrapperEntity parent;
2526

2627
ModernHologram(@NotNull Location location) {
2728
this.location = location;
@@ -55,6 +56,11 @@ public void hide() {
5556
public void teleport(Location location) {
5657
this.location = location;
5758
if (lines.isEmpty()) return;
59+
60+
if (parent != null) {
61+
return;
62+
}
63+
5864
WrapperEntity first = lines.get(0);
5965
first.teleport(location);
6066
for (WrapperEntity e : lines) {
@@ -63,6 +69,23 @@ public void teleport(Location location) {
6369
}
6470
}
6571

72+
@Override
73+
public void setParent(@NotNull WrapperEntity parent) {
74+
this.parent = parent;
75+
if (lines.isEmpty()) return;
76+
77+
WrapperEntity first = lines.get(0);
78+
for (WrapperEntity e : lines) {
79+
if (e.getUuid().equals(first.getUuid())) continue;
80+
try {
81+
first.addPassenger(e);
82+
} catch (Exception ignored) {}
83+
}
84+
try {
85+
parent.addPassenger(first);
86+
} catch (Exception ignored) {}
87+
}
88+
6689
@Override
6790
public @Nullable Component getLine(int index) {
6891
if (index < 0 || index >= lines.size()) {
@@ -79,6 +102,7 @@ public void setLine(int index, @Nullable Component line) {
79102
meta.setInvisible(true);
80103
meta.setHasNoGravity(true);
81104
meta.setText(line);
105+
meta.setBillboardConstraints(me.tofaa.entitylib.meta.display.AbstractDisplayMeta.BillboardConstraints.CENTER);
82106
if (this.modifier != null) {
83107
this.modifier.accept(meta);
84108
}
@@ -110,6 +134,13 @@ public void addViewer(@NotNull UUID viewer) {
110134
}
111135
}
112136

137+
@Override
138+
public void removeViewer(@NotNull UUID viewer) {
139+
for (WrapperEntity line : lines) {
140+
line.removeViewer(viewer);
141+
}
142+
}
143+
113144

114145
@Override
115146
public int length() {
@@ -121,6 +152,11 @@ public int length() {
121152
return location;
122153
}
123154

155+
@Override
156+
public @NotNull WrapperEntity getEntity() {
157+
return lines.isEmpty() ? null : lines.get(0);
158+
}
159+
124160

125161
@Override
126162
public void setModifier(@NotNull Consumer<TextDisplayMeta> consumer) {

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.1.0"
1+
val fullVersion = "3.2.0"
22
val snapshot = true
33

44
group = "io.github.tofaa2"

movement-engine/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
entitylib.`library-conventions`
3+
}
4+
5+
description = "EntityLib Movement Engine - Pathfinding and movement for WrapperEntities"
6+
7+
repositories {
8+
maven("https://maven.pvphub.me/tofaa")
9+
maven("https://repo.papermc.io/repository/maven-public/")
10+
}
11+
12+
dependencies {
13+
compileOnly(libs.packetevents.spigot)
14+
compileOnly(libs.adventure.api)
15+
compileOnly(libs.paper)
16+
api(project(":api"))
17+
implementation(project(":common"))
18+
}

0 commit comments

Comments
 (0)