Skip to content

Commit b704d30

Browse files
fix(clientmod): null-guard entity data scan in ravengard session logger
getNonDefaultValues returns null rather than an empty list when an entity carries no non-default data, and the rig discovery scan touches every display in the level, so the first plain display crashed the client tick. Guards all three call sites and wraps the tick body so a logger fault degrades to a chat error instead of a crash.
1 parent 1eb1229 commit b704d30

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

clientmod/src/main/java/gg/itzkatze/thehypixelrecreationmod/features/packetlog/RavengardSessionLogger.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ public static void tick() {
122122
if (!active) {
123123
return;
124124
}
125+
try {
126+
tickInternal();
127+
} catch (RuntimeException exception) {
128+
ChatUtils.error("Ravengard session logger tick failed: " + exception);
129+
}
130+
}
125131

132+
private static void tickInternal() {
126133
Minecraft client = Minecraft.getInstance();
127134
if (client.level == null) {
128135
StopResult result = stop();
@@ -165,7 +172,11 @@ private static void discoverRigs(Minecraft client) {
165172
}
166173

167174
private static String rigModel(Entity entity) {
168-
for (SynchedEntityData.DataValue<?> value : entity.getEntityData().getNonDefaultValues()) {
175+
List<SynchedEntityData.DataValue<?>> values = entity.getEntityData().getNonDefaultValues();
176+
if (values == null) {
177+
return null;
178+
}
179+
for (SynchedEntityData.DataValue<?> value : values) {
169180
if (value.value() instanceof ItemStack stack && !stack.isEmpty()) {
170181
var model = stack.get(DataComponents.ITEM_MODEL);
171182
if (model != null && model.toString().startsWith(RIG_MODEL_PREFIX)) {
@@ -188,8 +199,11 @@ private static void addEntity(Entity entity, String reason) {
188199
+ " uuid=" + entity.getUUID()
189200
+ " pos=vec3(" + entity.getX() + "," + entity.getY() + "," + entity.getZ() + ")");
190201
writeLine("# reason: " + reason);
191-
for (SynchedEntityData.DataValue<?> value : entity.getEntityData().getNonDefaultValues()) {
192-
writeLine("# data " + value.id() + " = " + formatValue(value.value()));
202+
List<SynchedEntityData.DataValue<?>> values = entity.getEntityData().getNonDefaultValues();
203+
if (values != null) {
204+
for (SynchedEntityData.DataValue<?> value : values) {
205+
writeLine("# data " + value.id() + " = " + formatValue(value.value()));
206+
}
193207
}
194208

195209
for (Entity passenger : entity.getPassengers()) {
@@ -234,8 +248,10 @@ private static void sampleTrack(Minecraft client) {
234248
.append(",\"z\":").append(fmt(entity.getZ()))
235249
.append(",\"yaw\":").append(fmt(entity.getYRot()));
236250

237-
if (entity instanceof Display display) {
238-
for (SynchedEntityData.DataValue<?> value : display.getEntityData().getNonDefaultValues()) {
251+
List<SynchedEntityData.DataValue<?>> displayValues =
252+
entity instanceof Display display ? display.getEntityData().getNonDefaultValues() : null;
253+
if (displayValues != null) {
254+
for (SynchedEntityData.DataValue<?> value : displayValues) {
239255
Object raw = value.value();
240256
if (raw instanceof Vector3fc vector) {
241257
json.append(",\"d").append(value.id()).append("\":[")

0 commit comments

Comments
 (0)