-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add further information to thread check errors
The entity data is more complete, which will help debug problems on Folia.
- Loading branch information
1 parent
cf1d26a
commit 661ef81
Showing
2 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/ca/spottedleaf/moonrise/common/util/EntityUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters