修复无人机数据处理问题,为TagDataParser添加错误处理
This commit is contained in:
parent
c39cb62469
commit
9edf8784df
2 changed files with 26 additions and 7 deletions
|
@ -413,7 +413,17 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
var rotation = attachmentData.rotation();
|
||||
|
||||
if (attachmentData.displayData() != null) {
|
||||
this.entityData.set(DISPLAY_ENTITY_TAG, TagDataParser.parse(attachmentData.displayData()));
|
||||
this.entityData.set(DISPLAY_ENTITY_TAG, TagDataParser.parse(attachmentData.displayData(), name -> {
|
||||
var uuid = player.getUUID();
|
||||
return switch (name) {
|
||||
case "@sbw:owner" -> NbtUtils.createUUID(uuid);
|
||||
case "@sbw:owner_string_lower" ->
|
||||
StringTag.valueOf(uuid.toString().replace("-", "").toLowerCase(Locale.ENGLISH));
|
||||
case "@sbw:owner_string_upper" ->
|
||||
StringTag.valueOf(uuid.toString().replace("-", "").toUpperCase(Locale.ENGLISH));
|
||||
default -> StringTag.valueOf(name);
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
this.entityData.set(DISPLAY_DATA, List.of(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.nbt.*;
|
||||
|
@ -28,9 +29,13 @@ public class TagDataParser {
|
|||
if (object == null) return tag;
|
||||
|
||||
for (var d : object.entrySet()) {
|
||||
try {
|
||||
var parsed = parse(d.getValue(), tagModifier);
|
||||
if (parsed == null) continue;
|
||||
tag.put(d.getKey(), parsed);
|
||||
} catch (Exception e) {
|
||||
Mod.LOGGER.error("Failed to parse tag {}: {}", d.getKey(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return tag;
|
||||
|
@ -48,9 +53,13 @@ public class TagDataParser {
|
|||
// 递归处理嵌套内容
|
||||
var tag = new CompoundTag();
|
||||
for (var d : object.getAsJsonObject().entrySet()) {
|
||||
try {
|
||||
var parsed = parse(d.getValue(), tagModifier);
|
||||
if (parsed == null) continue;
|
||||
tag.put(d.getKey(), parsed);
|
||||
} catch (Exception e) {
|
||||
Mod.LOGGER.error("Failed to parse tag {}: {}", d.getKey(), e);
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
} else if (object.isJsonArray()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue