forked from GeyserMC/Geyser
Update to Cloudburst NBT 2.0
This commit is contained in:
parent
5958b5d0ba
commit
da1674c8d6
39 changed files with 550 additions and 584 deletions
|
@ -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.Tag;
|
||||
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.packet.SetEntityMotionPacket;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
|
@ -49,7 +51,6 @@ public class FireworkEntity extends Entity {
|
|||
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||
if (entityMetadata.getId() == 7) {
|
||||
|
@ -62,19 +63,19 @@ public class FireworkEntity extends Entity {
|
|||
|
||||
CompoundTag fireworks = tag.get("Fireworks");
|
||||
|
||||
CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();
|
||||
NbtMapBuilder fireworksBuilder = NbtMap.builder();
|
||||
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) {
|
||||
for (Tag effect : ((ListTag) fireworks.get("Explosions")).getValue()) {
|
||||
CompoundTag effectData = (CompoundTag) effect;
|
||||
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder();
|
||||
NbtMapBuilder effectBuilder = NbtMap.builder();
|
||||
|
||||
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) {
|
||||
|
@ -86,7 +87,7 @@ public class FireworkEntity extends Entity {
|
|||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
effectBuilder.byteArrayTag("FireworkColor", colors);
|
||||
effectBuilder.putByteArray("FireworkColor", colors);
|
||||
}
|
||||
|
||||
if (effectData.get("FadeColors") != null) {
|
||||
|
@ -98,24 +99,24 @@ public class FireworkEntity extends Entity {
|
|||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
effectBuilder.byteArrayTag("FireworkFade", colors);
|
||||
effectBuilder.putByteArray("FireworkFade", colors);
|
||||
}
|
||||
|
||||
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) {
|
||||
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()) {
|
||||
//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();
|
||||
|
|
|
@ -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.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
|
@ -66,21 +66,21 @@ public class ItemFrameEntity extends Entity {
|
|||
/**
|
||||
* 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) {
|
||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||
CompoundTagBuilder builder = CompoundTag.builder();
|
||||
builder.tag(CompoundTag.builder()
|
||||
.stringTag("name", "minecraft:frame")
|
||||
.intTag("version", BlockTranslator.getBlockStateVersion())
|
||||
.tag(CompoundTag.builder()
|
||||
.intTag("facing_direction", direction.ordinal())
|
||||
.byteTag("item_frame_map_bit", (byte) 0)
|
||||
.build("states"))
|
||||
.build("block"));
|
||||
builder.shortTag("id", (short) 199);
|
||||
bedrockRuntimeId = BlockTranslator.getItemFrame(builder.buildRootTag());
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
NbtMapBuilder blockBuilder = NbtMap.builder()
|
||||
.putString("name", "minecraft:frame")
|
||||
.putInt("version", BlockTranslator.getBlockStateVersion());
|
||||
blockBuilder.put("states", NbtMap.builder()
|
||||
.putInt("facing_direction", direction.ordinal())
|
||||
.putByte("item_frame_map_bit", (byte) 0)
|
||||
.build());
|
||||
builder.put("block", blockBuilder.build());
|
||||
builder.putShort("id", (short) 199);
|
||||
bedrockRuntimeId = BlockTranslator.getItemFrame(builder.build());
|
||||
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) {
|
||||
ItemData itemData = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
|
||||
ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue());
|
||||
CompoundTagBuilder builder = CompoundTag.builder();
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
|
||||
String blockName = "";
|
||||
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) {
|
||||
builder.tag(itemData.getTag().toBuilder().build("tag"));
|
||||
builder.put("tag", itemData.getTag().toBuilder().build());
|
||||
}
|
||||
builder.shortTag("Damage", itemData.getDamage());
|
||||
builder.stringTag("Name", blockName);
|
||||
CompoundTagBuilder tag = getDefaultTag().toBuilder();
|
||||
tag.tag(builder.build("Item"));
|
||||
tag.floatTag("ItemDropChance", 1.0f);
|
||||
tag.floatTag("ItemRotation", rotation);
|
||||
cachedTag = tag.buildRootTag();
|
||||
builder.putShort("Damage", itemData.getDamage());
|
||||
builder.putString("Name", blockName);
|
||||
NbtMapBuilder tag = getDefaultTag().toBuilder();
|
||||
tag.put("Item", builder.build());
|
||||
tag.putFloat("ItemDropChance", 1.0f);
|
||||
tag.putFloat("ItemRotation", rotation);
|
||||
cachedTag = tag.build();
|
||||
updateBlock(session);
|
||||
}
|
||||
else if (entityMetadata.getId() == 7 && entityMetadata.getValue() == null && cachedTag != null) {
|
||||
|
@ -133,9 +133,9 @@ public class ItemFrameEntity extends Entity {
|
|||
updateBlock(session);
|
||||
return;
|
||||
}
|
||||
CompoundTagBuilder builder = cachedTag.toBuilder();
|
||||
builder.floatTag("ItemRotation", rotation);
|
||||
cachedTag = builder.buildRootTag();
|
||||
NbtMapBuilder builder = cachedTag.toBuilder();
|
||||
builder.putFloat("ItemRotation", rotation);
|
||||
cachedTag = builder.build();
|
||||
updateBlock(session);
|
||||
}
|
||||
else {
|
||||
|
@ -158,14 +158,14 @@ public class ItemFrameEntity extends Entity {
|
|||
return true;
|
||||
}
|
||||
|
||||
private CompoundTag getDefaultTag() {
|
||||
CompoundTagBuilder builder = CompoundTag.builder();
|
||||
builder.intTag("x", bedrockPosition.getX());
|
||||
builder.intTag("y", bedrockPosition.getY());
|
||||
builder.intTag("z", bedrockPosition.getZ());
|
||||
builder.byteTag("isMovable", (byte) 1);
|
||||
builder.stringTag("id", "ItemFrame");
|
||||
return builder.buildRootTag();
|
||||
private NbtMap getDefaultTag() {
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
builder.putInt("x", bedrockPosition.getX());
|
||||
builder.putInt("y", bedrockPosition.getY());
|
||||
builder.putInt("z", bedrockPosition.getZ());
|
||||
builder.putByte("isMovable", (byte) 1);
|
||||
builder.putString("id", "ItemFrame");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -218,11 +218,11 @@ public class GeyserSession implements CommandSender {
|
|||
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
||||
|
||||
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
|
||||
biomeDefinitionListPacket.setTag(BiomeTranslator.BIOMES);
|
||||
biomeDefinitionListPacket.setDefinitions(BiomeTranslator.BIOMES);
|
||||
upstream.sendPacket(biomeDefinitionListPacket);
|
||||
|
||||
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
||||
entityPacket.setTag(EntityIdentifierRegistry.ENTITY_IDENTIFIERS);
|
||||
entityPacket.setIdentifiers(EntityIdentifierRegistry.ENTITY_IDENTIFIERS);
|
||||
upstream.sendPacket(entityPacket);
|
||||
|
||||
CreativeContentPacket creativePacket = new CreativeContentPacket();
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
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.stream.NBTInputStream;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
|
||||
|
@ -40,7 +40,7 @@ import java.util.Arrays;
|
|||
// Array index formula by https://wiki.vg/Chunk_Format
|
||||
public class BiomeTranslator {
|
||||
|
||||
public static final CompoundTag BIOMES;
|
||||
public static final NbtMap BIOMES;
|
||||
|
||||
private BiomeTranslator() {
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ public class BiomeTranslator {
|
|||
/* Load biomes */
|
||||
InputStream stream = FileUtils.getResource("bedrock/biome_definitions.dat");
|
||||
|
||||
CompoundTag biomesTag;
|
||||
NbtMap biomesTag;
|
||||
|
||||
try (NBTInputStream biomenbtInputStream = NbtUtils.createNetworkReader(stream)) {
|
||||
biomesTag = (CompoundTag) biomenbtInputStream.readTag();
|
||||
biomesTag = (NbtMap) biomenbtInputStream.readTag();
|
||||
BIOMES = biomesTag;
|
||||
} catch (Exception ex) {
|
||||
GeyserConnector.getInstance().getLogger().warning("Failed to get biomes from biome definitions, is there something wrong with the file?");
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
|
||||
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.stream.NBTInputStream;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -38,7 +38,7 @@ import java.io.InputStream;
|
|||
*/
|
||||
public class EntityIdentifierRegistry {
|
||||
|
||||
public static CompoundTag ENTITY_IDENTIFIERS;
|
||||
public static NbtMap ENTITY_IDENTIFIERS;
|
||||
|
||||
private EntityIdentifierRegistry() {
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class EntityIdentifierRegistry {
|
|||
InputStream stream = FileUtils.getResource("bedrock/entity_identifiers.dat");
|
||||
|
||||
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
|
||||
ENTITY_IDENTIFIERS = (CompoundTag) nbtInputStream.readTag();
|
||||
ENTITY_IDENTIFIERS = (NbtMap) nbtInputStream.readTag();
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to get entities from entity identifiers", e);
|
||||
}
|
||||
|
|
|
@ -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.packet.ingame.client.world.ClientUpdateSignPacket;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
@ -45,47 +45,45 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
|
|||
|
||||
@Override
|
||||
public void translate(BlockEntityDataPacket packet, GeyserSession session) {
|
||||
if (packet.getData() instanceof CompoundTag) {
|
||||
CompoundTag tag = (CompoundTag) packet.getData();
|
||||
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
|
||||
// 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
|
||||
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
|
||||
if (!tag.getString("Text").equals(lastMessages.get(pos))) {
|
||||
lastMessages.put(pos, tag.getString("Text"));
|
||||
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);
|
||||
NbtMap tag = packet.getData();
|
||||
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
|
||||
// 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
|
||||
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
|
||||
if (!tag.getString("Text").equals(lastMessages.get(pos))) {
|
||||
lastMessages.put(pos, tag.getString("Text"));
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,19 +26,19 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.bedrock;
|
||||
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.nbt.NbtType;
|
||||
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBClientRequestPacket;
|
||||
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.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
import org.geysermc.connector.utils.DimensionUtils;
|
||||
import org.geysermc.connector.utils.LoadstoneTracker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Translator(packet = PositionTrackingDBClientRequestPacket.class)
|
||||
public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTranslator<PositionTrackingDBClientRequestPacket> {
|
||||
|
||||
|
@ -60,22 +60,20 @@ public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTran
|
|||
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE);
|
||||
|
||||
// Build the nbt data for the update
|
||||
CompoundTagBuilder builder = CompoundTagBuilder.builder();
|
||||
builder.intTag("dim", DimensionUtils.javaToBedrock(pos.getDimension()));
|
||||
builder.stringTag("id", String.format("%08X", packet.getTrackingId()));
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
builder.putInt("dim", DimensionUtils.javaToBedrock(pos.getDimension()));
|
||||
builder.putString("id", String.format("%08X", packet.getTrackingId()));
|
||||
|
||||
builder.byteTag("version", (byte) 1); // Not sure what this is for
|
||||
builder.byteTag("status", (byte) 0); // Not sure what this is for
|
||||
builder.putByte("version", (byte) 1); // Not sure what this is for
|
||||
builder.putByte("status", (byte) 0); // Not sure what this is for
|
||||
|
||||
// Build the position for the update
|
||||
List<IntTag> posList = new ArrayList<>();
|
||||
posList.add(new IntTag("", pos.getX()));
|
||||
posList.add(new IntTag("", pos.getY()));
|
||||
posList.add(new IntTag("", pos.getZ()));
|
||||
|
||||
builder.listTag("pos", IntTag.class, posList);
|
||||
|
||||
broadcastPacket.setTag(builder.buildRootTag());
|
||||
IntList posList = new IntArrayList();
|
||||
posList.add(pos.getX());
|
||||
posList.add(pos.getY());
|
||||
posList.add(pos.getZ());
|
||||
builder.putList("pos", NbtType.INT, posList);
|
||||
broadcastPacket.setTag(builder.build());
|
||||
|
||||
session.sendUpstreamPacket(broadcastPacket);
|
||||
}
|
||||
|
|
|
@ -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.packet.ingame.client.window.ClientRenameItemPacket;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.*;
|
||||
import org.geysermc.connector.inventory.Inventory;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
@ -103,7 +104,7 @@ public class AnvilInventoryTranslator extends BlockInventoryTranslator {
|
|||
}
|
||||
if (itemName != null) {
|
||||
String rename;
|
||||
com.nukkitx.nbt.tag.CompoundTag tag = itemName.getTag();
|
||||
NbtMap tag = itemName.getTag();
|
||||
if (tag != null) {
|
||||
rename = tag.getCompound("display").getString("Name");
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.inventory;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
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.packet.BlockEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
||||
|
@ -57,14 +57,14 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
|||
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
||||
session.sendUpstreamPacket(blockPacket);
|
||||
|
||||
CompoundTag tag = CompoundTag.builder()
|
||||
.stringTag("id", "Chest")
|
||||
.intTag("x", position.getX())
|
||||
.intTag("y", position.getY())
|
||||
.intTag("z", position.getZ())
|
||||
.intTag("pairx", pairPosition.getX())
|
||||
.intTag("pairz", pairPosition.getZ())
|
||||
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
|
||||
NbtMap tag = NbtMap.builder()
|
||||
.putString("id", "Chest")
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.putInt("pairx", pairPosition.getX())
|
||||
.putInt("pairz", pairPosition.getZ())
|
||||
.putString("CustomName", inventory.getTitle()).build();
|
||||
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
|
||||
dataPacket.setData(tag);
|
||||
dataPacket.setBlockPosition(position);
|
||||
|
@ -77,14 +77,14 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
|||
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
||||
session.sendUpstreamPacket(blockPacket);
|
||||
|
||||
tag = CompoundTag.builder()
|
||||
.stringTag("id", "Chest")
|
||||
.intTag("x", pairPosition.getX())
|
||||
.intTag("y", pairPosition.getY())
|
||||
.intTag("z", pairPosition.getZ())
|
||||
.intTag("pairx", position.getX())
|
||||
.intTag("pairz", position.getZ())
|
||||
.stringTag("CustomName", inventory.getTitle()).buildRootTag();
|
||||
tag = NbtMap.builder()
|
||||
.putString("id", "Chest")
|
||||
.putInt("x", pairPosition.getX())
|
||||
.putInt("y", pairPosition.getY())
|
||||
.putInt("z", pairPosition.getZ())
|
||||
.putInt("pairx", position.getX())
|
||||
.putInt("pairz", position.getZ())
|
||||
.putString("CustomName", inventory.getTitle()).build();
|
||||
dataPacket = new BlockEntityDataPacket();
|
||||
dataPacket.setData(tag);
|
||||
dataPacket.setBlockPosition(pairPosition);
|
||||
|
|
|
@ -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.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.packet.BlockEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
||||
|
@ -56,11 +56,11 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||
session.sendUpstreamPacket(blockPacket);
|
||||
inventory.setHolderPosition(position);
|
||||
|
||||
CompoundTag tag = CompoundTag.builder()
|
||||
.intTag("x", position.getX())
|
||||
.intTag("y", position.getY())
|
||||
.intTag("z", position.getZ())
|
||||
.stringTag("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).buildRootTag();
|
||||
NbtMap tag = NbtMap.builder()
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.putString("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).build();
|
||||
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
|
||||
dataPacket.setData(tag);
|
||||
dataPacket.setBlockPosition(position);
|
||||
|
|
|
@ -29,6 +29,7 @@ package org.geysermc.connector.network.translators.item;
|
|||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtUtils;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
|
@ -156,7 +157,7 @@ public class ItemRegistry {
|
|||
byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText());
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
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));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -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.message.MessageSerializer;
|
||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
|
||||
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 it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
@ -150,9 +161,9 @@ public abstract class ItemTranslator {
|
|||
|
||||
|
||||
// Get the display name of the item
|
||||
CompoundTag tag = itemData.getTag();
|
||||
NbtMap tag = itemData.getTag();
|
||||
if (tag != null) {
|
||||
CompoundTag display = tag.getCompound("display");
|
||||
NbtMap display = tag.getCompound("display");
|
||||
if (display != null) {
|
||||
String name = display.getString("Name");
|
||||
|
||||
|
@ -162,15 +173,15 @@ public abstract class ItemTranslator {
|
|||
name = MessageUtils.getTranslatedBedrockMessage(MessageSerializer.fromString(name), session.getClientData().getLanguageCode());
|
||||
|
||||
// Build the new display tag
|
||||
CompoundTagBuilder displayBuilder = display.toBuilder();
|
||||
displayBuilder.stringTag("Name", name);
|
||||
NbtMapBuilder displayBuilder = display.toBuilder();
|
||||
displayBuilder.putString("Name", name);
|
||||
|
||||
// Build the new root tag
|
||||
CompoundTagBuilder builder = tag.toBuilder();
|
||||
builder.tag(displayBuilder.build("display"));
|
||||
NbtMapBuilder builder = tag.toBuilder();
|
||||
builder.put("display", displayBuilder.build());
|
||||
|
||||
// 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) {
|
||||
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 CompoundTag translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
||||
Map<String, Tag<?>> javaValue = new HashMap<>();
|
||||
public NbtMap translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
||||
Map<String, Object> javaValue = new HashMap<>();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
for (String str : tag.getValue().keySet()) {
|
||||
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)
|
||||
continue;
|
||||
|
||||
javaValue.put(translatedTag.getName(), translatedTag);
|
||||
javaValue.put(javaTag.getName(), translatedTag);
|
||||
}
|
||||
}
|
||||
|
||||
return new CompoundTag(tag.getName(), javaValue);
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
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) {
|
||||
ByteArrayTag byteArrayTag = (ByteArrayTag) tag;
|
||||
return new com.nukkitx.nbt.tag.ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
|
||||
return ((ByteArrayTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof ByteTag) {
|
||||
ByteTag byteTag = (ByteTag) tag;
|
||||
return new com.nukkitx.nbt.tag.ByteTag(byteTag.getName(), byteTag.getValue());
|
||||
return ((ByteTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof DoubleTag) {
|
||||
DoubleTag doubleTag = (DoubleTag) tag;
|
||||
return new com.nukkitx.nbt.tag.DoubleTag(doubleTag.getName(), doubleTag.getValue());
|
||||
return ((DoubleTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof FloatTag) {
|
||||
FloatTag floatTag = (FloatTag) tag;
|
||||
return new com.nukkitx.nbt.tag.FloatTag(floatTag.getName(), floatTag.getValue());
|
||||
return ((FloatTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof IntArrayTag) {
|
||||
IntArrayTag intArrayTag = (IntArrayTag) tag;
|
||||
return new com.nukkitx.nbt.tag.IntArrayTag(intArrayTag.getName(), intArrayTag.getValue());
|
||||
return ((IntArrayTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof IntTag) {
|
||||
IntTag intTag = (IntTag) tag;
|
||||
return new com.nukkitx.nbt.tag.IntTag(intTag.getName(), intTag.getValue());
|
||||
return ((IntTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof LongArrayTag) {
|
||||
|
@ -260,50 +266,46 @@ public abstract class ItemTranslator {
|
|||
}
|
||||
|
||||
if (tag instanceof LongTag) {
|
||||
LongTag longTag = (LongTag) tag;
|
||||
return new com.nukkitx.nbt.tag.LongTag(longTag.getName(), longTag.getValue());
|
||||
return ((LongTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof ShortTag) {
|
||||
ShortTag shortTag = (ShortTag) tag;
|
||||
return new com.nukkitx.nbt.tag.ShortTag(shortTag.getName(), shortTag.getValue());
|
||||
return ((ShortTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof StringTag) {
|
||||
StringTag stringTag = (StringTag) tag;
|
||||
return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), stringTag.getValue());
|
||||
return ((StringTag) tag).getValue();
|
||||
}
|
||||
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
|
||||
List<Tag<?>> tagList = new ArrayList<>();
|
||||
List<Object> tagList = new ArrayList<>();
|
||||
for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) {
|
||||
tagList.add(translateToBedrockNBT(value));
|
||||
}
|
||||
Class<?> clazz = CompoundTag.class;
|
||||
NbtType<?> type = NbtType.COMPOUND;
|
||||
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) {
|
||||
com.github.steveice10.opennbt.tag.builtin.CompoundTag compoundTag = (com.github.steveice10.opennbt.tag.builtin.CompoundTag) tag;
|
||||
|
||||
return translateNbtToBedrock(compoundTag);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public com.github.steveice10.opennbt.tag.builtin.CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
||||
com.github.steveice10.opennbt.tag.builtin.CompoundTag javaTag = new com.github.steveice10.opennbt.tag.builtin.CompoundTag(tag.getName());
|
||||
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(name);
|
||||
Map<String, com.github.steveice10.opennbt.tag.builtin.Tag> javaValue = javaTag.getValue();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
for (String str : tag.getValue().keySet()) {
|
||||
Tag<?> bedrockTag = tag.get(str);
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag translatedTag = translateToJavaNBT(bedrockTag);
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
for (String str : tag.keySet()) {
|
||||
Object bedrockTag = tag.get(str);
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag translatedTag = translateToJavaNBT(name, bedrockTag);
|
||||
if (translatedTag == null)
|
||||
continue;
|
||||
|
||||
|
@ -315,77 +317,65 @@ public abstract class ItemTranslator {
|
|||
return javaTag;
|
||||
}
|
||||
|
||||
private com.github.steveice10.opennbt.tag.builtin.Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag<?> tag) {
|
||||
if (tag instanceof com.nukkitx.nbt.tag.ByteArrayTag) {
|
||||
com.nukkitx.nbt.tag.ByteArrayTag byteArrayTag = (com.nukkitx.nbt.tag.ByteArrayTag) tag;
|
||||
return new ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
|
||||
private com.github.steveice10.opennbt.tag.builtin.Tag translateToJavaNBT(String name, Object object) {
|
||||
if (object instanceof int[]) {
|
||||
return new IntArrayTag(name, (int[]) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.ByteTag) {
|
||||
com.nukkitx.nbt.tag.ByteTag byteTag = (com.nukkitx.nbt.tag.ByteTag) tag;
|
||||
return new ByteTag(byteTag.getName(), byteTag.getValue());
|
||||
if (object instanceof byte[]) {
|
||||
return new ByteArrayTag(name, (byte[]) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.DoubleTag) {
|
||||
com.nukkitx.nbt.tag.DoubleTag doubleTag = (com.nukkitx.nbt.tag.DoubleTag) tag;
|
||||
return new DoubleTag(doubleTag.getName(), doubleTag.getValue());
|
||||
if (object instanceof Byte) {
|
||||
return new ByteTag(name, (byte) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.FloatTag) {
|
||||
com.nukkitx.nbt.tag.FloatTag floatTag = (com.nukkitx.nbt.tag.FloatTag) tag;
|
||||
return new FloatTag(floatTag.getName(), floatTag.getValue());
|
||||
if (object instanceof Float) {
|
||||
return new FloatTag(name, (float) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.IntArrayTag) {
|
||||
com.nukkitx.nbt.tag.IntArrayTag intArrayTag = (com.nukkitx.nbt.tag.IntArrayTag) tag;
|
||||
return new IntArrayTag(intArrayTag.getName(), intArrayTag.getValue());
|
||||
if (object instanceof Double) {
|
||||
return new DoubleTag(name, (double) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.IntTag) {
|
||||
com.nukkitx.nbt.tag.IntTag intTag = (com.nukkitx.nbt.tag.IntTag) tag;
|
||||
return new IntTag(intTag.getName(), intTag.getValue());
|
||||
if (object instanceof Integer) {
|
||||
return new IntTag(name, (int) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.LongArrayTag) {
|
||||
com.nukkitx.nbt.tag.LongArrayTag longArrayTag = (com.nukkitx.nbt.tag.LongArrayTag) tag;
|
||||
return new LongArrayTag(longArrayTag.getName(), longArrayTag.getValue());
|
||||
if (object instanceof long[]) {
|
||||
return new LongArrayTag(name, (long[]) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.LongTag) {
|
||||
com.nukkitx.nbt.tag.LongTag longTag = (com.nukkitx.nbt.tag.LongTag) tag;
|
||||
return new LongTag(longTag.getName(), longTag.getValue());
|
||||
if (object instanceof Long) {
|
||||
return new LongTag(name, (long) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.ShortTag) {
|
||||
com.nukkitx.nbt.tag.ShortTag shortTag = (com.nukkitx.nbt.tag.ShortTag) tag;
|
||||
return new ShortTag(shortTag.getName(), shortTag.getValue());
|
||||
if (object instanceof Short) {
|
||||
return new ShortTag(name, (short) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.StringTag) {
|
||||
com.nukkitx.nbt.tag.StringTag stringTag = (com.nukkitx.nbt.tag.StringTag) tag;
|
||||
return new StringTag(stringTag.getName(), stringTag.getValue());
|
||||
if (object instanceof String) {
|
||||
return new StringTag(name, (String) object);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.ListTag) {
|
||||
com.nukkitx.nbt.tag.ListTag<?> listTag = (com.nukkitx.nbt.tag.ListTag<?>) tag;
|
||||
|
||||
if (object instanceof List) {
|
||||
List<com.github.steveice10.opennbt.tag.builtin.Tag> tags = new ArrayList<>();
|
||||
|
||||
for (Object value : listTag.getValue()) {
|
||||
if (!(value instanceof com.nukkitx.nbt.tag.Tag))
|
||||
continue;
|
||||
|
||||
com.nukkitx.nbt.tag.Tag<?> tagValue = (com.nukkitx.nbt.tag.Tag<?>) value;
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = translateToJavaNBT(tagValue);
|
||||
for (Object value : (List<?>) object) {
|
||||
com.github.steveice10.opennbt.tag.builtin.Tag javaTag = translateToJavaNBT("", value);
|
||||
if (javaTag != null)
|
||||
tags.add(javaTag);
|
||||
}
|
||||
return new ListTag(listTag.getName(), tags);
|
||||
return new ListTag(name, tags);
|
||||
}
|
||||
|
||||
if (tag instanceof com.nukkitx.nbt.tag.CompoundTag) {
|
||||
com.nukkitx.nbt.tag.CompoundTag compoundTag = (com.nukkitx.nbt.tag.CompoundTag) tag;
|
||||
return translateToJavaNBT(compoundTag);
|
||||
if (object instanceof NbtMap) {
|
||||
NbtMap map = (NbtMap) object;
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
if (entry.getValue().equals(map.get(name))) {
|
||||
return translateToJavaNBT(entry.getKey(), map.getCompound(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -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.StringTag;
|
||||
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 org.geysermc.connector.network.translators.ItemRemapper;
|
||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||
|
@ -63,10 +66,10 @@ public class BannerTranslator extends ItemTranslator {
|
|||
if (blockEntityTag.contains("Patterns")) {
|
||||
ListTag patterns = blockEntityTag.get("Patterns");
|
||||
|
||||
CompoundTagBuilder builder = itemData.getTag().toBuilder();
|
||||
builder.tag(convertBannerPattern(patterns));
|
||||
NbtMapBuilder builder = itemData.getTag().toBuilder();
|
||||
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;
|
||||
|
@ -78,9 +81,9 @@ public class BannerTranslator extends ItemTranslator {
|
|||
|
||||
ItemStack itemStack = super.translateToJava(itemData, itemEntry);
|
||||
|
||||
com.nukkitx.nbt.tag.CompoundTag nbtTag = itemData.getTag();
|
||||
if (nbtTag.contains("Patterns")) {
|
||||
com.nukkitx.nbt.tag.ListTag<?> patterns = nbtTag.get("Patterns");
|
||||
NbtMap nbtTag = itemData.getTag();
|
||||
if (nbtTag.containsKey("Patterns", NbtType.COMPOUND)) {
|
||||
List<NbtMap> patterns = nbtTag.getList("Patterns", NbtType.COMPOUND);
|
||||
|
||||
CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag");
|
||||
blockEntityTag.put(convertBannerPattern(patterns));
|
||||
|
@ -102,16 +105,16 @@ public class BannerTranslator extends ItemTranslator {
|
|||
* @param patterns The patterns to convert
|
||||
* @return The new converted patterns
|
||||
*/
|
||||
public static com.nukkitx.nbt.tag.ListTag convertBannerPattern(ListTag patterns) {
|
||||
List<com.nukkitx.nbt.tag.CompoundTag> tagsList = new ArrayList<>();
|
||||
public static NbtList<NbtMap> convertBannerPattern(ListTag patterns) {
|
||||
List<NbtMap> tagsList = new ArrayList<>();
|
||||
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) {
|
||||
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
|
||||
* @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();
|
||||
|
||||
// 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 CompoundTagBuilder.builder()
|
||||
.intTag("Color", 15 - (int) pattern.get("Color").getValue())
|
||||
.stringTag("Pattern", (String) pattern.get("Pattern").getValue())
|
||||
.stringTag("Pattern", patternName)
|
||||
.buildRootTag();
|
||||
return NbtMap.builder()
|
||||
.putInt("Color", 15 - (int) pattern.get("Color").getValue())
|
||||
.putString("Pattern", (String) pattern.get("Pattern").getValue())
|
||||
.putString("Pattern", patternName)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,10 +144,10 @@ public class BannerTranslator extends ItemTranslator {
|
|||
* @param patterns The patterns to convert
|
||||
* @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<>();
|
||||
for (Object patternTag : patterns.getValue()) {
|
||||
CompoundTag newPatternTag = getJavaBannerPattern((com.nukkitx.nbt.tag.CompoundTag) patternTag);
|
||||
for (Object patternTag : patterns) {
|
||||
CompoundTag newPatternTag = getJavaBannerPattern((NbtMap) patternTag);
|
||||
tagsList.add(newPatternTag);
|
||||
}
|
||||
|
||||
|
@ -157,7 +160,7 @@ public class BannerTranslator extends ItemTranslator {
|
|||
* @param pattern Bedorck edition 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<>();
|
||||
tags.put("Color", new IntTag("Color", 15 - pattern.getInt("Color")));
|
||||
tags.put("Pattern", new StringTag("Pattern", pattern.getString("Pattern")));
|
||||
|
|
|
@ -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.ShapelessRecipeData;
|
||||
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.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData;
|
||||
|
@ -169,6 +169,6 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
|||
private static class GroupedItem {
|
||||
int id;
|
||||
int count;
|
||||
CompoundTag tag;
|
||||
NbtMap tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.packet.ingame.server.world.ServerBlockValuePacket;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEventPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
@ -132,16 +132,16 @@ public class JavaBlockValueTranslator extends PacketTranslator<ServerBlockValueP
|
|||
* @param state
|
||||
* @return Bedrock CompoundTag of piston
|
||||
*/
|
||||
private CompoundTag buildPistonTag(Vector3i position, float progress, float lastProgress, byte state) {
|
||||
CompoundTagBuilder builder = CompoundTag.EMPTY.toBuilder();
|
||||
builder.intTag("x", position.getX())
|
||||
.intTag("y", position.getY())
|
||||
.intTag("z", position.getZ())
|
||||
.floatTag("Progress", progress)
|
||||
.floatTag("LastProgress", lastProgress)
|
||||
.stringTag("id", "PistonArm")
|
||||
.byteTag("NewState", state)
|
||||
.byteTag("State", state);
|
||||
return builder.buildRootTag();
|
||||
private NbtMap buildPistonTag(Vector3i position, float progress, float lastProgress, byte state) {
|
||||
NbtMapBuilder builder = NbtMap.builder()
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.putFloat("Progress", progress)
|
||||
.putFloat("LastProgress", lastProgress)
|
||||
.putString("id", "PistonArm")
|
||||
.putByte("NewState", state)
|
||||
.putByte("State", state);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.packet.ingame.server.world.ServerChunkDataPacket;
|
||||
import com.nukkitx.nbt.NBTOutputStream;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
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.protocol.bedrock.packet.LevelChunkPacket;
|
||||
|
||||
|
@ -82,8 +82,8 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||
|
||||
ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer());
|
||||
NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream);
|
||||
for (CompoundTag blockEntity : chunkData.getBlockEntities()) {
|
||||
nbtStream.write(blockEntity);
|
||||
for (NbtMap blockEntity : chunkData.getBlockEntities()) {
|
||||
nbtStream.writeTag(blockEntity);
|
||||
}
|
||||
|
||||
byteBuf.writeBytes(stream.buffer());
|
||||
|
@ -100,7 +100,7 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||
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)
|
||||
for (Object2IntMap.Entry<CompoundTag> blockEntityEntry : chunkData.getLoadBlockEntitiesLater().object2IntEntrySet()) {
|
||||
for (Object2IntMap.Entry<NbtMap> blockEntityEntry : chunkData.getLoadBlockEntitiesLater().object2IntEntrySet()) {
|
||||
int x = blockEntityEntry.getKey().getInt("x");
|
||||
int y = blockEntityEntry.getKey().getInt("y");
|
||||
int z = blockEntityEntry.getKey().getInt("z");
|
||||
|
|
|
@ -52,7 +52,7 @@ public class JavaExplosionTranslator extends PacketTranslator<ServerExplosionPac
|
|||
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
|
||||
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.setPosition(pos.toFloat());
|
||||
session.sendUpstreamPacket(levelEventPacket);
|
||||
|
|
|
@ -75,7 +75,7 @@ public class JavaPlayEffectTranslator extends PacketTranslator<ServerPlayEffectP
|
|||
effect.setData(BlockTranslator.getBedrockBlockId(breakBlockEffectData.getBlockState()));
|
||||
break;
|
||||
case EXPLOSION:
|
||||
effect.setType(LevelEventType.PARTICLE_LARGE_EXPLOSION);
|
||||
effect.setType(LevelEventType.PARTICLE_EXPLOSION);
|
||||
break;
|
||||
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
|
||||
|
|
|
@ -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.window.VillagerTrade;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerTradeListPacket;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.nbt.NbtType;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
|
@ -75,67 +76,67 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||
updateTradePacket.setUsingEconomyTrade(true);
|
||||
updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||
updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||
CompoundTagBuilder builder = CompoundTagBuilder.builder();
|
||||
List<CompoundTag> tags = new ArrayList<>();
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
List<NbtMap> tags = new ArrayList<>();
|
||||
for (VillagerTrade trade : packet.getTrades()) {
|
||||
CompoundTagBuilder recipe = CompoundTagBuilder.builder();
|
||||
recipe.intTag("maxUses", trade.getMaxUses());
|
||||
recipe.intTag("traderExp", trade.getXp());
|
||||
recipe.floatTag("priceMultiplierA", trade.getPriceMultiplier());
|
||||
recipe.tag(getItemTag(session, trade.getOutput(), "sell", 0));
|
||||
recipe.floatTag("priceMultiplierB", 0.0f);
|
||||
recipe.intTag("buyCountB", trade.getSecondInput() != null ? trade.getSecondInput().getAmount() : 0);
|
||||
recipe.intTag("buyCountA", trade.getFirstInput().getAmount());
|
||||
recipe.intTag("demand", trade.getDemand());
|
||||
recipe.intTag("tier", packet.getVillagerLevel() - 1);
|
||||
recipe.tag(getItemTag(session, trade.getFirstInput(), "buyA", trade.getSpecialPrice()));
|
||||
NbtMapBuilder recipe = NbtMap.builder();
|
||||
recipe.putInt("maxUses", trade.getMaxUses());
|
||||
recipe.putInt("traderExp", trade.getXp());
|
||||
recipe.putFloat("priceMultiplierA", trade.getPriceMultiplier());
|
||||
recipe.put("sell", getItemTag(session, trade.getOutput(), 0));
|
||||
recipe.putFloat("priceMultiplierB", 0.0f);
|
||||
recipe.putInt("buyCountB", trade.getSecondInput() != null ? trade.getSecondInput().getAmount() : 0);
|
||||
recipe.putInt("buyCountA", trade.getFirstInput().getAmount());
|
||||
recipe.putInt("demand", trade.getDemand());
|
||||
recipe.putInt("tier", packet.getVillagerLevel() - 1);
|
||||
recipe.put("buyA", getItemTag(session, trade.getFirstInput(), trade.getSpecialPrice()));
|
||||
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.byteTag("rewardExp", (byte) 1);
|
||||
tags.add(recipe.buildRootTag());
|
||||
recipe.putInt("uses", trade.getNumUses());
|
||||
recipe.putByte("rewardExp", (byte) 1);
|
||||
tags.add(recipe.build());
|
||||
}
|
||||
|
||||
//Hidden trade to fix visual experience bug
|
||||
if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) {
|
||||
tags.add(CompoundTagBuilder.builder()
|
||||
.intTag("maxUses", 0)
|
||||
.intTag("traderExp", 0)
|
||||
.floatTag("priceMultiplierA", 0.0f)
|
||||
.floatTag("priceMultiplierB", 0.0f)
|
||||
.intTag("buyCountB", 0)
|
||||
.intTag("buyCountA", 0)
|
||||
.intTag("demand", 0)
|
||||
.intTag("tier", 5)
|
||||
.intTag("uses", 0)
|
||||
.byteTag("rewardExp", (byte) 0)
|
||||
.buildRootTag());
|
||||
tags.add(NbtMap.builder()
|
||||
.putInt("maxUses", 0)
|
||||
.putInt("traderExp", 0)
|
||||
.putFloat("priceMultiplierA", 0.0f)
|
||||
.putFloat("priceMultiplierB", 0.0f)
|
||||
.putInt("buyCountB", 0)
|
||||
.putInt("buyCountA", 0)
|
||||
.putInt("demand", 0)
|
||||
.putInt("tier", 5)
|
||||
.putInt("uses", 0)
|
||||
.putByte("rewardExp", (byte) 0)
|
||||
.build());
|
||||
}
|
||||
|
||||
builder.listTag("Recipes", CompoundTag.class, tags);
|
||||
List<CompoundTag> expTags = new ArrayList<>();
|
||||
expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag());
|
||||
expTags.add(CompoundTagBuilder.builder().intTag("1", 10).buildRootTag());
|
||||
expTags.add(CompoundTagBuilder.builder().intTag("2", 70).buildRootTag());
|
||||
expTags.add(CompoundTagBuilder.builder().intTag("3", 150).buildRootTag());
|
||||
expTags.add(CompoundTagBuilder.builder().intTag("4", 250).buildRootTag());
|
||||
builder.listTag("TierExpRequirements", CompoundTag.class, expTags);
|
||||
updateTradePacket.setOffers(builder.buildRootTag());
|
||||
builder.putList("Recipes", NbtType.COMPOUND, tags);
|
||||
List<NbtMap> expTags = new ArrayList<>();
|
||||
expTags.add(NbtMap.builder().putInt("0", 0).build());
|
||||
expTags.add(NbtMap.builder().putInt("1", 10).build());
|
||||
expTags.add(NbtMap.builder().putInt("2", 70).build());
|
||||
expTags.add(NbtMap.builder().putInt("3", 150).build());
|
||||
expTags.add(NbtMap.builder().putInt("4", 250).build());
|
||||
builder.putList("TierExpRequirements", NbtType.COMPOUND, expTags);
|
||||
updateTradePacket.setOffers(builder.build());
|
||||
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);
|
||||
ItemEntry itemEntry = ItemRegistry.getItem(stack);
|
||||
CompoundTagBuilder builder = CompoundTagBuilder.builder();
|
||||
builder.byteTag("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1)));
|
||||
builder.shortTag("Damage", itemData.getDamage());
|
||||
builder.shortTag("id", (short) itemEntry.getBedrockId());
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
builder.putByte("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1)));
|
||||
builder.putShort("Damage", itemData.getDamage());
|
||||
builder.putShort("id", (short) itemEntry.getBedrockId());
|
||||
if (itemData.getTag() != null) {
|
||||
CompoundTag tag = itemData.getTag().toBuilder().build("tag");
|
||||
builder.tag(tag);
|
||||
NbtMap tag = itemData.getTag().toBuilder().build();
|
||||
builder.put("tag", tag);
|
||||
}
|
||||
return builder.build(name);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
package org.geysermc.connector.network.translators.world.block;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -41,7 +41,7 @@ public class BlockStateValues {
|
|||
private static final Int2ByteMap BED_COLORS = new Int2ByteOpenHashMap();
|
||||
private static final Int2ObjectMap<DoubleChestValue> DOUBLE_CHEST_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 Int2BooleanMap IS_STICKY_PISTON = 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
|
||||
* @return Map of flower pot blocks.
|
||||
*/
|
||||
public static Map<String, CompoundTag> getFlowerPotBlocks() {
|
||||
public static Map<String, NbtMap> getFlowerPotBlocks() {
|
||||
return FLOWER_POT_BLOCKS;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,12 @@ package org.geysermc.connector.network.translators.world.block;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.common.collect.BiMap;
|
||||
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.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.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
|
@ -45,7 +46,7 @@ import java.io.InputStream;
|
|||
import java.util.*;
|
||||
|
||||
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 BEDROCK_WATER_ID;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public class BlockTranslator {
|
|||
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 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
|
||||
public static final int CARPET = 171;
|
||||
|
@ -79,16 +80,16 @@ public class BlockTranslator {
|
|||
/* Load block palette */
|
||||
InputStream stream = FileUtils.getResource("bedrock/runtime_block_states.dat");
|
||||
|
||||
ListTag<CompoundTag> blocksTag;
|
||||
NbtList<NbtMap> blocksTag;
|
||||
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
|
||||
blocksTag = (ListTag<CompoundTag>) nbtInputStream.readTag();
|
||||
blocksTag = (NbtList<NbtMap>) nbtInputStream.readTag();
|
||||
} catch (Exception 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) {
|
||||
throw new AssertionError("Duplicate block states in Bedrock palette");
|
||||
}
|
||||
|
@ -101,9 +102,9 @@ public class BlockTranslator {
|
|||
} catch (Exception e) {
|
||||
throw new AssertionError("Unable to load Java block mappings", e);
|
||||
}
|
||||
Object2IntMap<CompoundTag> addedStatesMap = new Object2IntOpenHashMap<>();
|
||||
Object2IntMap<NbtMap> addedStatesMap = new Object2IntOpenHashMap<>();
|
||||
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");
|
||||
ref.getTypesAnnotatedWith(BlockEntity.class);
|
||||
|
@ -120,7 +121,7 @@ public class BlockTranslator {
|
|||
javaRuntimeId++;
|
||||
Map.Entry<String, JsonNode> entry = blocksIterator.next();
|
||||
String javaId = entry.getKey();
|
||||
CompoundTag blockTag = buildBedrockState(entry.getValue());
|
||||
NbtMap blockTag = buildBedrockState(entry.getValue());
|
||||
|
||||
// TODO fix this, (no block should have a null hardness)
|
||||
JsonNode hardnessNode = entry.getValue().get("block_hardness");
|
||||
|
@ -181,7 +182,7 @@ public class BlockTranslator {
|
|||
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId);
|
||||
}
|
||||
|
||||
CompoundTag runtimeTag = blockStateMap.remove(blockTag);
|
||||
NbtMap runtimeTag = blockStateMap.remove(blockTag);
|
||||
if (runtimeTag != null) {
|
||||
addedStatesMap.put(blockTag, bedrockRuntimeId);
|
||||
paletteList.add(runtimeTag);
|
||||
|
@ -240,15 +241,15 @@ public class BlockTranslator {
|
|||
|
||||
// Loop around again to find all item frame runtime IDs
|
||||
int frameRuntimeId = 0;
|
||||
for (CompoundTag tag : paletteList) {
|
||||
CompoundTag blockTag = tag.getCompound("block");
|
||||
for (NbtMap tag : paletteList) {
|
||||
NbtMap blockTag = tag.getCompound("block");
|
||||
if (blockTag.getString("name").equals("minecraft:frame")) {
|
||||
ITEM_FRAMES.put(tag, frameRuntimeId);
|
||||
}
|
||||
frameRuntimeId++;
|
||||
}
|
||||
|
||||
BLOCKS = new ListTag<>("", CompoundTag.class, paletteList);
|
||||
BLOCKS = new NbtList<>(NbtType.COMPOUND, paletteList);
|
||||
}
|
||||
|
||||
private BlockTranslator() {
|
||||
|
@ -258,12 +259,12 @@ public class BlockTranslator {
|
|||
// no-op
|
||||
}
|
||||
|
||||
private static CompoundTag buildBedrockState(JsonNode node) {
|
||||
CompoundTagBuilder tagBuilder = CompoundTag.builder();
|
||||
tagBuilder.stringTag("name", node.get("bedrock_identifier").textValue())
|
||||
.intTag("version", BlockTranslator.BLOCK_STATE_VERSION);
|
||||
private static NbtMap buildBedrockState(JsonNode node) {
|
||||
NbtMapBuilder tagBuilder = NbtMap.builder();
|
||||
tagBuilder.putString("name", node.get("bedrock_identifier").textValue())
|
||||
.putInt("version", BlockTranslator.BLOCK_STATE_VERSION);
|
||||
|
||||
CompoundTagBuilder statesBuilder = CompoundTag.builder();
|
||||
NbtMapBuilder statesBuilder = NbtMap.builder();
|
||||
|
||||
// check for states
|
||||
if (node.has("bedrock_states")) {
|
||||
|
@ -274,17 +275,18 @@ public class BlockTranslator {
|
|||
JsonNode stateValue = stateEntry.getValue();
|
||||
switch (stateValue.getNodeType()) {
|
||||
case BOOLEAN:
|
||||
statesBuilder.booleanTag(stateEntry.getKey(), stateValue.booleanValue());
|
||||
statesBuilder.putBoolean(stateEntry.getKey(), stateValue.booleanValue());
|
||||
continue;
|
||||
case STRING:
|
||||
statesBuilder.stringTag(stateEntry.getKey(), stateValue.textValue());
|
||||
statesBuilder.putString(stateEntry.getKey(), stateValue.textValue());
|
||||
continue;
|
||||
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) {
|
||||
|
@ -295,7 +297,7 @@ public class BlockTranslator {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.ListTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtType;
|
||||
import org.geysermc.connector.network.translators.item.translators.BannerTranslator;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Banner", regex = "banner")
|
||||
public class BannerBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
|
||||
|
@ -46,21 +45,21 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
|
||||
int bannerColor = BlockStateValues.getBannerColor(blockState);
|
||||
if (bannerColor != -1) {
|
||||
tags.add(new IntTag("Base", 15 - bannerColor));
|
||||
tags.put("Base", 15 - bannerColor);
|
||||
}
|
||||
|
||||
if (tag.contains("Patterns")) {
|
||||
ListTag patterns = tag.get("Patterns");
|
||||
tags.add(BannerTranslator.convertBannerPattern(patterns));
|
||||
tags.put("", BannerTranslator.convertBannerPattern(patterns));
|
||||
}
|
||||
|
||||
if (tag.contains("CustomName")) {
|
||||
tags.add(new StringTag("CustomName", (String) tag.get("CustomName").getValue()));
|
||||
tags.put("CustomName", tag.get("CustomName").getValue());
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
@ -74,9 +73,9 @@ public class BannerBlockEntityTranslator extends BlockEntityTranslator implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putList("Patterns", NbtType.COMPOUND, new ArrayList<>())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,11 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.ByteTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Bed", regex = "bed")
|
||||
public class BedBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
|
||||
|
@ -43,12 +41,12 @@ public class BedBlockEntityTranslator extends BlockEntityTranslator implements R
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
byte bedcolor = BlockStateValues.getBedColor(blockState);
|
||||
// Just in case...
|
||||
if (bedcolor == -1) bedcolor = 0;
|
||||
tags.add(new ByteTag("color", bedcolor));
|
||||
tags.put("color", bedcolor);
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -58,9 +56,9 @@ public class BedBlockEntityTranslator extends BlockEntityTranslator implements R
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.byteTag("color", (byte) 0);
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putByte("color", (byte) 0)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ public interface BedrockOnlyBlockEntity {
|
|||
* @param blockState Java BlockState of block.
|
||||
* @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)) {
|
||||
return FlowerPotBlockEntityTranslator.getTag(blockState, position);
|
||||
} else if (PistonBlockEntityTranslator.isBlock(blockState)) {
|
||||
|
|
|
@ -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.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
|
@ -37,7 +37,6 @@ import org.geysermc.connector.utils.BlockEntityUtils;
|
|||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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 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 y = Integer.parseInt(String.valueOf(tag.getValue().get("y").getValue()));
|
||||
int z = Integer.parseInt(String.valueOf(tag.getValue().get("z").getValue()));
|
||||
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(id), x, y, z).toBuilder();
|
||||
translateTag(tag, blockState).forEach(tagBuilder::tag);
|
||||
return tagBuilder.buildRootTag();
|
||||
NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(id), x, y, z).toBuilder();
|
||||
Map<String, Object> translatedTags = translateTag(tag, blockState);
|
||||
translatedTags.forEach(tagBuilder::put);
|
||||
return tagBuilder.build();
|
||||
}
|
||||
|
||||
protected CompoundTag getConstantJavaTag(String javaId, int x, int y, int z) {
|
||||
|
@ -112,13 +112,13 @@ public abstract class BlockEntityTranslator {
|
|||
return tag;
|
||||
}
|
||||
|
||||
protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
|
||||
.intTag("x", x)
|
||||
.intTag("y", y)
|
||||
.intTag("z", z)
|
||||
.stringTag("id", bedrockId);
|
||||
return tagBuilder.buildRootTag();
|
||||
protected NbtMap getConstantBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return NbtMap.builder()
|
||||
.putInt("x", x)
|
||||
.putInt("y", y)
|
||||
.putInt("z", z)
|
||||
.putString("id", bedrockId)
|
||||
.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -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.ListTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Campfire", regex = "campfire")
|
||||
public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
ListTag items = tag.get("Items");
|
||||
int i = 1;
|
||||
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++;
|
||||
}
|
||||
return tags;
|
||||
|
@ -59,22 +58,17 @@ public class CampfireBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
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();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z);
|
||||
}
|
||||
|
||||
protected com.nukkitx.nbt.tag.CompoundTag getItem(CompoundTag tag) {
|
||||
protected NbtMap getItem(CompoundTag tag) {
|
||||
ItemEntry entry = ItemRegistry.getItemEntry((String) tag.get("id").getValue());
|
||||
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
|
||||
.shortTag("id", (short) entry.getBedrockId())
|
||||
.byteTag("Count", (byte) tag.get("Count").getValue())
|
||||
.shortTag("Damage", (short) entry.getBedrockData())
|
||||
.tag(CompoundTagBuilder.builder().build("tag"));
|
||||
return tagBuilder.buildRootTag();
|
||||
NbtMapBuilder tagBuilder = NbtMap.builder()
|
||||
.putShort("id", (short) entry.getBedrockId())
|
||||
.putByte("Count", (byte) tag.get("Count").getValue())
|
||||
.putShort("Damage", (short) entry.getBedrockData());
|
||||
tagBuilder.put("tag", NbtMap.builder().build());
|
||||
return tagBuilder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,17 +28,15 @@ package org.geysermc.connector.network.translators.world.block.entity;
|
|||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.ByteTag;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
import org.geysermc.connector.network.translators.world.block.DoubleChestValue;
|
||||
import org.geysermc.connector.utils.BlockEntityUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 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
|
||||
public void updateBlock(GeyserSession session, int blockState, Vector3i position) {
|
||||
CompoundTag javaTag = getConstantJavaTag("chest", position.getX(), position.getY(), position.getZ());
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId("chest"), position.getX(), position.getY(), position.getZ()).toBuilder();
|
||||
translateTag(javaTag, blockState).forEach(tagBuilder::tag);
|
||||
BlockEntityUtils.updateBlockEntity(session, tagBuilder.buildRootTag(), position);
|
||||
NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId("chest"), position.getX(), position.getY(), position.getZ()).toBuilder();
|
||||
translateTag(javaTag, blockState).forEach(tagBuilder::put);
|
||||
BlockEntityUtils.updateBlockEntity(session, tagBuilder.build(), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
if (BlockStateValues.getDoubleChestValues().containsKey(blockState)) {
|
||||
DoubleChestValue chestValues = BlockStateValues.getDoubleChestValues().get(blockState);
|
||||
if (chestValues != null) {
|
||||
|
@ -85,10 +83,10 @@ public class DoubleChestBlockEntityTranslator extends BlockEntityTranslator impl
|
|||
x = x + (chestValues.isLeft ? 1 : -1);
|
||||
}
|
||||
}
|
||||
tags.add(new IntTag("pairx", x));
|
||||
tags.add(new IntTag("pairz", z));
|
||||
tags.put("pairx", x);
|
||||
tags.put("pairz", z);
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,17 +26,17 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
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.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Empty", regex = "")
|
||||
public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
return new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,7 @@ public class EmptyBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.LongTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtList;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "EndGateway", regex = "end_gateway")
|
||||
public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
tags.add(new IntTag("Age", (int) (long) tag.get("Age").getValue()));
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
tags.put("Age", (int) ((long) tag.get("Age").getValue()));
|
||||
// Java sometimes does not provide this tag, but Bedrock crashes if it doesn't exist
|
||||
// Linked coordinates
|
||||
List<IntTag> tagsList = new ArrayList<>();
|
||||
IntList tagsList = new IntArrayList();
|
||||
// Yes, the axis letters are capitalized
|
||||
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "X")));
|
||||
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Y")));
|
||||
tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Z")));
|
||||
com.nukkitx.nbt.tag.ListTag<IntTag> exitPortal =
|
||||
new com.nukkitx.nbt.tag.ListTag<>("ExitPortal", IntTag.class, tagsList);
|
||||
tags.add(exitPortal);
|
||||
tagsList.add(getExitPortalCoordinate(tag, "X"));
|
||||
tagsList.add(getExitPortalCoordinate(tag, "Y"));
|
||||
tagsList.add(getExitPortalCoordinate(tag, "Z"));
|
||||
tags.put("ExitPortal", new NbtList<>(NbtType.INT, tagsList));
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -63,20 +64,16 @@ public class EndGatewayBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
List<IntTag> tagsList = new ArrayList<>();
|
||||
tagsList.add(new IntTag("", 0));
|
||||
tagsList.add(new IntTag("", 0));
|
||||
tagsList.add(new IntTag("", 0));
|
||||
tagBuilder.listTag("ExitPortal", IntTag.class, tagsList);
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putList("ExitPortal", NbtType.INT, Arrays.asList(0, 0, 0))
|
||||
.build();
|
||||
}
|
||||
|
||||
private int getExitPortalCoordinate(CompoundTag tag, String axis) {
|
||||
// Return 0 if it doesn't exist, otherwise give proper value
|
||||
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);
|
||||
return intTag.getValue();
|
||||
} return 0;
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
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.
|
||||
* @return Bedrock tag of flower pot.
|
||||
*/
|
||||
public static CompoundTag getTag(int blockState, Vector3i position) {
|
||||
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
|
||||
.intTag("x", position.getX())
|
||||
.intTag("y", position.getY())
|
||||
.intTag("z", position.getZ())
|
||||
.byteTag("isMovable", (byte) 1)
|
||||
.stringTag("id", "FlowerPot");
|
||||
public static NbtMap getTag(int blockState, Vector3i position) {
|
||||
NbtMapBuilder tagBuilder = NbtMap.builder()
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.putByte("isMovable", (byte) 1)
|
||||
.putString("id", "FlowerPot");
|
||||
// Get the Java name of the plant inside. e.g. minecraft:oak_sapling
|
||||
String name = BlockStateValues.getFlowerPotValues().get(blockState);
|
||||
if (name != null) {
|
||||
// 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.
|
||||
CompoundTag plant = BlockStateValues.getFlowerPotBlocks().get(name);
|
||||
NbtMap plant = BlockStateValues.getFlowerPotBlocks().get(name);
|
||||
if (plant != null) {
|
||||
tagBuilder.tag(plant.toBuilder().build("PlantBlock"));
|
||||
tagBuilder.put("PlantBlock", plant.toBuilder().build());
|
||||
}
|
||||
}
|
||||
return tagBuilder.buildRootTag();
|
||||
return tagBuilder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
|
||||
/**
|
||||
|
@ -51,21 +51,21 @@ public class PistonBlockEntityTranslator {
|
|||
* @param position Bedrock position of piston.
|
||||
* @return Bedrock tag of piston.
|
||||
*/
|
||||
public static CompoundTag getTag(int blockState, Vector3i position) {
|
||||
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
|
||||
.intTag("x", position.getX())
|
||||
.intTag("y", position.getY())
|
||||
.intTag("z", position.getZ())
|
||||
.byteTag("isMovable", (byte) 1)
|
||||
.stringTag("id", "PistonArm");
|
||||
public static NbtMap getTag(int blockState, Vector3i position) {
|
||||
NbtMapBuilder tagBuilder = NbtMap.builder()
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.putByte("isMovable", (byte) 1)
|
||||
.putString("id", "PistonArm");
|
||||
if (BlockStateValues.getPistonValues().containsKey(blockState)) {
|
||||
boolean extended = BlockStateValues.getPistonValues().get(blockState);
|
||||
// 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
|
||||
tagBuilder.byteTag("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0));
|
||||
tagBuilder.putByte("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0));
|
||||
}
|
||||
return tagBuilder.buildRootTag();
|
||||
return tagBuilder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,26 +27,23 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.ByteTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "ShulkerBox", regex = "shulker_box")
|
||||
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
|
||||
byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
|
||||
// Just in case...
|
||||
if (direction == -1) direction = 1;
|
||||
tags.add(new ByteTag("facing", direction));
|
||||
|
||||
tags.put("facing", direction);
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -56,9 +53,9 @@ public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.byteTag("facing", (byte)1);
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putByte("facing", (byte) 1)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Sign", regex = "sign")
|
||||
public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
|
||||
StringBuilder signText = new StringBuilder();
|
||||
for(int i = 0; i < 4; i++) {
|
||||
|
@ -57,7 +55,7 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -72,9 +70,9 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.stringTag("Text", "");
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putString("Text", "")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,15 +25,11 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
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 com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "Skull", regex = "skull")
|
||||
public class SkullBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState {
|
||||
|
@ -44,14 +40,14 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
byte skullVariant = BlockStateValues.getSkullVariant(blockState);
|
||||
float rotation = BlockStateValues.getSkullRotation(blockState) * 22.5f;
|
||||
// Just in case...
|
||||
if (skullVariant == -1) skullVariant = 0;
|
||||
tags.add(new FloatTag("Rotation", rotation));
|
||||
tags.add(new ByteTag("SkullType", skullVariant));
|
||||
tags.put("Rotation", rotation);
|
||||
tags.put("SkullType", skullVariant);
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -61,10 +57,10 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.floatTag("Rotation", 0);
|
||||
tagBuilder.byteTag("SkullType", (byte) 0);
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putFloat("Rotation", 0f)
|
||||
.putByte("SkullType", (byte) 0)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,63 +27,62 @@
|
|||
package org.geysermc.connector.network.translators.world.block.entity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.*;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@BlockEntity(name = "MobSpawner", regex = "mob_spawner")
|
||||
public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {
|
||||
|
||||
@Override
|
||||
public List<Tag<?>> translateTag(CompoundTag tag, int blockState) {
|
||||
List<Tag<?>> tags = new ArrayList<>();
|
||||
public Map<String, Object> translateTag(CompoundTag tag, int blockState) {
|
||||
Map<String, Object> tags = new HashMap<>();
|
||||
|
||||
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) {
|
||||
tags.add(new ShortTag("RequiredPlayerRange", (short) tag.get("RequiredPlayerRange").getValue()));
|
||||
tags.put("RequiredPlayerRange", (short) tag.get("RequiredPlayerRange").getValue());
|
||||
}
|
||||
|
||||
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) {
|
||||
tags.add(new ShortTag("MaxSpawnDelay", (short) tag.get("MaxSpawnDelay").getValue()));
|
||||
tags.put("MaxSpawnDelay", (short) tag.get("MaxSpawnDelay").getValue());
|
||||
}
|
||||
|
||||
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) {
|
||||
tags.add(new ShortTag("SpawnRange", (short) tag.get("SpawnRange").getValue()));
|
||||
tags.put("SpawnRange", (short) tag.get("SpawnRange").getValue());
|
||||
}
|
||||
|
||||
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) {
|
||||
CompoundTag spawnData = tag.get("SpawnData");
|
||||
String entityID = (String) spawnData.get("id").getValue();
|
||||
tags.add(new StringTag("EntityIdentifier", entityID));
|
||||
tags.put("EntityIdentifier", entityID);
|
||||
|
||||
EntityType type = EntityType.getFromIdentifier(entityID);
|
||||
if (type != null) {
|
||||
tags.add(new FloatTag("DisplayEntityWidth", type.getWidth()));
|
||||
tags.add(new FloatTag("DisplayEntityHeight", type.getHeight()));
|
||||
tags.add(new FloatTag("DisplayEntityScale", 1.0f));
|
||||
tags.put("DisplayEntityWidth", type.getWidth());
|
||||
tags.put("DisplayEntityHeight", type.getHeight());
|
||||
tags.put("DisplayEntityScale", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
tags.add(new StringTag("id", "MobSpawner"));
|
||||
tags.add(new ByteTag("isMovable", (byte) 1));
|
||||
tags.put("id", "MobSpawner");
|
||||
tags.put("isMovable", (byte) 1);
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
@ -94,11 +93,10 @@ public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
|
||||
tagBuilder.byteTag("isMovable", (byte) 1)
|
||||
.stringTag("id", "MobSpawner");
|
||||
|
||||
return tagBuilder.buildRootTag();
|
||||
public NbtMap getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
|
||||
return getConstantBedrockTag(bedrockId, x, y, z).toBuilder()
|
||||
.putByte("isMovable", (byte) 1)
|
||||
.putString("id", "MobSpawner")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.geysermc.connector.utils;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
|
||||
|
@ -41,11 +42,11 @@ public class BlockEntityUtils {
|
|||
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()));
|
||||
}
|
||||
|
||||
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();
|
||||
blockEntityPacket.setBlockPosition(position);
|
||||
blockEntityPacket.setData(blockEntity);
|
||||
|
|
|
@ -33,9 +33,9 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.nukkitx.math.vector.Vector2i;
|
||||
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.stream.NBTOutputStream;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
|
@ -64,7 +64,7 @@ public class ChunkUtils {
|
|||
*/
|
||||
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;
|
||||
|
||||
static {
|
||||
|
@ -72,7 +72,7 @@ public class ChunkUtils {
|
|||
outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size
|
||||
|
||||
try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
|
||||
stream.write(EMPTY_TAG);
|
||||
stream.writeTag(EMPTY_TAG);
|
||||
}
|
||||
|
||||
EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
|
||||
|
@ -91,7 +91,7 @@ public class ChunkUtils {
|
|||
Object2IntMap<Position> blockEntityPositions = new Object2IntOpenHashMap<>();
|
||||
|
||||
// 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++) {
|
||||
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;
|
||||
while (i < blockEntities.length) {
|
||||
CompoundTag tag = blockEntities[i];
|
||||
|
@ -162,7 +162,7 @@ public class ChunkUtils {
|
|||
bedrockBlockEntities[i] = blockEntityTranslator.getBlockEntityTag(tagName, tag, blockState);
|
||||
i++;
|
||||
}
|
||||
for (com.nukkitx.nbt.tag.CompoundTag tag : bedrockOnlyBlockEntities) {
|
||||
for (NbtMap tag : bedrockOnlyBlockEntities) {
|
||||
bedrockBlockEntities[i] = tag;
|
||||
i++;
|
||||
}
|
||||
|
@ -270,8 +270,8 @@ public class ChunkUtils {
|
|||
public ChunkSection[] sections;
|
||||
|
||||
@Getter
|
||||
private com.nukkitx.nbt.tag.CompoundTag[] blockEntities = new com.nukkitx.nbt.tag.CompoundTag[0];
|
||||
private NbtMap[] blockEntities = new NbtMap[0];
|
||||
@Getter
|
||||
private Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> loadBlockEntitiesLater = new Object2IntOpenHashMap<>();
|
||||
private Object2IntMap<NbtMap> loadBlockEntitiesLater = new Object2IntOpenHashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@ package org.geysermc.connector.utils;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
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.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
|
||||
|
@ -136,13 +137,13 @@ public class InventoryUtils {
|
|||
* part of the inventory is unusable.
|
||||
*/
|
||||
public static ItemData createUnusableSpaceBlock(String description) {
|
||||
CompoundTagBuilder root = CompoundTagBuilder.builder();
|
||||
CompoundTagBuilder display = CompoundTagBuilder.builder();
|
||||
NbtMapBuilder root = NbtMap.builder();
|
||||
NbtMapBuilder display = NbtMap.builder();
|
||||
|
||||
display.stringTag("Name", ChatColor.RESET + "Unusable inventory space");
|
||||
display.listTag("Lore", StringTag.class, Collections.singletonList(new StringTag("", ChatColor.RESET + ChatColor.DARK_PURPLE + description)));
|
||||
display.putString("Name", ChatColor.RESET + "Unusable inventory space");
|
||||
display.putList("Lore", NbtType.STRING, Collections.singletonList(ChatColor.RESET + ChatColor.DARK_PURPLE + description));
|
||||
|
||||
root.tag(display.build("display"));
|
||||
return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.buildRootTag());
|
||||
root.put("display", display.build());
|
||||
return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,6 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue