mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
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
|
- [ ] Team-based scoreboards
|
||||||
- [ ] Inventory support
|
- [ ] Inventory support
|
||||||
- [x] Inventory viewing
|
- [x] Inventory viewing
|
||||||
|
- [x] NBT data (experimental)
|
||||||
- [ ] Inventory movement (transactions)
|
- [ ] Inventory movement (transactions)
|
||||||
- [ ] Player movement support
|
- [ ] Player movement support
|
||||||
- [x] Entity support (experimental)
|
- [x] Entity support (experimental)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package org.geysermc.connector.network.translators.item;
|
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.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.ByteArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
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.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||||
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
import org.geysermc.connector.utils.Remapper;
|
import org.geysermc.connector.utils.Remapper;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
|
@ -53,13 +55,11 @@ public class ItemTranslator {
|
||||||
public ItemStack translateToJava(ItemData data) {
|
public ItemStack translateToJava(ItemData data) {
|
||||||
JavaItem javaItem = getJavaItem(data);
|
JavaItem javaItem = getJavaItem(data);
|
||||||
|
|
||||||
// TODO: Fix NBT
|
if (data.getTag() == null) {
|
||||||
// if (data.getTag() == null) {
|
|
||||||
// return new ItemStack(javaItem.getId(), data.getCount());
|
|
||||||
// }
|
|
||||||
// return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
|
|
||||||
return new ItemStack(javaItem.getId(), data.getCount());
|
return new ItemStack(javaItem.getId(), data.getCount());
|
||||||
}
|
}
|
||||||
|
return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
|
||||||
|
}
|
||||||
|
|
||||||
public ItemData translateToBedrock(ItemStack stack) {
|
public ItemData translateToBedrock(ItemStack stack) {
|
||||||
// Most likely air if null
|
// Most likely air if null
|
||||||
|
@ -68,14 +68,11 @@ public class ItemTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
BedrockItem bedrockItem = getBedrockItem(stack);
|
BedrockItem bedrockItem = getBedrockItem(stack);
|
||||||
|
if (stack.getNBT() == null) {
|
||||||
// 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()));
|
|
||||||
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount());
|
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) {
|
public BedrockItem getBedrockItem(ItemStack stack) {
|
||||||
for (Map.Entry<String, JavaItem> javaItems : Toolbox.JAVA_ITEMS.entrySet()) {
|
for (Map.Entry<String, JavaItem> javaItems : Toolbox.JAVA_ITEMS.entrySet()) {
|
||||||
|
@ -284,24 +281,23 @@ public class ItemTranslator {
|
||||||
|
|
||||||
if (tag instanceof StringTag) {
|
if (tag instanceof StringTag) {
|
||||||
StringTag stringTag = (StringTag) tag;
|
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) {
|
if (tag instanceof ListTag) {
|
||||||
ListTag listTag = (ListTag) tag;
|
ListTag listTag = (ListTag) tag;
|
||||||
|
if (listTag.getName().equalsIgnoreCase("Lore")) {
|
||||||
List<com.nukkitx.nbt.tag.Tag> tags = new ArrayList<com.nukkitx.nbt.tag.Tag>();
|
List<com.nukkitx.nbt.tag.StringTag> tags = new ArrayList<>();
|
||||||
for (Object value : listTag.getValue()) {
|
for (Object value : listTag.getValue()) {
|
||||||
if (!(value instanceof Tag))
|
if (!(value instanceof Tag))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Tag tagValue = (Tag) value;
|
com.nukkitx.nbt.tag.StringTag bedrockTag = (com.nukkitx.nbt.tag.StringTag) translateToBedrockNBT((Tag) value);
|
||||||
com.nukkitx.nbt.tag.Tag bedrockTag = translateToBedrockNBT(tagValue);
|
|
||||||
if (bedrockTag != null)
|
if (bedrockTag != null)
|
||||||
tags.add(bedrockTag);
|
tags.add(bedrockTag);
|
||||||
}
|
}
|
||||||
// TODO: Fix unchecked call here
|
return new com.nukkitx.nbt.tag.ListTag<>(listTag.getName(), com.nukkitx.nbt.tag.StringTag.class, tags);
|
||||||
return new com.nukkitx.nbt.tag.ListTag(listTag.getName(), listTag.getElementType(), tags);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag instanceof CompoundTag) {
|
if (tag instanceof CompoundTag) {
|
||||||
|
|
Loading…
Reference in a new issue