9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +00:00

修复NBT parser

This commit is contained in:
XiaoMoMi
2025-04-14 04:26:12 +08:00
parent d693e5f31c
commit b5505ec06d
2 changed files with 7 additions and 3 deletions

View File

@@ -67,6 +67,10 @@ public class ComponentItemFactory extends BukkitItemFactory {
ComponentType.parseJson(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type), it));
}
protected void setNBTComponentDirectly(ItemWrapper<ItemStack> item, Key type, Object value) {
ComponentType.parseNbt(type, value).ifPresent(it -> FastNMS.INSTANCE.setComponent(item.getLiteralObject(), KeyUtils.toResourceLocation(type), it));
}
@Override
public Object encodeJava(Key componentType, @Nullable Object component) {
return ComponentType.encodeJava(componentType, component).orElse(null);

View File

@@ -28,7 +28,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
if (json == null) {
resetComponent(item, ComponentKeys.CUSTOM_NAME);
} else {
setJavaComponentDirectly(item, ComponentKeys.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
setNBTComponentDirectly(item, ComponentKeys.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
}
@@ -43,7 +43,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
if (json == null) {
resetComponent(item, ComponentKeys.ITEM_NAME);
} else {
setJavaComponentDirectly(item, ComponentKeys.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
setNBTComponentDirectly(item, ComponentKeys.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
}
@@ -77,7 +77,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
for (String json : lore) {
loreTags.add(ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
setJavaComponentDirectly(item, ComponentKeys.LORE, TagList.newTag(loreTags));
setNBTComponentDirectly(item, ComponentKeys.LORE, TagList.newTag(loreTags));
}
}
}