forked from GeyserMC/Geyser
Fix NBT translations (for the most part)
This commit is contained in:
parent
5be882b040
commit
9399296908
2 changed files with 22 additions and 25 deletions
|
@ -29,6 +29,7 @@ Links:
|
|||
- [ ] Team-based scoreboards
|
||||
- [ ] Inventory support
|
||||
- [x] Inventory viewing
|
||||
- [x] NBT data (experimental)
|
||||
- [ ] Inventory movement (transactions)
|
||||
- [ ] Player movement support
|
||||
- [x] Entity support (experimental)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
package org.geysermc.connector.network.translators.item;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
|
@ -40,6 +41,7 @@ import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
|||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
import org.geysermc.connector.utils.Remapper;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
|
@ -53,13 +55,11 @@ public class ItemTranslator {
|
|||
public ItemStack translateToJava(ItemData data) {
|
||||
JavaItem javaItem = getJavaItem(data);
|
||||
|
||||
// TODO: Fix NBT
|
||||
// if (data.getTag() == null) {
|
||||
// return new ItemStack(javaItem.getId(), data.getCount());
|
||||
// }
|
||||
// return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
|
||||
if (data.getTag() == null) {
|
||||
return new ItemStack(javaItem.getId(), data.getCount());
|
||||
}
|
||||
return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
|
||||
}
|
||||
|
||||
public ItemData translateToBedrock(ItemStack stack) {
|
||||
// Most likely air if null
|
||||
|
@ -68,14 +68,11 @@ public class ItemTranslator {
|
|||
}
|
||||
|
||||
BedrockItem bedrockItem = getBedrockItem(stack);
|
||||
|
||||
// TODO: Fix NBT
|
||||
//if (stack.getNBT() == null) {
|
||||
// return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount());
|
||||
// }
|
||||
// return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
|
||||
if (stack.getNBT() == null) {
|
||||
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount());
|
||||
}
|
||||
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
|
||||
}
|
||||
|
||||
public BedrockItem getBedrockItem(ItemStack stack) {
|
||||
for (Map.Entry<String, JavaItem> javaItems : Toolbox.JAVA_ITEMS.entrySet()) {
|
||||
|
@ -284,24 +281,23 @@ public class ItemTranslator {
|
|||
|
||||
if (tag instanceof StringTag) {
|
||||
StringTag stringTag = (StringTag) tag;
|
||||
return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), stringTag.getValue());
|
||||
return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), MessageUtils.getBedrockMessage(Message.fromString(stringTag.getValue())));
|
||||
}
|
||||
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
|
||||
List<com.nukkitx.nbt.tag.Tag> tags = new ArrayList<com.nukkitx.nbt.tag.Tag>();
|
||||
if (listTag.getName().equalsIgnoreCase("Lore")) {
|
||||
List<com.nukkitx.nbt.tag.StringTag> tags = new ArrayList<>();
|
||||
for (Object value : listTag.getValue()) {
|
||||
if (!(value instanceof Tag))
|
||||
continue;
|
||||
|
||||
Tag tagValue = (Tag) value;
|
||||
com.nukkitx.nbt.tag.Tag bedrockTag = translateToBedrockNBT(tagValue);
|
||||
com.nukkitx.nbt.tag.StringTag bedrockTag = (com.nukkitx.nbt.tag.StringTag) translateToBedrockNBT((Tag) value);
|
||||
if (bedrockTag != null)
|
||||
tags.add(bedrockTag);
|
||||
}
|
||||
// TODO: Fix unchecked call here
|
||||
return new com.nukkitx.nbt.tag.ListTag(listTag.getName(), listTag.getElementType(), tags);
|
||||
return new com.nukkitx.nbt.tag.ListTag<>(listTag.getName(), com.nukkitx.nbt.tag.StringTag.class, tags);
|
||||
}
|
||||
}
|
||||
|
||||
if (tag instanceof CompoundTag) {
|
||||
|
|
Loading…
Reference in a new issue