Update to Cloudburst NBT 2.0

This commit is contained in:
RednedEpic 2020-07-05 15:58:43 -05:00
parent 5958b5d0ba
commit da1674c8d6
39 changed files with 550 additions and 584 deletions

View file

@ -31,7 +31,9 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
@ -49,7 +51,6 @@ public class FireworkEntity extends Entity {
super(entityId, geyserId, entityType, position, motion, rotation); super(entityId, geyserId, entityType, position, motion, rotation);
} }
@Override @Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 7) { if (entityMetadata.getId() == 7) {
@ -62,19 +63,19 @@ public class FireworkEntity extends Entity {
CompoundTag fireworks = tag.get("Fireworks"); CompoundTag fireworks = tag.get("Fireworks");
CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder(); NbtMapBuilder fireworksBuilder = NbtMap.builder();
if (fireworks.get("Flight") != null) { if (fireworks.get("Flight") != null) {
fireworksBuilder.byteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())); fireworksBuilder.putByte("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue()));
} }
List<com.nukkitx.nbt.tag.CompoundTag> explosions = new ArrayList<>(); List<NbtMap> explosions = new ArrayList<>();
if (fireworks.get("Explosions") != null) { if (fireworks.get("Explosions") != null) {
for (Tag effect : ((ListTag) fireworks.get("Explosions")).getValue()) { for (Tag effect : ((ListTag) fireworks.get("Explosions")).getValue()) {
CompoundTag effectData = (CompoundTag) effect; CompoundTag effectData = (CompoundTag) effect;
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder(); NbtMapBuilder effectBuilder = NbtMap.builder();
if (effectData.get("Type") != null) { if (effectData.get("Type") != null) {
effectBuilder.byteTag("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue())); effectBuilder.putByte("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue()));
} }
if (effectData.get("Colors") != null) { if (effectData.get("Colors") != null) {
@ -86,7 +87,7 @@ public class FireworkEntity extends Entity {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
} }
effectBuilder.byteArrayTag("FireworkColor", colors); effectBuilder.putByteArray("FireworkColor", colors);
} }
if (effectData.get("FadeColors") != null) { if (effectData.get("FadeColors") != null) {
@ -98,24 +99,24 @@ public class FireworkEntity extends Entity {
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID(); colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
} }
effectBuilder.byteArrayTag("FireworkFade", colors); effectBuilder.putByteArray("FireworkFade", colors);
} }
if (effectData.get("Trail") != null) { if (effectData.get("Trail") != null) {
effectBuilder.byteTag("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue())); effectBuilder.putByte("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue()));
} }
if (effectData.get("Flicker") != null) { if (effectData.get("Flicker") != null) {
effectBuilder.byteTag("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue())); effectBuilder.putByte("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue()));
} }
explosions.add(effectBuilder.buildRootTag()); explosions.add(effectBuilder.build());
} }
} }
fireworksBuilder.tag(new com.nukkitx.nbt.tag.ListTag<>("Explosions", com.nukkitx.nbt.tag.CompoundTag.class, explosions)); fireworksBuilder.putList("Explosions", NbtType.COMPOUND, explosions);
metadata.put(EntityData.DISPLAY_ITEM, CompoundTagBuilder.builder().tag(fireworksBuilder.build("Fireworks")).buildRootTag()); metadata.put(EntityData.DISPLAY_ITEM, NbtMap.builder().put("Fireworks", fireworksBuilder.build()));
} else if (entityMetadata.getId() == 8 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) { } else if (entityMetadata.getId() == 8 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) {
//Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too. //Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too.
PlayerEntity entity = session.getPlayerEntity(); PlayerEntity entity = session.getPlayerEntity();

View file

@ -30,8 +30,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.entity.object.HangingDirection; import com.github.steveice10.mc.protocol.data.game.entity.object.HangingDirection;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
@ -66,21 +66,21 @@ public class ItemFrameEntity extends Entity {
/** /**
* Cached item frame's Bedrock compound tag. * Cached item frame's Bedrock compound tag.
*/ */
private CompoundTag cachedTag; private NbtMap cachedTag;
public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, HangingDirection direction) { public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, HangingDirection direction) {
super(entityId, geyserId, entityType, position, motion, rotation); super(entityId, geyserId, entityType, position, motion, rotation);
CompoundTagBuilder builder = CompoundTag.builder(); NbtMapBuilder builder = NbtMap.builder();
builder.tag(CompoundTag.builder() NbtMapBuilder blockBuilder = NbtMap.builder()
.stringTag("name", "minecraft:frame") .putString("name", "minecraft:frame")
.intTag("version", BlockTranslator.getBlockStateVersion()) .putInt("version", BlockTranslator.getBlockStateVersion());
.tag(CompoundTag.builder() blockBuilder.put("states", NbtMap.builder()
.intTag("facing_direction", direction.ordinal()) .putInt("facing_direction", direction.ordinal())
.byteTag("item_frame_map_bit", (byte) 0) .putByte("item_frame_map_bit", (byte) 0)
.build("states")) .build());
.build("block")); builder.put("block", blockBuilder.build());
builder.shortTag("id", (short) 199); builder.putShort("id", (short) 199);
bedrockRuntimeId = BlockTranslator.getItemFrame(builder.buildRootTag()); bedrockRuntimeId = BlockTranslator.getItemFrame(builder.build());
bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ()); bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ());
} }
@ -100,7 +100,7 @@ public class ItemFrameEntity extends Entity {
if (entityMetadata.getId() == 7 && entityMetadata.getValue() != null) { if (entityMetadata.getId() == 7 && entityMetadata.getValue() != null) {
ItemData itemData = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue()); ItemData itemData = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue()); ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue());
CompoundTagBuilder builder = CompoundTag.builder(); NbtMapBuilder builder = NbtMap.builder();
String blockName = ""; String blockName = "";
for (StartGamePacket.ItemEntry startGamePacketItemEntry : ItemRegistry.ITEMS) { for (StartGamePacket.ItemEntry startGamePacketItemEntry : ItemRegistry.ITEMS) {
@ -110,17 +110,17 @@ public class ItemFrameEntity extends Entity {
} }
} }
builder.byteTag("Count", (byte) itemData.getCount()); builder.putByte("Count", (byte) itemData.getCount());
if (itemData.getTag() != null) { if (itemData.getTag() != null) {
builder.tag(itemData.getTag().toBuilder().build("tag")); builder.put("tag", itemData.getTag().toBuilder().build());
} }
builder.shortTag("Damage", itemData.getDamage()); builder.putShort("Damage", itemData.getDamage());
builder.stringTag("Name", blockName); builder.putString("Name", blockName);
CompoundTagBuilder tag = getDefaultTag().toBuilder(); NbtMapBuilder tag = getDefaultTag().toBuilder();
tag.tag(builder.build("Item")); tag.put("Item", builder.build());
tag.floatTag("ItemDropChance", 1.0f); tag.putFloat("ItemDropChance", 1.0f);
tag.floatTag("ItemRotation", rotation); tag.putFloat("ItemRotation", rotation);
cachedTag = tag.buildRootTag(); cachedTag = tag.build();
updateBlock(session); updateBlock(session);
} }
else if (entityMetadata.getId() == 7 && entityMetadata.getValue() == null && cachedTag != null) { else if (entityMetadata.getId() == 7 && entityMetadata.getValue() == null && cachedTag != null) {
@ -133,9 +133,9 @@ public class ItemFrameEntity extends Entity {
updateBlock(session); updateBlock(session);
return; return;
} }
CompoundTagBuilder builder = cachedTag.toBuilder(); NbtMapBuilder builder = cachedTag.toBuilder();
builder.floatTag("ItemRotation", rotation); builder.putFloat("ItemRotation", rotation);
cachedTag = builder.buildRootTag(); cachedTag = builder.build();
updateBlock(session); updateBlock(session);
} }
else { else {
@ -158,14 +158,14 @@ public class ItemFrameEntity extends Entity {
return true; return true;
} }
private CompoundTag getDefaultTag() { private NbtMap getDefaultTag() {
CompoundTagBuilder builder = CompoundTag.builder(); NbtMapBuilder builder = NbtMap.builder();
builder.intTag("x", bedrockPosition.getX()); builder.putInt("x", bedrockPosition.getX());
builder.intTag("y", bedrockPosition.getY()); builder.putInt("y", bedrockPosition.getY());
builder.intTag("z", bedrockPosition.getZ()); builder.putInt("z", bedrockPosition.getZ());
builder.byteTag("isMovable", (byte) 1); builder.putByte("isMovable", (byte) 1);
builder.stringTag("id", "ItemFrame"); builder.putString("id", "ItemFrame");
return builder.buildRootTag(); return builder.build();
} }
/** /**

View file

@ -218,11 +218,11 @@ public class GeyserSession implements CommandSender {
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket(); BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
biomeDefinitionListPacket.setTag(BiomeTranslator.BIOMES); biomeDefinitionListPacket.setDefinitions(BiomeTranslator.BIOMES);
upstream.sendPacket(biomeDefinitionListPacket); upstream.sendPacket(biomeDefinitionListPacket);
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket(); AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
entityPacket.setTag(EntityIdentifierRegistry.ENTITY_IDENTIFIERS); entityPacket.setIdentifiers(EntityIdentifierRegistry.ENTITY_IDENTIFIERS);
upstream.sendPacket(entityPacket); upstream.sendPacket(entityPacket);
CreativeContentPacket creativePacket = new CreativeContentPacket(); CreativeContentPacket creativePacket = new CreativeContentPacket();

View file

@ -26,9 +26,9 @@
package org.geysermc.connector.network.translators; package org.geysermc.connector.network.translators;
import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
@ -40,7 +40,7 @@ import java.util.Arrays;
// Array index formula by https://wiki.vg/Chunk_Format // Array index formula by https://wiki.vg/Chunk_Format
public class BiomeTranslator { public class BiomeTranslator {
public static final CompoundTag BIOMES; public static final NbtMap BIOMES;
private BiomeTranslator() { private BiomeTranslator() {
} }
@ -53,10 +53,10 @@ public class BiomeTranslator {
/* Load biomes */ /* Load biomes */
InputStream stream = FileUtils.getResource("bedrock/biome_definitions.dat"); InputStream stream = FileUtils.getResource("bedrock/biome_definitions.dat");
CompoundTag biomesTag; NbtMap biomesTag;
try (NBTInputStream biomenbtInputStream = NbtUtils.createNetworkReader(stream)) { try (NBTInputStream biomenbtInputStream = NbtUtils.createNetworkReader(stream)) {
biomesTag = (CompoundTag) biomenbtInputStream.readTag(); biomesTag = (NbtMap) biomenbtInputStream.readTag();
BIOMES = biomesTag; BIOMES = biomesTag;
} catch (Exception ex) { } catch (Exception ex) {
GeyserConnector.getInstance().getLogger().warning("Failed to get biomes from biome definitions, is there something wrong with the file?"); GeyserConnector.getInstance().getLogger().warning("Failed to get biomes from biome definitions, is there something wrong with the file?");

View file

@ -26,9 +26,9 @@
package org.geysermc.connector.network.translators; package org.geysermc.connector.network.translators;
import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
import java.io.InputStream; import java.io.InputStream;
@ -38,7 +38,7 @@ import java.io.InputStream;
*/ */
public class EntityIdentifierRegistry { public class EntityIdentifierRegistry {
public static CompoundTag ENTITY_IDENTIFIERS; public static NbtMap ENTITY_IDENTIFIERS;
private EntityIdentifierRegistry() { private EntityIdentifierRegistry() {
} }
@ -52,7 +52,7 @@ public class EntityIdentifierRegistry {
InputStream stream = FileUtils.getResource("bedrock/entity_identifiers.dat"); InputStream stream = FileUtils.getResource("bedrock/entity_identifiers.dat");
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) { try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
ENTITY_IDENTIFIERS = (CompoundTag) nbtInputStream.readTag(); ENTITY_IDENTIFIERS = (NbtMap) nbtInputStream.readTag();
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("Unable to get entities from entity identifiers", e); throw new AssertionError("Unable to get entities from entity identifiers", e);
} }

View file

@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.bedrock;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -45,47 +45,45 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
@Override @Override
public void translate(BlockEntityDataPacket packet, GeyserSession session) { public void translate(BlockEntityDataPacket packet, GeyserSession session) {
if (packet.getData() instanceof CompoundTag) { NbtMap tag = packet.getData();
CompoundTag tag = (CompoundTag) packet.getData(); if (tag.getString("id").equals("Sign")) {
if (tag.getString("id").equals("Sign")) { // This is the reason why this all works - Bedrock sends packets every time you update the sign, Java only wants the final packet
// This is the reason why this all works - Bedrock sends packets every time you update the sign, Java only wants the final packet // But Bedrock sends one final packet when you're done editing the sign, which should be equal to the last message since there's no edits
// But Bedrock sends one final packet when you're done editing the sign, which should be equal to the last message since there's no edits // So if the latest update does not match the last cached update then it's still being edited
// So if the latest update does not match the last cached update then it's still being edited Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z")); if (!tag.getString("Text").equals(lastMessages.get(pos))) {
if (!tag.getString("Text").equals(lastMessages.get(pos))) { lastMessages.put(pos, tag.getString("Text"));
lastMessages.put(pos, tag.getString("Text")); return;
return;
}
// Otherwise the two messages are identical and we can get to work deconstructing
StringBuilder newMessage = new StringBuilder();
// While Bedrock's sign lines are one string, Java's is an array of each line
// (Initialized all with empty strings because it complains about null)
String[] lines = new String[] {"", "", "", ""};
int iterator = 0;
// This converts the message into the array'd message Java wants
for (char character : tag.getString("Text").toCharArray()) {
// If we get a return in Bedrock, that signals to use the next line.
if (character == '\n') {
lines[iterator] = newMessage.toString();
iterator++;
// Bedrock, for whatever reason, can hold a message out of bounds
// We don't care about that so we discard that
if (iterator > lines.length - 1) {
break;
}
newMessage = new StringBuilder();
} else newMessage.append(character);
}
// Put the final line on since it isn't done in the for loop
if (iterator < lines.length) lines[iterator] = newMessage.toString();
ClientUpdateSignPacket clientUpdateSignPacket = new ClientUpdateSignPacket(pos, lines);
session.sendDownstreamPacket(clientUpdateSignPacket);
//TODO (potentially): originally I was going to update the sign blocks so Bedrock and Java users would match visually
// However Java can still store a lot per-line and visuals are still messed up so that doesn't work
// We remove the sign position from map to indicate there is no work-in-progress sign
lastMessages.remove(pos);
} }
// Otherwise the two messages are identical and we can get to work deconstructing
StringBuilder newMessage = new StringBuilder();
// While Bedrock's sign lines are one string, Java's is an array of each line
// (Initialized all with empty strings because it complains about null)
String[] lines = new String[] {"", "", "", ""};
int iterator = 0;
// This converts the message into the array'd message Java wants
for (char character : tag.getString("Text").toCharArray()) {
// If we get a return in Bedrock, that signals to use the next line.
if (character == '\n') {
lines[iterator] = newMessage.toString();
iterator++;
// Bedrock, for whatever reason, can hold a message out of bounds
// We don't care about that so we discard that
if (iterator > lines.length - 1) {
break;
}
newMessage = new StringBuilder();
} else newMessage.append(character);
}
// Put the final line on since it isn't done in the for loop
if (iterator < lines.length) lines[iterator] = newMessage.toString();
ClientUpdateSignPacket clientUpdateSignPacket = new ClientUpdateSignPacket(pos, lines);
session.sendDownstreamPacket(clientUpdateSignPacket);
//TODO (potentially): originally I was going to update the sign blocks so Bedrock and Java users would match visually
// However Java can still store a lot per-line and visuals are still messed up so that doesn't work
// We remove the sign position from map to indicate there is no work-in-progress sign
lastMessages.remove(pos);
} }
} }

View file

@ -26,19 +26,19 @@
package org.geysermc.connector.network.translators.bedrock; package org.geysermc.connector.network.translators.bedrock;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.IntTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBClientRequestPacket; import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBClientRequestPacket;
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBServerBroadcastPacket; import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBServerBroadcastPacket;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.LoadstoneTracker; import org.geysermc.connector.utils.LoadstoneTracker;
import java.util.ArrayList;
import java.util.List;
@Translator(packet = PositionTrackingDBClientRequestPacket.class) @Translator(packet = PositionTrackingDBClientRequestPacket.class)
public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTranslator<PositionTrackingDBClientRequestPacket> { public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTranslator<PositionTrackingDBClientRequestPacket> {
@ -60,22 +60,20 @@ public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTran
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE); broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE);
// Build the nbt data for the update // Build the nbt data for the update
CompoundTagBuilder builder = CompoundTagBuilder.builder(); NbtMapBuilder builder = NbtMap.builder();
builder.intTag("dim", DimensionUtils.javaToBedrock(pos.getDimension())); builder.putInt("dim", DimensionUtils.javaToBedrock(pos.getDimension()));
builder.stringTag("id", String.format("%08X", packet.getTrackingId())); builder.putString("id", String.format("%08X", packet.getTrackingId()));
builder.byteTag("version", (byte) 1); // Not sure what this is for builder.putByte("version", (byte) 1); // Not sure what this is for
builder.byteTag("status", (byte) 0); // Not sure what this is for builder.putByte("status", (byte) 0); // Not sure what this is for
// Build the position for the update // Build the position for the update
List<IntTag> posList = new ArrayList<>(); IntList posList = new IntArrayList();
posList.add(new IntTag("", pos.getX())); posList.add(pos.getX());
posList.add(new IntTag("", pos.getY())); posList.add(pos.getY());
posList.add(new IntTag("", pos.getZ())); posList.add(pos.getZ());
builder.putList("pos", NbtType.INT, posList);
builder.listTag("pos", IntTag.class, posList); broadcastPacket.setTag(builder.build());
broadcastPacket.setTag(builder.buildRootTag());
session.sendUpstreamPacket(broadcastPacket); session.sendUpstreamPacket(broadcastPacket);
} }

View file

@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.data.message.TextMessage;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.*; import com.nukkitx.protocol.bedrock.data.inventory.*;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
@ -103,7 +104,7 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
} }
if (itemName != null) { if (itemName != null) {
String rename; String rename;
com.nukkitx.nbt.tag.CompoundTag tag = itemName.getTag(); NbtMap tag = itemName.getTag();
if (tag != null) { if (tag != null) {
rename = tag.getCompound("display").getString("Name"); rename = tag.getCompound("display").getString("Name");
} else { } else {

View file

@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
@ -57,14 +57,14 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);
CompoundTag tag = CompoundTag.builder() NbtMap tag = NbtMap.builder()
.stringTag("id", "Chest") .putString("id", "Chest")
.intTag("x", position.getX()) .putInt("x", position.getX())
.intTag("y", position.getY()) .putInt("y", position.getY())
.intTag("z", position.getZ()) .putInt("z", position.getZ())
.intTag("pairx", pairPosition.getX()) .putInt("pairx", pairPosition.getX())
.intTag("pairz", pairPosition.getZ()) .putInt("pairz", pairPosition.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag(); .putString("CustomName", inventory.getTitle()).build();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag); dataPacket.setData(tag);
dataPacket.setBlockPosition(position); dataPacket.setBlockPosition(position);
@ -77,14 +77,14 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);
tag = CompoundTag.builder() tag = NbtMap.builder()
.stringTag("id", "Chest") .putString("id", "Chest")
.intTag("x", pairPosition.getX()) .putInt("x", pairPosition.getX())
.intTag("y", pairPosition.getY()) .putInt("y", pairPosition.getY())
.intTag("z", pairPosition.getZ()) .putInt("z", pairPosition.getZ())
.intTag("pairx", position.getX()) .putInt("pairx", position.getX())
.intTag("pairz", position.getZ()) .putInt("pairz", position.getZ())
.stringTag("CustomName", inventory.getTitle()).buildRootTag(); .putString("CustomName", inventory.getTitle()).build();
dataPacket = new BlockEntityDataPacket(); dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag); dataPacket.setData(tag);
dataPacket.setBlockPosition(pairPosition); dataPacket.setBlockPosition(pairPosition);

View file

@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.inventory.holder;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
@ -56,11 +56,11 @@ public class BlockInventoryHolder extends InventoryHolder {
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position); inventory.setHolderPosition(position);
CompoundTag tag = CompoundTag.builder() NbtMap tag = NbtMap.builder()
.intTag("x", position.getX()) .putInt("x", position.getX())
.intTag("y", position.getY()) .putInt("y", position.getY())
.intTag("z", position.getZ()) .putInt("z", position.getZ())
.stringTag("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).buildRootTag(); .putString("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).build();
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
dataPacket.setData(tag); dataPacket.setData(tag);
dataPacket.setBlockPosition(position); dataPacket.setBlockPosition(position);

View file

@ -29,6 +29,7 @@ package org.geysermc.connector.network.translators.item;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
@ -156,7 +157,7 @@ public class ItemRegistry {
byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText()); byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText());
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
try { try {
com.nukkitx.nbt.tag.CompoundTag tag = (com.nukkitx.nbt.tag.CompoundTag) NbtUtils.createReaderLE(bais).readTag(); NbtMap tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1, tag)); creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1, tag));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -28,10 +28,21 @@ 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.MessageSerializer; import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.opennbt.tag.builtin.*; import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.nukkitx.nbt.tag.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.nukkitx.nbt.tag.Tag; import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
@ -150,9 +161,9 @@ public abstract class ItemTranslator {
// Get the display name of the item // Get the display name of the item
CompoundTag tag = itemData.getTag(); NbtMap tag = itemData.getTag();
if (tag != null) { if (tag != null) {
CompoundTag display = tag.getCompound("display"); NbtMap display = tag.getCompound("display");
if (display != null) { if (display != null) {
String name = display.getString("Name"); String name = display.getString("Name");
@ -162,15 +173,15 @@ public abstract class ItemTranslator {
name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getClientData().getLanguageCode()); name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getClientData().getLanguageCode());
// Build the new display tag // Build the new display tag
CompoundTagBuilder displayBuilder = display.toBuilder(); NbtMapBuilder displayBuilder = display.toBuilder();
displayBuilder.stringTag("Name", name); displayBuilder.putString("Name", name);
// Build the new root tag // Build the new root tag
CompoundTagBuilder builder = tag.toBuilder(); NbtMapBuilder builder = tag.toBuilder();
builder.tag(displayBuilder.build("display")); builder.put("display", displayBuilder.build());
// Create a new item with the original data + updated name // Create a new item with the original data + updated name
itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.buildRootTag()); itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.build());
} }
} }
} }
@ -200,56 +211,51 @@ public abstract class ItemTranslator {
if (itemData.getTag() == null) { if (itemData.getTag() == null) {
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag("")); return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag(""));
} }
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT(itemData.getTag())); return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag()));
} }
public abstract List<ItemEntry> getAppliedItems(); public abstract List<ItemEntry> getAppliedItems();
public CompoundTag translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) { public NbtMap translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
Map<String, Tag<?>> javaValue = new HashMap<>(); Map<String, Object> javaValue = new HashMap<>();
if (tag.getValue() != null && !tag.getValue().isEmpty()) { if (tag.getValue() != null && !tag.getValue().isEmpty()) {
for (String str : tag.getValue().keySet()) { for (String str : tag.getValue().keySet()) {
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = tag.get(str); com.github.steveice10.opennbt.tag.builtin.Tag javaTag = tag.get(str);
com.nukkitx.nbt.tag.Tag<?> translatedTag = translateToBedrockNBT(javaTag); Object translatedTag = translateToBedrockNBT(javaTag);
if (translatedTag == null) if (translatedTag == null)
continue; continue;
javaValue.put(translatedTag.getName(), translatedTag); javaValue.put(javaTag.getName(), translatedTag);
} }
} }
NbtMapBuilder builder = NbtMap.builder();
return new CompoundTag(tag.getName(), javaValue); javaValue.forEach(builder::put);
return builder.build();
} }
private Tag<?> translateToBedrockNBT(com.github.steveice10.opennbt.tag.builtin.Tag tag) { private Object translateToBedrockNBT(com.github.steveice10.opennbt.tag.builtin.Tag tag) {
if (tag instanceof ByteArrayTag) { if (tag instanceof ByteArrayTag) {
ByteArrayTag byteArrayTag = (ByteArrayTag) tag; return ((ByteArrayTag) tag).getValue();
return new com.nukkitx.nbt.tag.ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
} }
if (tag instanceof ByteTag) { if (tag instanceof ByteTag) {
ByteTag byteTag = (ByteTag) tag; return ((ByteTag) tag).getValue();
return new com.nukkitx.nbt.tag.ByteTag(byteTag.getName(), byteTag.getValue());
} }
if (tag instanceof DoubleTag) { if (tag instanceof DoubleTag) {
DoubleTag doubleTag = (DoubleTag) tag; return ((DoubleTag) tag).getValue();
return new com.nukkitx.nbt.tag.DoubleTag(doubleTag.getName(), doubleTag.getValue());
} }
if (tag instanceof FloatTag) { if (tag instanceof FloatTag) {
FloatTag floatTag = (FloatTag) tag; return ((FloatTag) tag).getValue();
return new com.nukkitx.nbt.tag.FloatTag(floatTag.getName(), floatTag.getValue());
} }
if (tag instanceof IntArrayTag) { if (tag instanceof IntArrayTag) {
IntArrayTag intArrayTag = (IntArrayTag) tag; return ((IntArrayTag) tag).getValue();
return new com.nukkitx.nbt.tag.IntArrayTag(intArrayTag.getName(), intArrayTag.getValue());
} }
if (tag instanceof IntTag) { if (tag instanceof IntTag) {
IntTag intTag = (IntTag) tag; return ((IntTag) tag).getValue();
return new com.nukkitx.nbt.tag.IntTag(intTag.getName(), intTag.getValue());
} }
if (tag instanceof LongArrayTag) { if (tag instanceof LongArrayTag) {
@ -260,50 +266,46 @@ public abstract class ItemTranslator {
} }
if (tag instanceof LongTag) { if (tag instanceof LongTag) {
LongTag longTag = (LongTag) tag; return ((LongTag) tag).getValue();
return new com.nukkitx.nbt.tag.LongTag(longTag.getName(), longTag.getValue());
} }
if (tag instanceof ShortTag) { if (tag instanceof ShortTag) {
ShortTag shortTag = (ShortTag) tag; return ((ShortTag) tag).getValue();
return new com.nukkitx.nbt.tag.ShortTag(shortTag.getName(), shortTag.getValue());
} }
if (tag instanceof StringTag) { if (tag instanceof StringTag) {
StringTag stringTag = (StringTag) tag; return ((StringTag) tag).getValue();
return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), stringTag.getValue());
} }
if (tag instanceof ListTag) { if (tag instanceof ListTag) {
ListTag listTag = (ListTag) tag; ListTag listTag = (ListTag) tag;
List<Tag<?>> tagList = new ArrayList<>(); List<Object> tagList = new ArrayList<>();
for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) { for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) {
tagList.add(translateToBedrockNBT(value)); tagList.add(translateToBedrockNBT(value));
} }
Class<?> clazz = CompoundTag.class; NbtType<?> type = NbtType.COMPOUND;
if (!tagList.isEmpty()) { if (!tagList.isEmpty()) {
clazz = tagList.get(0).getClass(); type = NbtType.byClass(tagList.get(0).getClass());
} }
return new com.nukkitx.nbt.tag.ListTag(listTag.getName(), clazz, tagList); return new NbtList(type, tagList);
} }
if (tag instanceof com.github.steveice10.opennbt.tag.builtin.CompoundTag) { if (tag instanceof com.github.steveice10.opennbt.tag.builtin.CompoundTag) {
com.github.steveice10.opennbt.tag.builtin.CompoundTag compoundTag = (com.github.steveice10.opennbt.tag.builtin.CompoundTag) tag; com.github.steveice10.opennbt.tag.builtin.CompoundTag compoundTag = (com.github.steveice10.opennbt.tag.builtin.CompoundTag) tag;
return translateNbtToBedrock(compoundTag); return translateNbtToBedrock(compoundTag);
} }
return null; return null;
} }
public com.github.steveice10.opennbt.tag.builtin.CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) { public com.github.steveice10.opennbt.tag.builtin.CompoundTag translateToJavaNBT(String name, NbtMap tag) {
com.github.steveice10.opennbt.tag.builtin.CompoundTag javaTag = new com.github.steveice10.opennbt.tag.builtin.CompoundTag(tag.getName()); com.github.steveice10.opennbt.tag.builtin.CompoundTag javaTag = new com.github.steveice10.opennbt.tag.builtin.CompoundTag(name);
Map<String, com.github.steveice10.opennbt.tag.builtin.Tag> javaValue = javaTag.getValue(); Map<String, com.github.steveice10.opennbt.tag.builtin.Tag> javaValue = javaTag.getValue();
if (tag.getValue() != null && !tag.getValue().isEmpty()) { if (tag != null && !tag.isEmpty()) {
for (String str : tag.getValue().keySet()) { for (String str : tag.keySet()) {
Tag<?> bedrockTag = tag.get(str); Object bedrockTag = tag.get(str);
com.github.steveice10.opennbt.tag.builtin.Tag translatedTag = translateToJavaNBT(bedrockTag); com.github.steveice10.opennbt.tag.builtin.Tag translatedTag = translateToJavaNBT(name, bedrockTag);
if (translatedTag == null) if (translatedTag == null)
continue; continue;
@ -315,77 +317,65 @@ public abstract class ItemTranslator {
return javaTag; return javaTag;
} }
private com.github.steveice10.opennbt.tag.builtin.Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag<?> tag) { private com.github.steveice10.opennbt.tag.builtin.Tag translateToJavaNBT(String name, Object object) {
if (tag instanceof com.nukkitx.nbt.tag.ByteArrayTag) { if (object instanceof int[]) {
com.nukkitx.nbt.tag.ByteArrayTag byteArrayTag = (com.nukkitx.nbt.tag.ByteArrayTag) tag; return new IntArrayTag(name, (int[]) object);
return new ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.ByteTag) { if (object instanceof byte[]) {
com.nukkitx.nbt.tag.ByteTag byteTag = (com.nukkitx.nbt.tag.ByteTag) tag; return new ByteArrayTag(name, (byte[]) object);
return new ByteTag(byteTag.getName(), byteTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.DoubleTag) { if (object instanceof Byte) {
com.nukkitx.nbt.tag.DoubleTag doubleTag = (com.nukkitx.nbt.tag.DoubleTag) tag; return new ByteTag(name, (byte) object);
return new DoubleTag(doubleTag.getName(), doubleTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.FloatTag) { if (object instanceof Float) {
com.nukkitx.nbt.tag.FloatTag floatTag = (com.nukkitx.nbt.tag.FloatTag) tag; return new FloatTag(name, (float) object);
return new FloatTag(floatTag.getName(), floatTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.IntArrayTag) { if (object instanceof Double) {
com.nukkitx.nbt.tag.IntArrayTag intArrayTag = (com.nukkitx.nbt.tag.IntArrayTag) tag; return new DoubleTag(name, (double) object);
return new IntArrayTag(intArrayTag.getName(), intArrayTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.IntTag) { if (object instanceof Integer) {
com.nukkitx.nbt.tag.IntTag intTag = (com.nukkitx.nbt.tag.IntTag) tag; return new IntTag(name, (int) object);
return new IntTag(intTag.getName(), intTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.LongArrayTag) { if (object instanceof long[]) {
com.nukkitx.nbt.tag.LongArrayTag longArrayTag = (com.nukkitx.nbt.tag.LongArrayTag) tag; return new LongArrayTag(name, (long[]) object);
return new LongArrayTag(longArrayTag.getName(), longArrayTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.LongTag) { if (object instanceof Long) {
com.nukkitx.nbt.tag.LongTag longTag = (com.nukkitx.nbt.tag.LongTag) tag; return new LongTag(name, (long) object);
return new LongTag(longTag.getName(), longTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.ShortTag) { if (object instanceof Short) {
com.nukkitx.nbt.tag.ShortTag shortTag = (com.nukkitx.nbt.tag.ShortTag) tag; return new ShortTag(name, (short) object);
return new ShortTag(shortTag.getName(), shortTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.StringTag) { if (object instanceof String) {
com.nukkitx.nbt.tag.StringTag stringTag = (com.nukkitx.nbt.tag.StringTag) tag; return new StringTag(name, (String) object);
return new StringTag(stringTag.getName(), stringTag.getValue());
} }
if (tag instanceof com.nukkitx.nbt.tag.ListTag) { if (object instanceof List) {
com.nukkitx.nbt.tag.ListTag<?> listTag = (com.nukkitx.nbt.tag.ListTag<?>) tag;
List<com.github.steveice10.opennbt.tag.builtin.Tag> tags = new ArrayList<>(); List<com.github.steveice10.opennbt.tag.builtin.Tag> tags = new ArrayList<>();
for (Object value : listTag.getValue()) { for (Object value : (List<?>) object) {
if (!(value instanceof com.nukkitx.nbt.tag.Tag)) com.github.steveice10.opennbt.tag.builtin.Tag javaTag = translateToJavaNBT("", value);
continue;
com.nukkitx.nbt.tag.Tag<?> tagValue = (com.nukkitx.nbt.tag.Tag<?>) value;
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = translateToJavaNBT(tagValue);
if (javaTag != null) if (javaTag != null)
tags.add(javaTag); tags.add(javaTag);
} }
return new ListTag(listTag.getName(), tags); return new ListTag(name, tags);
} }
if (tag instanceof com.nukkitx.nbt.tag.CompoundTag) { if (object instanceof NbtMap) {
com.nukkitx.nbt.tag.CompoundTag compoundTag = (com.nukkitx.nbt.tag.CompoundTag) tag; NbtMap map = (NbtMap) object;
return translateToJavaNBT(compoundTag); for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue().equals(map.get(name))) {
return translateToJavaNBT(entry.getKey(), map.getCompound(name));
}
}
} }
return null; return null;

View file

@ -31,7 +31,10 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
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.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.connector.network.translators.ItemRemapper; import org.geysermc.connector.network.translators.ItemRemapper;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
@ -63,10 +66,10 @@ public class BannerTranslator extends ItemTranslator {
if (blockEntityTag.contains("Patterns")) { if (blockEntityTag.contains("Patterns")) {
ListTag patterns = blockEntityTag.get("Patterns"); ListTag patterns = blockEntityTag.get("Patterns");
CompoundTagBuilder builder = itemData.getTag().toBuilder(); NbtMapBuilder builder = itemData.getTag().toBuilder();
builder.tag(convertBannerPattern(patterns)); builder.put("Patterns", convertBannerPattern(patterns));
itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.buildRootTag()); itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.build());
} }
return itemData; return itemData;
@ -78,9 +81,9 @@ public class BannerTranslator extends ItemTranslator {
ItemStack itemStack = super.translateToJava(itemData, itemEntry); ItemStack itemStack = super.translateToJava(itemData, itemEntry);
com.nukkitx.nbt.tag.CompoundTag nbtTag = itemData.getTag(); NbtMap nbtTag = itemData.getTag();
if (nbtTag.contains("Patterns")) { if (nbtTag.containsKey("Patterns", NbtType.COMPOUND)) {
com.nukkitx.nbt.tag.ListTag<?> patterns = nbtTag.get("Patterns"); List<NbtMap> patterns = nbtTag.getList("Patterns", NbtType.COMPOUND);
CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag"); CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag");
blockEntityTag.put(convertBannerPattern(patterns)); blockEntityTag.put(convertBannerPattern(patterns));
@ -102,16 +105,16 @@ public class BannerTranslator extends ItemTranslator {
* @param patterns The patterns to convert * @param patterns The patterns to convert
* @return The new converted patterns * @return The new converted patterns
*/ */
public static com.nukkitx.nbt.tag.ListTag convertBannerPattern(ListTag patterns) { public static NbtList<NbtMap> convertBannerPattern(ListTag patterns) {
List<com.nukkitx.nbt.tag.CompoundTag> tagsList = new ArrayList<>(); List<NbtMap> tagsList = new ArrayList<>();
for (com.github.steveice10.opennbt.tag.builtin.Tag patternTag : patterns.getValue()) { for (com.github.steveice10.opennbt.tag.builtin.Tag patternTag : patterns.getValue()) {
com.nukkitx.nbt.tag.CompoundTag newPatternTag = getBedrockBannerPattern((CompoundTag) patternTag); NbtMap newPatternTag = getBedrockBannerPattern((CompoundTag) patternTag);
if (newPatternTag != null) { if (newPatternTag != null) {
tagsList.add(newPatternTag); tagsList.add(newPatternTag);
} }
} }
return new com.nukkitx.nbt.tag.ListTag<>("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, tagsList); return new NbtList<>(NbtType.COMPOUND, tagsList);
} }
/** /**
@ -120,7 +123,7 @@ public class BannerTranslator extends ItemTranslator {
* @param pattern Java edition pattern nbt * @param pattern Java edition pattern nbt
* @return The Bedrock edition format pattern nbt * @return The Bedrock edition format pattern nbt
*/ */
public static com.nukkitx.nbt.tag.CompoundTag getBedrockBannerPattern(CompoundTag pattern) { public static NbtMap getBedrockBannerPattern(CompoundTag pattern) {
String patternName = (String) pattern.get("Pattern").getValue(); String patternName = (String) pattern.get("Pattern").getValue();
// Return null if its the globe pattern as it doesn't exist on bedrock // Return null if its the globe pattern as it doesn't exist on bedrock
@ -128,11 +131,11 @@ public class BannerTranslator extends ItemTranslator {
return null; return null;
} }
return CompoundTagBuilder.builder() return NbtMap.builder()
.intTag("Color", 15 - (int) pattern.get("Color").getValue()) .putInt("Color", 15 - (int) pattern.get("Color").getValue())
.stringTag("Pattern", (String) pattern.get("Pattern").getValue()) .putString("Pattern", (String) pattern.get("Pattern").getValue())
.stringTag("Pattern", patternName) .putString("Pattern", patternName)
.buildRootTag(); .build();
} }
/** /**
@ -141,10 +144,10 @@ public class BannerTranslator extends ItemTranslator {
* @param patterns The patterns to convert * @param patterns The patterns to convert
* @return The new converted patterns * @return The new converted patterns
*/ */
public static ListTag convertBannerPattern(com.nukkitx.nbt.tag.ListTag<?> patterns) { public static ListTag convertBannerPattern(List<NbtMap> patterns) {
List<Tag> tagsList = new ArrayList<>(); List<Tag> tagsList = new ArrayList<>();
for (Object patternTag : patterns.getValue()) { for (Object patternTag : patterns) {
CompoundTag newPatternTag = getJavaBannerPattern((com.nukkitx.nbt.tag.CompoundTag) patternTag); CompoundTag newPatternTag = getJavaBannerPattern((NbtMap) patternTag);
tagsList.add(newPatternTag); tagsList.add(newPatternTag);
} }
@ -157,7 +160,7 @@ public class BannerTranslator extends ItemTranslator {
* @param pattern Bedorck edition pattern nbt * @param pattern Bedorck edition pattern nbt
* @return The Java edition format pattern nbt * @return The Java edition format pattern nbt
*/ */
public static CompoundTag getJavaBannerPattern(com.nukkitx.nbt.tag.CompoundTag pattern) { public static CompoundTag getJavaBannerPattern(NbtMap pattern) {
Map<String, Tag> tags = new HashMap<>(); Map<String, Tag> tags = new HashMap<>();
tags.put("Color", new IntTag("Color", 15 - pattern.getInt("Color"))); tags.put("Color", new IntTag("Color", 15 - pattern.getInt("Color")));
tags.put("Pattern", new StringTag("Pattern", pattern.getString("Pattern"))); tags.put("Pattern", new StringTag("Pattern", pattern.getString("Pattern")));

View file

@ -30,7 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Recipe;
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData; import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData;
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData; import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareRecipesPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareRecipesPacket;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.CraftingData; import com.nukkitx.protocol.bedrock.data.inventory.CraftingData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData;
@ -169,6 +169,6 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
private static class GroupedItem { private static class GroupedItem {
int id; int id;
int count; int count;
CompoundTag tag; NbtMap tag;
} }
} }

View file

@ -28,8 +28,8 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.value.*; import com.github.steveice10.mc.protocol.data.game.world.block.value.*;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockValuePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockValuePacket;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.BlockEventPacket; import com.nukkitx.protocol.bedrock.packet.BlockEventPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
@ -132,16 +132,16 @@ public class JavaBlockValueTranslator extends PacketTranslator<ServerBlockValueP
* @param state * @param state
* @return Bedrock CompoundTag of piston * @return Bedrock CompoundTag of piston
*/ */
private CompoundTag buildPistonTag(Vector3i position, float progress, float lastProgress, byte state) { private NbtMap buildPistonTag(Vector3i position, float progress, float lastProgress, byte state) {
CompoundTagBuilder builder = CompoundTag.EMPTY.toBuilder(); NbtMapBuilder builder = NbtMap.builder()
builder.intTag("x", position.getX()) .putInt("x", position.getX())
.intTag("y", position.getY()) .putInt("y", position.getY())
.intTag("z", position.getZ()) .putInt("z", position.getZ())
.floatTag("Progress", progress) .putFloat("Progress", progress)
.floatTag("LastProgress", lastProgress) .putFloat("LastProgress", lastProgress)
.stringTag("id", "PistonArm") .putString("id", "PistonArm")
.byteTag("NewState", state) .putByte("NewState", state)
.byteTag("State", state); .putByte("State", state);
return builder.buildRootTag(); return builder.build();
} }
} }

View file

@ -27,9 +27,9 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
import com.nukkitx.nbt.NBTOutputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.network.VarInts; import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
@ -82,8 +82,8 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer());
NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream); NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream);
for (CompoundTag blockEntity : chunkData.getBlockEntities()) { for (NbtMap blockEntity : chunkData.getBlockEntities()) {
nbtStream.write(blockEntity); nbtStream.writeTag(blockEntity);
} }
byteBuf.writeBytes(stream.buffer()); byteBuf.writeBytes(stream.buffer());
@ -100,7 +100,7 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
session.sendUpstreamPacket(levelChunkPacket); session.sendUpstreamPacket(levelChunkPacket);
// Some block entities need to be loaded in later or else text doesn't show (signs) or they crash the game (end gateway blocks) // Some block entities need to be loaded in later or else text doesn't show (signs) or they crash the game (end gateway blocks)
for (Object2IntMap.Entry<CompoundTag> blockEntityEntry : chunkData.getLoadBlockEntitiesLater().object2IntEntrySet()) { for (Object2IntMap.Entry<NbtMap> blockEntityEntry : chunkData.getLoadBlockEntitiesLater().object2IntEntrySet()) {
int x = blockEntityEntry.getKey().getInt("x"); int x = blockEntityEntry.getKey().getInt("x");
int y = blockEntityEntry.getKey().getInt("y"); int y = blockEntityEntry.getKey().getInt("y");
int z = blockEntityEntry.getKey().getInt("z"); int z = blockEntityEntry.getKey().getInt("z");

View file

@ -52,7 +52,7 @@ public class JavaExplosionTranslator extends PacketTranslator<ServerExplosionPac
Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
// Since bedrock does not play an explosion sound and particles sound, we have to manually do so // Since bedrock does not play an explosion sound and particles sound, we have to manually do so
LevelEventPacket levelEventPacket = new LevelEventPacket(); LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setType(packet.getRadius() >= 2.0f ? LevelEventType.PARTICLE_HUGE_EXPLODE : LevelEventType.PARTICLE_LARGE_EXPLOSION); levelEventPacket.setType(packet.getRadius() >= 2.0f ? LevelEventType.PARTICLE_HUGE_EXPLODE : LevelEventType.PARTICLE_EXPLOSION);
levelEventPacket.setData(0); levelEventPacket.setData(0);
levelEventPacket.setPosition(pos.toFloat()); levelEventPacket.setPosition(pos.toFloat());
session.sendUpstreamPacket(levelEventPacket); session.sendUpstreamPacket(levelEventPacket);

View file

@ -75,7 +75,7 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
effect.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState())); effect.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState()));
break; break;
case EXPLOSION: case EXPLOSION:
effect.setType(LevelEventType.PARTICLE_LARGE_EXPLOSION); effect.setType(LevelEventType.PARTICLE_EXPLOSION);
break; break;
case MOB_SPAWN: case MOB_SPAWN:
effect.setType(LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); // TODO: Check, but I don't think I really verified this ever went into effect on Java effect.setType(LevelEventType.PARTICLE_MOB_BLOCK_SPAWN); // TODO: Check, but I don't think I really verified this ever went into effect on Java

View file

@ -29,8 +29,9 @@ package org.geysermc.connector.network.translators.java.world;
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.game.window.VillagerTrade; import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerTradeListPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerTradeListPacket;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
@ -75,67 +76,67 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
updateTradePacket.setUsingEconomyTrade(true); updateTradePacket.setUsingEconomyTrade(true);
updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId()); updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId()); updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId());
CompoundTagBuilder builder = CompoundTagBuilder.builder(); NbtMapBuilder builder = NbtMap.builder();
List<CompoundTag> tags = new ArrayList<>(); List<NbtMap> tags = new ArrayList<>();
for (VillagerTrade trade : packet.getTrades()) { for (VillagerTrade trade : packet.getTrades()) {
CompoundTagBuilder recipe = CompoundTagBuilder.builder(); NbtMapBuilder recipe = NbtMap.builder();
recipe.intTag("maxUses", trade.getMaxUses()); recipe.putInt("maxUses", trade.getMaxUses());
recipe.intTag("traderExp", trade.getXp()); recipe.putInt("traderExp", trade.getXp());
recipe.floatTag("priceMultiplierA", trade.getPriceMultiplier()); recipe.putFloat("priceMultiplierA", trade.getPriceMultiplier());
recipe.tag(getItemTag(session, trade.getOutput(), "sell", 0)); recipe.put("sell", getItemTag(session, trade.getOutput(), 0));
recipe.floatTag("priceMultiplierB", 0.0f); recipe.putFloat("priceMultiplierB", 0.0f);
recipe.intTag("buyCountB", trade.getSecondInput() != null ? trade.getSecondInput().getAmount() : 0); recipe.putInt("buyCountB", trade.getSecondInput() != null ? trade.getSecondInput().getAmount() : 0);
recipe.intTag("buyCountA", trade.getFirstInput().getAmount()); recipe.putInt("buyCountA", trade.getFirstInput().getAmount());
recipe.intTag("demand", trade.getDemand()); recipe.putInt("demand", trade.getDemand());
recipe.intTag("tier", packet.getVillagerLevel() - 1); recipe.putInt("tier", packet.getVillagerLevel() - 1);
recipe.tag(getItemTag(session, trade.getFirstInput(), "buyA", trade.getSpecialPrice())); recipe.put("buyA", getItemTag(session, trade.getFirstInput(), trade.getSpecialPrice()));
if (trade.getSecondInput() != null) { if (trade.getSecondInput() != null) {
recipe.tag(getItemTag(session, trade.getSecondInput(), "buyB", 0)); recipe.put("buyB", getItemTag(session, trade.getSecondInput(), 0));
} }
recipe.intTag("uses", trade.getNumUses()); recipe.putInt("uses", trade.getNumUses());
recipe.byteTag("rewardExp", (byte) 1); recipe.putByte("rewardExp", (byte) 1);
tags.add(recipe.buildRootTag()); tags.add(recipe.build());
} }
//Hidden trade to fix visual experience bug //Hidden trade to fix visual experience bug
if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) { if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) {
tags.add(CompoundTagBuilder.builder() tags.add(NbtMap.builder()
.intTag("maxUses", 0) .putInt("maxUses", 0)
.intTag("traderExp", 0) .putInt("traderExp", 0)
.floatTag("priceMultiplierA", 0.0f) .putFloat("priceMultiplierA", 0.0f)
.floatTag("priceMultiplierB", 0.0f) .putFloat("priceMultiplierB", 0.0f)
.intTag("buyCountB", 0) .putInt("buyCountB", 0)
.intTag("buyCountA", 0) .putInt("buyCountA", 0)
.intTag("demand", 0) .putInt("demand", 0)
.intTag("tier", 5) .putInt("tier", 5)
.intTag("uses", 0) .putInt("uses", 0)
.byteTag("rewardExp", (byte) 0) .putByte("rewardExp", (byte) 0)
.buildRootTag()); .build());
} }
builder.listTag("Recipes", CompoundTag.class, tags); builder.putList("Recipes", NbtType.COMPOUND, tags);
List<CompoundTag> expTags = new ArrayList<>(); List<NbtMap> expTags = new ArrayList<>();
expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag()); expTags.add(NbtMap.builder().putInt("0", 0).build());
expTags.add(CompoundTagBuilder.builder().intTag("1", 10).buildRootTag()); expTags.add(NbtMap.builder().putInt("1", 10).build());
expTags.add(CompoundTagBuilder.builder().intTag("2", 70).buildRootTag()); expTags.add(NbtMap.builder().putInt("2", 70).build());
expTags.add(CompoundTagBuilder.builder().intTag("3", 150).buildRootTag()); expTags.add(NbtMap.builder().putInt("3", 150).build());
expTags.add(CompoundTagBuilder.builder().intTag("4", 250).buildRootTag()); expTags.add(NbtMap.builder().putInt("4", 250).build());
builder.listTag("TierExpRequirements", CompoundTag.class, expTags); builder.putList("TierExpRequirements", NbtType.COMPOUND, expTags);
updateTradePacket.setOffers(builder.buildRootTag()); updateTradePacket.setOffers(builder.build());
session.sendUpstreamPacket(updateTradePacket); session.sendUpstreamPacket(updateTradePacket);
} }
private CompoundTag getItemTag(GeyserSession session, ItemStack stack, String name, int specialPrice) { private NbtMap getItemTag(GeyserSession session, ItemStack stack, int specialPrice) {
ItemData itemData = ItemTranslator.translateToBedrock(session, stack); ItemData itemData = ItemTranslator.translateToBedrock(session, stack);
ItemEntry itemEntry = ItemRegistry.getItem(stack); ItemEntry itemEntry = ItemRegistry.getItem(stack);
CompoundTagBuilder builder = CompoundTagBuilder.builder(); NbtMapBuilder builder = NbtMap.builder();
builder.byteTag("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1))); builder.putByte("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1)));
builder.shortTag("Damage", itemData.getDamage()); builder.putShort("Damage", itemData.getDamage());
builder.shortTag("id", (short) itemEntry.getBedrockId()); builder.putShort("id", (short) itemEntry.getBedrockId());
if (itemData.getTag() != null) { if (itemData.getTag() != null) {
CompoundTag tag = itemData.getTag().toBuilder().build("tag"); NbtMap tag = itemData.getTag().toBuilder().build();
builder.tag(tag); builder.put("tag", tag);
} }
return builder.build(name); return builder.build();
} }
} }

View file

@ -26,7 +26,7 @@
package org.geysermc.connector.network.translators.world.block; package org.geysermc.connector.network.translators.world.block;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import java.util.HashMap; import java.util.HashMap;
@ -41,7 +41,7 @@ public class BlockStateValues {
private static final Int2ByteMap BED_COLORS = new Int2ByteOpenHashMap(); private static final Int2ByteMap BED_COLORS = new Int2ByteOpenHashMap();
private static final Int2ObjectMap<DoubleChestValue> DOUBLE_CHEST_VALUES = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<DoubleChestValue> DOUBLE_CHEST_VALUES = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<String> FLOWER_POT_VALUES = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<String> FLOWER_POT_VALUES = new Int2ObjectOpenHashMap<>();
private static final Map<String, CompoundTag> FLOWER_POT_BLOCKS = new HashMap<>(); private static final Map<String, NbtMap> FLOWER_POT_BLOCKS = new HashMap<>();
private static final Int2IntMap NOTEBLOCK_PITCHES = new Int2IntOpenHashMap(); private static final Int2IntMap NOTEBLOCK_PITCHES = new Int2IntOpenHashMap();
private static final Int2BooleanMap IS_STICKY_PISTON = new Int2BooleanOpenHashMap(); private static final Int2BooleanMap IS_STICKY_PISTON = new Int2BooleanOpenHashMap();
private static final Int2BooleanMap PISTON_VALUES = new Int2BooleanOpenHashMap(); private static final Int2BooleanMap PISTON_VALUES = new Int2BooleanOpenHashMap();
@ -159,7 +159,7 @@ public class BlockStateValues {
* Get the map of contained flower pot plants to Bedrock CompoundTag * Get the map of contained flower pot plants to Bedrock CompoundTag
* @return Map of flower pot blocks. * @return Map of flower pot blocks.
*/ */
public static Map<String, CompoundTag> getFlowerPotBlocks() { public static Map<String, NbtMap> getFlowerPotBlocks() {
return FLOWER_POT_BLOCKS; return FLOWER_POT_BLOCKS;
} }

View file

@ -28,11 +28,12 @@ package org.geysermc.connector.network.translators.world.block;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@ -45,7 +46,7 @@ import java.io.InputStream;
import java.util.*; import java.util.*;
public class BlockTranslator { public class BlockTranslator {
public static final ListTag<CompoundTag> BLOCKS; public static final NbtList<NbtMap> BLOCKS;
public static final int AIR = 0; public static final int AIR = 0;
public static final int BEDROCK_WATER_ID; public static final int BEDROCK_WATER_ID;
@ -53,7 +54,7 @@ public class BlockTranslator {
private static final Int2IntMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2IntOpenHashMap(); private static final Int2IntMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2IntOpenHashMap();
private static final BiMap<String, Integer> JAVA_ID_BLOCK_MAP = HashBiMap.create(); private static final BiMap<String, Integer> JAVA_ID_BLOCK_MAP = HashBiMap.create();
private static final IntSet WATERLOGGED = new IntOpenHashSet(); private static final IntSet WATERLOGGED = new IntOpenHashSet();
private static final Object2IntMap<CompoundTag> ITEM_FRAMES = new Object2IntOpenHashMap<>(); private static final Object2IntMap<NbtMap> ITEM_FRAMES = new Object2IntOpenHashMap<>();
// Bedrock carpet ID, used in LlamaEntity.java for decoration // Bedrock carpet ID, used in LlamaEntity.java for decoration
public static final int CARPET = 171; public static final int CARPET = 171;
@ -79,16 +80,16 @@ public class BlockTranslator {
/* Load block palette */ /* Load block palette */
InputStream stream = FileUtils.getResource("bedrock/runtime_block_states.dat"); InputStream stream = FileUtils.getResource("bedrock/runtime_block_states.dat");
ListTag<CompoundTag> blocksTag; NbtList<NbtMap> blocksTag;
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) { try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
blocksTag = (ListTag<CompoundTag>) nbtInputStream.readTag(); blocksTag = (NbtList<NbtMap>) nbtInputStream.readTag();
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("Unable to get blocks from runtime block states", e); throw new AssertionError("Unable to get blocks from runtime block states", e);
} }
Map<CompoundTag, CompoundTag> blockStateMap = new HashMap<>(); Map<NbtMap, NbtMap> blockStateMap = new HashMap<>();
for (CompoundTag tag : blocksTag.getValue()) { for (NbtMap tag : blocksTag) {
if (blockStateMap.putIfAbsent(tag.getCompound("block"), tag) != null) { if (blockStateMap.putIfAbsent(tag.getCompound("block"), tag) != null) {
throw new AssertionError("Duplicate block states in Bedrock palette"); throw new AssertionError("Duplicate block states in Bedrock palette");
} }
@ -101,9 +102,9 @@ public class BlockTranslator {
} catch (Exception e) { } catch (Exception e) {
throw new AssertionError("Unable to load Java block mappings", e); throw new AssertionError("Unable to load Java block mappings", e);
} }
Object2IntMap<CompoundTag> addedStatesMap = new Object2IntOpenHashMap<>(); Object2IntMap<NbtMap> addedStatesMap = new Object2IntOpenHashMap<>();
addedStatesMap.defaultReturnValue(-1); addedStatesMap.defaultReturnValue(-1);
List<CompoundTag> paletteList = new ArrayList<>(); List<NbtMap> paletteList = new ArrayList<>();
Reflections ref = new Reflections("org.geysermc.connector.network.translators.world.block.entity"); Reflections ref = new Reflections("org.geysermc.connector.network.translators.world.block.entity");
ref.getTypesAnnotatedWith(BlockEntity.class); ref.getTypesAnnotatedWith(BlockEntity.class);
@ -120,7 +121,7 @@ public class BlockTranslator {
javaRuntimeId++; javaRuntimeId++;
Map.Entry<String, JsonNode> entry = blocksIterator.next(); Map.Entry<String, JsonNode> entry = blocksIterator.next();
String javaId = entry.getKey(); String javaId = entry.getKey();
CompoundTag blockTag = buildBedrockState(entry.getValue()); NbtMap blockTag = buildBedrockState(entry.getValue());
// TODO fix this, (no block should have a null hardness) // TODO fix this, (no block should have a null hardness)
JsonNode hardnessNode = entry.getValue().get("block_hardness"); JsonNode hardnessNode = entry.getValue().get("block_hardness");
@ -181,7 +182,7 @@ public class BlockTranslator {
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId); BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId);
} }
CompoundTag runtimeTag = blockStateMap.remove(blockTag); NbtMap runtimeTag = blockStateMap.remove(blockTag);
if (runtimeTag != null) { if (runtimeTag != null) {
addedStatesMap.put(blockTag, bedrockRuntimeId); addedStatesMap.put(blockTag, bedrockRuntimeId);
paletteList.add(runtimeTag); paletteList.add(runtimeTag);
@ -240,15 +241,15 @@ public class BlockTranslator {
// Loop around again to find all item frame runtime IDs // Loop around again to find all item frame runtime IDs
int frameRuntimeId = 0; int frameRuntimeId = 0;
for (CompoundTag tag : paletteList) { for (NbtMap tag : paletteList) {
CompoundTag blockTag = tag.getCompound("block"); NbtMap blockTag = tag.getCompound("block");
if (blockTag.getString("name").equals("minecraft:frame")) { if (blockTag.getString("name").equals("minecraft:frame")) {
ITEM_FRAMES.put(tag, frameRuntimeId); ITEM_FRAMES.put(tag, frameRuntimeId);
} }
frameRuntimeId++; frameRuntimeId++;
} }
BLOCKS = new ListTag<>("", CompoundTag.class, paletteList); BLOCKS = new NbtList<>(NbtType.COMPOUND, paletteList);
} }
private BlockTranslator() { private BlockTranslator() {
@ -258,12 +259,12 @@ public class BlockTranslator {
// no-op // no-op
} }
private static CompoundTag buildBedrockState(JsonNode node) { private static NbtMap buildBedrockState(JsonNode node) {
CompoundTagBuilder tagBuilder = CompoundTag.builder(); NbtMapBuilder tagBuilder = NbtMap.builder();
tagBuilder.stringTag("name", node.get("bedrock_identifier").textValue()) tagBuilder.putString("name", node.get("bedrock_identifier").textValue())
.intTag("version", BlockTranslator.BLOCK_STATE_VERSION); .putInt("version", BlockTranslator.BLOCK_STATE_VERSION);
CompoundTagBuilder statesBuilder = CompoundTag.builder(); NbtMapBuilder statesBuilder = NbtMap.builder();
// check for states // check for states
if (node.has("bedrock_states")) { if (node.has("bedrock_states")) {
@ -274,17 +275,18 @@ public class BlockTranslator {
JsonNode stateValue = stateEntry.getValue(); JsonNode stateValue = stateEntry.getValue();
switch (stateValue.getNodeType()) { switch (stateValue.getNodeType()) {
case BOOLEAN: case BOOLEAN:
statesBuilder.booleanTag(stateEntry.getKey(), stateValue.booleanValue()); statesBuilder.putBoolean(stateEntry.getKey(), stateValue.booleanValue());
continue; continue;
case STRING: case STRING:
statesBuilder.stringTag(stateEntry.getKey(), stateValue.textValue()); statesBuilder.putString(stateEntry.getKey(), stateValue.textValue());
continue; continue;
case NUMBER: case NUMBER:
statesBuilder.intTag(stateEntry.getKey(), stateValue.intValue()); statesBuilder.putInt(stateEntry.getKey(), stateValue.intValue());
} }
} }
} }
return tagBuilder.tag(statesBuilder.build("states")).build("block"); tagBuilder.put("states", statesBuilder.build());
return tagBuilder.build();
} }
public static int getBedrockBlockId(int state) { public static int getBedrockBlockId(int state) {
@ -295,7 +297,7 @@ public class BlockTranslator {
return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId); return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId);
} }
public static int getItemFrame(CompoundTag tag) { public static int getItemFrame(NbtMap tag) {
return ITEM_FRAMES.getOrDefault(tag, -1); return ITEM_FRAMES.getOrDefault(tag, -1);
} }

View file

@ -27,15 +27,14 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.IntTag; import com.nukkitx.nbt.NbtType;
import com.nukkitx.nbt.tag.StringTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.translators.item.translators.BannerTranslator; import org.geysermc.connector.network.translators.item.translators.BannerTranslator;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.HashMap;
import java.util.Map;
@BlockEntity(name = "Banner", regex = "banner") @BlockEntity(name = "Banner", regex = "banner")
public class BannerBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class BannerBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@ -46,21 +45,21 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator implement
} }
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
int bannerColor = BlockStateValues.getBannerColor(blockState); int bannerColor = BlockStateValues.getBannerColor(blockState);
if (bannerColor != -1) { if (bannerColor != -1) {
tags.add(new IntTag("Base", 15 - bannerColor)); tags.put("Base", 15 - bannerColor);
} }
if (tag.contains("Patterns")) { if (tag.contains("Patterns")) {
ListTag patterns = tag.get("Patterns"); ListTag patterns = tag.get("Patterns");
tags.add(BannerTranslator.convertBannerPattern(patterns)); tags.put("", BannerTranslator.convertBannerPattern(patterns));
} }
if (tag.contains("CustomName")) { if (tag.contains("CustomName")) {
tags.add(new StringTag("CustomName", (String) tag.get("CustomName").getValue())); tags.put("CustomName", tag.get("CustomName").getValue());
} }
return tags; return tags;
@ -74,9 +73,9 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator implement
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>()); .putList("Patterns", NbtType.COMPOUND, new ArrayList<>())
return tagBuilder.buildRootTag(); .build();
} }
} }

View file

@ -26,13 +26,11 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.ByteTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "Bed", regex = "bed") @BlockEntity(name = "Bed", regex = "bed")
public class BedBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class BedBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@ -43,12 +41,12 @@ public class BedBlockEntityTranslator extends BlockEntityTranslator implements R
} }
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
byte bedcolor = BlockStateValues.getBedColor(blockState); byte bedcolor = BlockStateValues.getBedColor(blockState);
// Just in case... // Just in case...
if (bedcolor == -1) bedcolor = 0; if (bedcolor == -1) bedcolor = 0;
tags.add(new ByteTag("color", bedcolor)); tags.put("color", bedcolor);
return tags; return tags;
} }
@ -58,9 +56,9 @@ public class BedBlockEntityTranslator extends BlockEntityTranslator implements R
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.byteTag("color", (byte) 0); .putByte("color", (byte) 0)
return tagBuilder.buildRootTag(); .build();
} }
} }

