Track reopened supply chests and fix API snapshots

This commit is contained in:
Tanner
2026-11-07 17:02:29 +00:00
parent 43b37b76f6
commit 9251edc36a
8 changed files with 280 additions and 7 deletions
+19 -1
View File
@@ -94,6 +94,24 @@ def _api_plain(value, depth=0):
return str(value)
def _api_json_safe(value, depth=0):
"""Normalize snapshots for JSON, including non-string dictionary keys."""
if depth > 12:
return '[nested data omitted]'
if value is None or isinstance(value, (str, int, float, bool)):
return value
if isinstance(value, dict):
return {str(key): _api_json_safe(item, depth + 1)
for key, item in value.items()}
if isinstance(value, (list, tuple, set)):
return [_api_json_safe(item, depth + 1) for item in value]
converted = _api_json_default(value)
if converted is value:
return str(value)
return _api_json_safe(converted, depth + 1)
def _api_json_default(value):
"""Serialize live protocol objects without invoking fragile __repr__ code."""
from minecraft.networking.packets import Packet
@@ -133,7 +151,7 @@ def api_global():
'dimension': chunks.dimension,
}
response = app.response_class(
response=json.dumps(snapshot, default=_api_json_default),
response=json.dumps(_api_json_safe(snapshot)),
status=200,
mimetype='application/json'
)