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:
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user