View file

@ -27,7 +27,7 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMap;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
/** /**
@ -49,7 +49,7 @@ public interface BedrockOnlyBlockEntity {
* @param blockState Java BlockState of block. * @param blockState Java BlockState of block.
* @return Bedrock tag, or null if not a Bedrock-only Block Entity * @return Bedrock tag, or null if not a Bedrock-only Block Entity
*/ */
static CompoundTag getTag(Vector3i position, int blockState) { static NbtMap getTag(Vector3i position, int blockState) {
if (new FlowerPotBlockEntityTranslator().isBlock(blockState)) { if (new FlowerPotBlockEntityTranslator().isBlock(blockState)) {
return FlowerPotBlockEntityTranslator.getTag(blockState, position); return FlowerPotBlockEntityTranslator.getTag(blockState, position);
} else if (PistonBlockEntityTranslator.isBlock(blockState)) { } else if (PistonBlockEntityTranslator.isBlock(blockState)) {

View file

@ -28,8 +28,8 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.Tag; import com.nukkitx.nbt.NbtMapBuilder;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
@ -37,7 +37,6 @@ import org.geysermc.connector.utils.BlockEntityUtils;
import org.reflections.Reflections; import org.reflections.Reflections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class BlockEntityTranslator { public abstract class BlockEntityTranslator {
@ -87,20 +86,21 @@ public abstract class BlockEntityTranslator {
} }
} }
public abstract List<Tag<?>> translateTag(CompoundTag tag, int blockState); public abstract Map<String, Object> translateTag(CompoundTag tag, int blockState);
public abstract CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z); public abstract CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z);
public abstract com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z); public abstract NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z);
public com.nukkitx.nbt.tag.CompoundTag getBlockEntityTag(String id, CompoundTag tag, int blockState) { public NbtMap getBlockEntityTag(String id, CompoundTag tag, int blockState) {
int x = Integer.parseInt(String.valueOf(tag.getValue().get("x").getValue())); int x = Integer.parseInt(String.valueOf(tag.getValue().get("x").getValue()));
int y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue())); int y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue()));
int z = Integer.parseInt(String.valueOf(tag.getValue().get("z").getValue())); int z = Integer.parseInt(String.valueOf(tag.getValue().get("z").getValue()));
CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(id), x, y, z).toBuilder(); NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(id), x, y, z).toBuilder();
translateTag(tag, blockState).forEach(tagBuilder::tag); Map<String, Object> translatedTags = translateTag(tag, blockState);
return tagBuilder.buildRootTag(); translatedTags.forEach(tagBuilder::put);
return tagBuilder.build();
} }
protected CompoundTag getConstantJavaTag(String javaId, int x, int y, int z) { protected CompoundTag getConstantJavaTag(String javaId, int x, int y, int z) {
@ -112,13 +112,13 @@ public abstract class BlockEntityTranslator {
return tag; return tag;
} }
protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(String bedrockId, int x, int y, int z) { protected NbtMap getConstantBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() return NbtMap.builder()
.intTag("x", x) .putInt("x", x)
.intTag("y", y) .putInt("y", y)
.intTag("z", z) .putInt("z", z)
.stringTag("id", bedrockId); .putString("id", bedrockId)
return tagBuilder.buildRootTag(); .build();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -27,25 +27,24 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.Tag; import com.nukkitx.nbt.NbtMapBuilder;
import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "Campfire", regex = "campfire") @BlockEntity(name = "Campfire", regex = "campfire")
public class CampfireBlockEntityTranslator extends BlockEntityTranslator { public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
ListTag items = tag.get("Items"); ListTag items = tag.get("Items");
int i = 1; int i = 1;
for (com.github.steveice10.opennbt.tag.builtin.Tag itemTag : items.getValue()) { for (com.github.steveice10.opennbt.tag.builtin.Tag itemTag : items.getValue()) {
tags.add(getItem((CompoundTag) itemTag).toBuilder().build("Item" + i)); tags.put("Item" + i, getItem((CompoundTag) itemTag));
i++; i++;
} }
return tags; return tags;
@ -59,22 +58,17 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z);
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item1", new HashMap<>()));
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>()));
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>()));
tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item4", new HashMap<>()));
return tagBuilder.buildRootTag();
} }
protected com.nukkitx.nbt.tag.CompoundTag getItem(CompoundTag tag) { protected NbtMap getItem(CompoundTag tag) {
ItemEntry entry = ItemRegistry.getItemEntry((String) tag.get("id").getValue()); ItemEntry entry = ItemRegistry.getItemEntry((String) tag.get("id").getValue());
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() NbtMapBuilder tagBuilder = NbtMap.builder()
.shortTag("id", (short) entry.getBedrockId()) .putShort("id", (short) entry.getBedrockId())
.byteTag("Count", (byte) tag.get("Count").getValue()) .putByte("Count", (byte) tag.get("Count").getValue())
.shortTag("Damage", (short) entry.getBedrockData()) .putShort("Damage", (short) entry.getBedrockData());
.tag(CompoundTagBuilder.builder().build("tag")); tagBuilder.put("tag", NbtMap.builder().build());
return tagBuilder.buildRootTag(); return tagBuilder.build();
} }
} }

