mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +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));
|
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
|
@Override
|
||||||
public Object encodeJava(Key componentType, @Nullable Object component) {
|
public Object encodeJava(Key componentType, @Nullable Object component) {
|
||||||
return ComponentType.encodeJava(componentType, component).orElse(null);
|
return ComponentType.encodeJava(componentType, component).orElse(null);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
|||||||
if (json == null) {
|
if (json == null) {
|
||||||
resetComponent(item, ComponentKeys.CUSTOM_NAME);
|
resetComponent(item, ComponentKeys.CUSTOM_NAME);
|
||||||
} else {
|
} 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) {
|
if (json == null) {
|
||||||
resetComponent(item, ComponentKeys.ITEM_NAME);
|
resetComponent(item, ComponentKeys.ITEM_NAME);
|
||||||
} else {
|
} 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) {
|
for (String json : lore) {
|
||||||
loreTags.add(ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
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