use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class LecternInventoryTranslator method getBaseLecternTag.
public static NbtMapBuilder getBaseLecternTag(int x, int y, int z, int totalPages) {
NbtMapBuilder builder = NbtMap.builder().putInt("x", x).putInt("y", y).putInt("z", z).putString("id", "Lectern");
if (totalPages != 0) {
builder.putByte("hasBook", (byte) 1);
builder.putInt("totalPages", totalPages);
} else {
// Not usually needed, but helps with kicking out Bedrock players from reading the UI
builder.putByte("hasBook", (byte) 0);
}
return builder;
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class JavaHorseScreenOpenTranslator method translate.
@Override
public void translate(GeyserSession session, ClientboundHorseScreenOpenPacket packet) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (entity == null) {
return;
}
UpdateEquipPacket updateEquipPacket = new UpdateEquipPacket();
updateEquipPacket.setWindowId((short) packet.getContainerId());
updateEquipPacket.setWindowType((short) ContainerType.HORSE.getId());
updateEquipPacket.setUniqueEntityId(entity.getGeyserId());
NbtMapBuilder builder = NbtMap.builder();
List<NbtMap> slots = new ArrayList<>();
InventoryTranslator inventoryTranslator;
if (entity instanceof LlamaEntity) {
inventoryTranslator = new LlamaInventoryTranslator(packet.getNumberOfSlots());
slots.add(CARPET_SLOT);
} else if (entity instanceof ChestedHorseEntity) {
inventoryTranslator = new DonkeyInventoryTranslator(packet.getNumberOfSlots());
slots.add(SADDLE_SLOT);
} else {
inventoryTranslator = new HorseInventoryTranslator(packet.getNumberOfSlots());
slots.add(SADDLE_SLOT);
slots.add(ARMOR_SLOT);
}
// Build the NbtMap that sets the icons for Bedrock (e.g. sets the saddle outline on the saddle slot)
builder.putList("slots", NbtType.COMPOUND, slots);
updateEquipPacket.setTag(builder.build());
session.sendUpstreamPacket(updateEquipPacket);
session.setInventoryTranslator(inventoryTranslator);
InventoryUtils.openInventory(session, new Container(entity.getNametag(), packet.getContainerId(), packet.getNumberOfSlots(), null, session.getPlayerInventory()));
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class BedrockPositionTrackingDBClientRequestTranslator method translate.
@Override
public void translate(GeyserSession session, PositionTrackingDBClientRequestPacket packet) {
PositionTrackingDBServerBroadcastPacket broadcastPacket = new PositionTrackingDBServerBroadcastPacket();
broadcastPacket.setTrackingId(packet.getTrackingId());
// Fetch the stored lodestone
LodestoneCache.LodestonePos pos = session.getLodestoneCache().getPos(packet.getTrackingId());
// If we don't have data for that ID tell the client its not found
if (pos == null) {
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.NOT_FOUND);
session.sendUpstreamPacket(broadcastPacket);
return;
}
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE);
// Build the NBT data for the update
NbtMapBuilder builder = NbtMap.builder();
builder.putInt("dim", DimensionUtils.javaToBedrock(pos.dimension()));
builder.putString("id", "0x" + String.format("%08X", packet.getTrackingId()));
// Not sure what this is for
builder.putByte("version", (byte) 1);
// Not sure what this is for
builder.putByte("status", (byte) 0);
// Build the position for the update
builder.putList("pos", NbtType.INT, pos.x(), pos.y(), pos.z());
broadcastPacket.setTag(builder.build());
session.sendUpstreamPacket(broadcastPacket);
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntity method toCompound.
public NbtMapBuilder toCompound() {
NbtMapBuilder compound = NbtMap.builder();
Vector position = this.block.getLocation();
compound.putString("id", BlockEntityType.getId(this.getClass()));
compound.putInt("x", position.getBlockX());
compound.putInt("y", position.getBlockY());
compound.putInt("z", position.getBlockZ());
compound.putBoolean("isMovable", this.isMoveable);
return compound;
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntityBlastFurnace method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder builder = super.toCompound();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < this.blastFurnaceInventory.getSize(); slot++) {
NbtMapBuilder itemCompound = NbtMap.builder();
Item item = this.blastFurnaceInventory.getItem(slot);
itemCompound.putByte("Slot", (byte) slot);
this.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
return builder;
}
Aggregations