View file

@ -28,17 +28,15 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.ByteTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.tag.IntTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import org.geysermc.connector.network.translators.world.block.DoubleChestValue; import org.geysermc.connector.network.translators.world.block.DoubleChestValue;
import org.geysermc.connector.utils.BlockEntityUtils; import org.geysermc.connector.utils.BlockEntityUtils;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
/** /**
* Chests have more block entity properties in Bedrock, which is solved by implementing the BedrockOnlyBlockEntity * Chests have more block entity properties in Bedrock, which is solved by implementing the BedrockOnlyBlockEntity
@ -54,14 +52,14 @@ public class DoubleChestBlockEntityTranslator extends BlockEntityTranslator impl
@Override @Override
public void updateBlock(GeyserSession session, int blockState, Vector3i position) { public void updateBlock(GeyserSession session, int blockState, Vector3i position) {
CompoundTag javaTag = getConstantJavaTag("chest", position.getX(), position.getY(), position.getZ()); CompoundTag javaTag = getConstantJavaTag("chest", position.getX(), position.getY(), position.getZ());
CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId("chest"), position.getX(), position.getY(), position.getZ()).toBuilder(); NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId("chest"), position.getX(), position.getY(), position.getZ()).toBuilder();
translateTag(javaTag, blockState).forEach(tagBuilder::tag); translateTag(javaTag, blockState).forEach(tagBuilder::put);
BlockEntityUtils.updateBlockEntity(session, tagBuilder.buildRootTag(), position); BlockEntityUtils.updateBlockEntity(session, tagBuilder.build(), position);
} }
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
if (BlockStateValues.getDoubleChestValues().containsKey(blockState)) { if (BlockStateValues.getDoubleChestValues().containsKey(blockState)) {
DoubleChestValue chestValues = BlockStateValues.getDoubleChestValues().get(blockState); DoubleChestValue chestValues = BlockStateValues.getDoubleChestValues().get(blockState);
if (chestValues != null) { if (chestValues != null) {
@ -85,10 +83,10 @@ public class DoubleChestBlockEntityTranslator extends BlockEntityTranslator impl
x = x + (chestValues.isLeft ? 1 : -1); x = x + (chestValues.isLeft ? 1 : -1);
} }
} }
tags.add(new IntTag("pairx", x)); tags.put("pairx", x);
tags.add(new IntTag("pairz", z)); tags.put("pairz", z);
if (!chestValues.isLeft) { if (!chestValues.isLeft) {
tags.add(new ByteTag("pairlead", (byte) 1)); tags.put("pairlead", (byte) 1);
} }
} }
} }
@ -101,7 +99,7 @@ public class DoubleChestBlockEntityTranslator extends BlockEntityTranslator impl
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
return null; return null;
} }
} }

View file

@ -26,17 +26,17 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.tag.Tag; import com.nukkitx.nbt.NbtMap;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "Empty", regex = "") @BlockEntity(name = "Empty", regex = "")
public class EmptyBlockEntityTranslator extends BlockEntityTranslator { public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
return new ArrayList<>(); return new HashMap<>();
} }
@Override @Override
@ -45,7 +45,7 @@ public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
return getConstantBedrockTag(bedrockId, x, y, z); return getConstantBedrockTag(bedrockId, x, y, z);
} }
} }

View file

@ -27,31 +27,32 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag; import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.tag.IntTag; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.Tag; import com.nukkitx.nbt.NbtType;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.ArrayList; import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "EndGateway", regex = "end_gateway") @BlockEntity(name = "EndGateway", regex = "end_gateway")
public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator { public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
tags.add(new IntTag("Age", (int) (long) tag.get("Age").getValue())); tags.put("Age", (int) ((long) tag.get("Age").getValue()));
// Java sometimes does not provide this tag, but Bedrock crashes if it doesn't exist // Java sometimes does not provide this tag, but Bedrock crashes if it doesn't exist
// Linked coordinates // Linked coordinates
List<IntTag> tagsList = new ArrayList<>(); IntList tagsList = new IntArrayList();
// Yes, the axis letters are capitalized // Yes, the axis letters are capitalized
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "X"))); tagsList.add(getExitPortalCoordinate(tag, "X"));
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Y"))); tagsList.add(getExitPortalCoordinate(tag, "Y"));
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Z"))); tagsList.add(getExitPortalCoordinate(tag, "Z"));
com.nukkitx.nbt.tag.ListTag<IntTag> exitPortal = tags.put("ExitPortal", new NbtList<>(NbtType.INT, tagsList));
new com.nukkitx.nbt.tag.ListTag<>("ExitPortal", IntTag.class, tagsList);
tags.add(exitPortal);
return tags; return tags;
} }
@ -63,20 +64,16 @@ public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
List<IntTag> tagsList = new ArrayList<>(); .putList("ExitPortal", NbtType.INT, Arrays.asList(0, 0, 0))
tagsList.add(new IntTag("", 0)); .build();
tagsList.add(new IntTag("", 0));
tagsList.add(new IntTag("", 0));
tagBuilder.listTag("ExitPortal", IntTag.class, tagsList);
return tagBuilder.buildRootTag();
} }
private int getExitPortalCoordinate(CompoundTag tag, String axis) { private int getExitPortalCoordinate(CompoundTag tag, String axis) {
// Return 0 if it doesn't exist, otherwise give proper value // Return 0 if it doesn't exist, otherwise give proper value
if (tag.get("ExitPortal") != null) { if (tag.get("ExitPortal") != null) {
LinkedHashMap compoundTag = (LinkedHashMap) tag.get("ExitPortal").getValue(); LinkedHashMap<?, ?> compoundTag = (LinkedHashMap<?, ?>) tag.get("ExitPortal").getValue();
com.github.steveice10.opennbt.tag.builtin.IntTag intTag = (com.github.steveice10.opennbt.tag.builtin.IntTag) compoundTag.get(axis); com.github.steveice10.opennbt.tag.builtin.IntTag intTag = (com.github.steveice10.opennbt.tag.builtin.IntTag) compoundTag.get(axis);
return intTag.getValue(); return intTag.getValue();
} return 0; } return 0;

View file

@ -27,8 +27,8 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
@ -62,23 +62,23 @@ public class FlowerPotBlockEntityTranslator implements BedrockOnlyBlockEntity, R
* @param position Bedrock position of flower pot. * @param position Bedrock position of flower pot.
* @return Bedrock tag of flower pot. * @return Bedrock tag of flower pot.
*/ */
public static CompoundTag getTag(int blockState, Vector3i position) { public static NbtMap getTag(int blockState, Vector3i position) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() NbtMapBuilder tagBuilder = NbtMap.builder()
.intTag("x", position.getX()) .putInt("x", position.getX())
.intTag("y", position.getY()) .putInt("y", position.getY())
.intTag("z", position.getZ()) .putInt("z", position.getZ())
.byteTag("isMovable", (byte) 1) .putByte("isMovable", (byte) 1)
.stringTag("id", "FlowerPot"); .putString("id", "FlowerPot");
// Get the Java name of the plant inside. e.g. minecraft:oak_sapling // Get the Java name of the plant inside. e.g. minecraft:oak_sapling
String name = BlockStateValues.getFlowerPotValues().get(blockState); String name = BlockStateValues.getFlowerPotValues().get(blockState);
if (name != null) { if (name != null) {
// Get the Bedrock CompoundTag of the block. // Get the Bedrock CompoundTag of the block.
// This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states. // This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states.
CompoundTag plant = BlockStateValues.getFlowerPotBlocks().get(name); NbtMap plant = BlockStateValues.getFlowerPotBlocks().get(name);
if (plant != null) { if (plant != null) {
tagBuilder.tag(plant.toBuilder().build("PlantBlock")); tagBuilder.put("PlantBlock", plant.toBuilder().build());
} }
} }
return tagBuilder.buildRootTag(); return tagBuilder.build();
} }
} }

View file

@ -27,8 +27,8 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.NbtMapBuilder;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
/** /**
@ -51,21 +51,21 @@ public class PistonBlockEntityTranslator {
* @param position Bedrock position of piston. * @param position Bedrock position of piston.
* @return Bedrock tag of piston. * @return Bedrock tag of piston.
*/ */
public static CompoundTag getTag(int blockState, Vector3i position) { public static NbtMap getTag(int blockState, Vector3i position) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() NbtMapBuilder tagBuilder = NbtMap.builder()
.intTag("x", position.getX()) .putInt("x", position.getX())
.intTag("y", position.getY()) .putInt("y", position.getY())
.intTag("z", position.getZ()) .putInt("z", position.getZ())
.byteTag("isMovable", (byte) 1) .putByte("isMovable", (byte) 1)
.stringTag("id", "PistonArm"); .putString("id", "PistonArm");
if (BlockStateValues.getPistonValues().containsKey(blockState)) { if (BlockStateValues.getPistonValues().containsKey(blockState)) {
boolean extended = BlockStateValues.getPistonValues().get(blockState); boolean extended = BlockStateValues.getPistonValues().get(blockState);
// 1f if extended, otherwise 0f // 1f if extended, otherwise 0f
tagBuilder.floatTag("Progress", (extended) ? 1.0f : 0.0f); tagBuilder.putFloat("Progress", (extended) ? 1.0f : 0.0f);
// 1 if sticky, 0 if not // 1 if sticky, 0 if not
tagBuilder.byteTag("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0)); tagBuilder.putByte("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0));
} }
return tagBuilder.buildRootTag(); return tagBuilder.build();
} }
} }

