Add further information to thread check errors

The entity data is more complete, which will help debug problems
on Folia.
This commit is contained in:
Spottedleaf
2025-01-28 13:28:37 -08:00
parent a392d475c2
commit 1004374a83
2 changed files with 69 additions and 15 deletions

View File

@ -35961,3 +35961,53 @@ index 5b6bd88a5bbbce6cce351938418eba4326e41002..faf45ac459f7c25309d6ef6dce371d48
int i = -this.pendingTicks.size();
for (SavedTick<T> savedTick : this.pendingTicks) {
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/EntityUtil.java b/src/main/java/ca/spottedleaf/moonrise/common/util/EntityUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..db5805298d33fbde3f3ed23d706dbc6af814122d
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/EntityUtil.java
@@ -0,0 +1,44 @@
+package ca.spottedleaf.moonrise.common.util;
+
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.phys.Vec3;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class EntityUtil {
+
+ private static final ThreadLocal<DecimalFormat> THREE_DECIMAL_PLACES = ThreadLocal.withInitial(() -> {
+ return new DecimalFormat("#,##0.000");
+ });
+
+ private static String formatVec(final Vec3 vec) {
+ final DecimalFormat format = THREE_DECIMAL_PLACES.get();
+
+ return "(" + format.format(vec.x) + "," + format.format(vec.y) + "," + format.format(vec.z) + ")";
+ }
+
+ private static String dumpEntityWithoutReferences(final Entity entity) {
+ if (entity == null) {
+ return "{null}";
+ }
+
+ return "{type=" + entity.getClass().getSimpleName() + ",id=" + entity.getId() + ",uuid=" + entity.getUUID() + ",pos=" + formatVec(entity.position())
+ + ",mot=" + formatVec(entity.getDeltaMovement()) + ",aabb=" + entity.getBoundingBox() + ",removed=" + entity.getRemovalReason() + ",has_vehicle=" + (entity.getVehicle() != null)
+ + ",passenger_count=" + entity.getPassengers().size();
+ }
+
+ public static String dumpEntity(final Entity entity) {
+ final List<Entity> passengers = entity.getPassengers();
+ final List<String> passengerStrings = new ArrayList<>(passengers.size());
+
+ for (final Entity passenger : passengers) {
+ passengerStrings.add("(" + dumpEntityWithoutReferences(passenger) + ")");
+ }
+
+ return "{root=[" + dumpEntityWithoutReferences(entity) + "], vehicle=[" + dumpEntityWithoutReferences(entity.getVehicle())
+ + "], passengers=[" + String.join(",", passengerStrings) + "]";
+ }
+
+ private EntityUtil() {}
+}