View file

@ -27,26 +27,23 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.ByteTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "ShulkerBox", regex = "shulker_box") @BlockEntity(name = "ShulkerBox", regex = "shulker_box")
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator { public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
byte direction = BlockStateValues.getShulkerBoxDirection(blockState); byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
// Just in case... // Just in case...
if (direction == -1) direction = 1; if (direction == -1) direction = 1;
tags.add(new ByteTag("facing", direction)); tags.put("facing", direction);
return tags; return tags;
} }
@ -56,9 +53,9 @@ public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.byteTag("facing", (byte)1); .putByte("facing", (byte) 1)
return tagBuilder.buildRootTag(); .build();
} }
} }

View file

@ -27,20 +27,18 @@ package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.StringTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "Sign", regex = "sign") @BlockEntity(name = "Sign", regex = "sign")
public class SignBlockEntityTranslator extends BlockEntityTranslator { public class SignBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
StringBuilder signText = new StringBuilder(); StringBuilder signText = new StringBuilder();
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
@ -57,7 +55,7 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
signText.append("\n"); signText.append("\n");
} }
tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(MessageSerializer.fromString(signText.toString())))); tags.put("Text", MessageUtils.getBedrockMessage(MessageSerializer.fromString(signText.toString())));
return tags; return tags;
} }
@ -72,9 +70,9 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.stringTag("Text", ""); .putString("Text", "")
return tagBuilder.buildRootTag(); .build();
} }
} }

View file

@ -25,15 +25,11 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.ByteTag;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.FloatTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; import org.geysermc.connector.network.translators.world.block.BlockStateValues;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "Skull", regex = "skull") @BlockEntity(name = "Skull", regex = "skull")
public class SkullBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { public class SkullBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
@ -44,14 +40,14 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements
} }
@Override @Override
public List<Tag<?>> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, int blockState) { public Map<String, Object> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
byte skullVariant = BlockStateValues.getSkullVariant(blockState); byte skullVariant = BlockStateValues.getSkullVariant(blockState);
float rotation = BlockStateValues.getSkullRotation(blockState) * 22.5f; float rotation = BlockStateValues.getSkullRotation(blockState) * 22.5f;
// Just in case... // Just in case...
if (skullVariant == -1) skullVariant = 0; if (skullVariant == -1) skullVariant = 0;
tags.add(new FloatTag("Rotation", rotation)); tags.put("Rotation", rotation);
tags.add(new ByteTag("SkullType", skullVariant)); tags.put("SkullType", skullVariant);
return tags; return tags;
} }
@ -61,10 +57,10 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements
} }
@Override @Override
public CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.floatTag("Rotation", 0); .putFloat("Rotation", 0f)
tagBuilder.byteTag("SkullType", (byte) 0); .putByte("SkullType", (byte) 0)
return tagBuilder.buildRootTag(); .build();
} }
} }

View file

@ -27,63 +27,62 @@
package org.geysermc.connector.network.translators.world.block.entity; package org.geysermc.connector.network.translators.world.block.entity;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.*;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
@BlockEntity(name = "MobSpawner", regex = "mob_spawner") @BlockEntity(name = "MobSpawner", regex = "mob_spawner")
public class SpawnerBlockEntityTranslator extends BlockEntityTranslator { public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {
@Override @Override
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) { public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
List<Tag<?>> tags = new ArrayList<>(); Map<String, Object> tags = new HashMap<>();
if (tag.get("MaxNearbyEntities") != null) { if (tag.get("MaxNearbyEntities") != null) {
tags.add(new ShortTag("MaxNearbyEntities", (short) tag.get("MaxNearbyEntities").getValue())); tags.put("MaxNearbyEntities", (short) tag.get("MaxNearbyEntities").getValue());
} }
if (tag.get("RequiredPlayerRange") != null) { if (tag.get("RequiredPlayerRange") != null) {
tags.add(new ShortTag("RequiredPlayerRange", (short) tag.get("RequiredPlayerRange").getValue())); tags.put("RequiredPlayerRange", (short) tag.get("RequiredPlayerRange").getValue());
} }
if (tag.get("SpawnCount") != null) { if (tag.get("SpawnCount") != null) {
tags.add(new ShortTag("SpawnCount", (short) tag.get("SpawnCount").getValue())); tags.put("SpawnCount", (short) tag.get("SpawnCount").getValue());
} }
if (tag.get("MaxSpawnDelay") != null) { if (tag.get("MaxSpawnDelay") != null) {
tags.add(new ShortTag("MaxSpawnDelay", (short) tag.get("MaxSpawnDelay").getValue())); tags.put("MaxSpawnDelay", (short) tag.get("MaxSpawnDelay").getValue());
} }
if (tag.get("Delay") != null) { if (tag.get("Delay") != null) {
tags.add(new ShortTag("Delay", (short) tag.get("Delay").getValue())); tags.put("Delay", (short) tag.get("Delay").getValue());
} }
if (tag.get("SpawnRange") != null) { if (tag.get("SpawnRange") != null) {
tags.add(new ShortTag("SpawnRange", (short) tag.get("SpawnRange").getValue())); tags.put("SpawnRange", (short) tag.get("SpawnRange").getValue());
} }
if (tag.get("MinSpawnDelay") != null) { if (tag.get("MinSpawnDelay") != null) {
tags.add(new ShortTag("MinSpawnDelay", (short) tag.get("MinSpawnDelay").getValue())); tags.put("MinSpawnDelay", (short) tag.get("MinSpawnDelay").getValue());
} }
if (tag.get("SpawnData") != null) { if (tag.get("SpawnData") != null) {
CompoundTag spawnData = tag.get("SpawnData"); CompoundTag spawnData = tag.get("SpawnData");
String entityID = (String) spawnData.get("id").getValue(); String entityID = (String) spawnData.get("id").getValue();
tags.add(new StringTag("EntityIdentifier", entityID)); tags.put("EntityIdentifier", entityID);
EntityType type = EntityType.getFromIdentifier(entityID); EntityType type = EntityType.getFromIdentifier(entityID);
if (type != null) { if (type != null) {
tags.add(new FloatTag("DisplayEntityWidth", type.getWidth())); tags.put("DisplayEntityWidth", type.getWidth());
tags.add(new FloatTag("DisplayEntityHeight", type.getHeight())); tags.put("DisplayEntityHeight", type.getHeight());
tags.add(new FloatTag("DisplayEntityScale", 1.0f)); tags.put("DisplayEntityScale", 1.0f);
} }
} }
tags.add(new StringTag("id", "MobSpawner")); tags.put("id", "MobSpawner");
tags.add(new ByteTag("isMovable", (byte) 1)); tags.put("isMovable", (byte) 1);
return tags; return tags;
} }
@ -94,11 +93,10 @@ public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {
} }
@Override @Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
tagBuilder.byteTag("isMovable", (byte) 1) .putByte("isMovable", (byte) 1)
.stringTag("id", "MobSpawner"); .putString("id", "MobSpawner")
.build();
return tagBuilder.buildRootTag();
} }
} }

View file

@ -2,6 +2,7 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator; import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
@ -41,11 +42,11 @@ public class BlockEntityUtils {
return blockEntityTranslator; return blockEntityTranslator;
} }
public static void updateBlockEntity(GeyserSession session, com.nukkitx.nbt.tag.CompoundTag blockEntity, Position position) { public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Position position) {
updateBlockEntity(session, blockEntity, Vector3i.from(position.getX(), position.getY(), position.getZ())); updateBlockEntity(session, blockEntity, Vector3i.from(position.getX(), position.getY(), position.getZ()));
} }
public static void updateBlockEntity(GeyserSession session, com.nukkitx.nbt.tag.CompoundTag blockEntity, Vector3i position) { public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Vector3i position) {
BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket(); BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
blockEntityPacket.setBlockPosition(position); blockEntityPacket.setBlockPosition(position);
blockEntityPacket.setData(blockEntity); blockEntityPacket.setData(blockEntity);

View file

@ -33,9 +33,9 @@ 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.math.vector.Vector2i; import com.nukkitx.math.vector.Vector2i;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NBTOutputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@ -64,7 +64,7 @@ public class ChunkUtils {
*/ */
public static final Object2IntMap<Position> CACHED_BLOCK_ENTITIES = new Object2IntOpenHashMap<>(); public static final Object2IntMap<Position> CACHED_BLOCK_ENTITIES = new Object2IntOpenHashMap<>();
private static final com.nukkitx.nbt.tag.CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag(); private static final NbtMap EMPTY_TAG = NbtMap.builder().build();
public static final byte[] EMPTY_LEVEL_CHUNK_DATA; public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
static { static {
@ -72,7 +72,7 @@ public class ChunkUtils {
outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size
try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) { try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
stream.write(EMPTY_TAG); stream.writeTag(EMPTY_TAG);
} }
EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray(); EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
@ -91,7 +91,7 @@ public class ChunkUtils {
Object2IntMap<Position> blockEntityPositions = new Object2IntOpenHashMap<>(); Object2IntMap<Position> blockEntityPositions = new Object2IntOpenHashMap<>();
// Temporarily stores compound tags of Bedrock-only block entities // Temporarily stores compound tags of Bedrock-only block entities
ObjectArrayList<com.nukkitx.nbt.tag.CompoundTag> bedrockOnlyBlockEntities = new ObjectArrayList<>(); ObjectArrayList<NbtMap> bedrockOnlyBlockEntities = new ObjectArrayList<>();
for (int chunkY = 0; chunkY < chunks.length; chunkY++) { for (int chunkY = 0; chunkY < chunks.length; chunkY++) {
chunkData.sections[chunkY] = new ChunkSection(); chunkData.sections[chunkY] = new ChunkSection();
@ -131,7 +131,7 @@ public class ChunkUtils {
} }
com.nukkitx.nbt.tag.CompoundTag[] bedrockBlockEntities = new com.nukkitx.nbt.tag.CompoundTag[blockEntities.length + bedrockOnlyBlockEntities.size()]; NbtMap[] bedrockBlockEntities = new NbtMap[blockEntities.length + bedrockOnlyBlockEntities.size()];
int i = 0; int i = 0;
while (i < blockEntities.length) { while (i < blockEntities.length) {
CompoundTag tag = blockEntities[i]; CompoundTag tag = blockEntities[i];
@ -162,7 +162,7 @@ public class ChunkUtils {
bedrockBlockEntities[i] = blockEntityTranslator.getBlockEntityTag(tagName, tag, blockState); bedrockBlockEntities[i] = blockEntityTranslator.getBlockEntityTag(tagName, tag, blockState);
i++; i++;
} }
for (com.nukkitx.nbt.tag.CompoundTag tag : bedrockOnlyBlockEntities) { for (NbtMap tag : bedrockOnlyBlockEntities) {
bedrockBlockEntities[i] = tag; bedrockBlockEntities[i] = tag;
i++; i++;
} }
@ -270,8 +270,8 @@ public class ChunkUtils {
public ChunkSection[] sections; public ChunkSection[] sections;
@Getter @Getter
private com.nukkitx.nbt.tag.CompoundTag[] blockEntities = new com.nukkitx.nbt.tag.CompoundTag[0]; private NbtMap[] blockEntities = new NbtMap[0];
@Getter @Getter
private Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> loadBlockEntitiesLater = new Object2IntOpenHashMap<>(); private Object2IntMap<NbtMap> loadBlockEntitiesLater = new Object2IntOpenHashMap<>();
} }
} }

View file

@ -27,8 +27,9 @@ package org.geysermc.connector.utils;
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.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.tag.StringTag; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId; import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
@ -136,13 +137,13 @@ public class InventoryUtils {
* part of the inventory is unusable. * part of the inventory is unusable.
*/ */
public static ItemData createUnusableSpaceBlock(String description) { public static ItemData createUnusableSpaceBlock(String description) {
CompoundTagBuilder root = CompoundTagBuilder.builder(); NbtMapBuilder root = NbtMap.builder();
CompoundTagBuilder display = CompoundTagBuilder.builder(); NbtMapBuilder display = NbtMap.builder();
display.stringTag("Name", ChatColor.RESET + "Unusable inventory space"); display.putString("Name", ChatColor.RESET + "Unusable inventory space");
display.listTag("Lore", StringTag.class, Collections.singletonList(new StringTag("", ChatColor.RESET + ChatColor.DARK_PURPLE + description))); display.putList("Lore", NbtType.STRING, Collections.singletonList(ChatColor.RESET + ChatColor.DARK_PURPLE + description));
root.tag(display.build("display")); root.put("display", display.build());
return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.buildRootTag()); return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.build());
} }
} }

View file

@ -26,12 +26,6 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.github.steveice10.opennbt.tag.builtin.*; import com.github.steveice10.opennbt.tag.builtin.*;
import com.nukkitx.nbt.CompoundTagBuilder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ItemUtils { public class ItemUtils {