use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntityBed method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder compound = super.toCompound();
compound.putByte("color", this.color);
return compound;
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntityChest method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder builder = super.toCompound();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < this.chestInventory.getSize(); slot++) {
NbtMapBuilder itemCompound = NbtMap.builder();
Item item = this.chestInventory.getItem(slot);
itemCompound.putByte("Slot", (byte) slot);
this.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
builder.putInt("pairx", this.pairX);
builder.putInt("pairz", this.pairZ);
builder.putBoolean("Findable", this.findable);
return builder;
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class CampfireBlockEntityTranslator method getItem.
protected NbtMap getItem(CompoundTag tag) {
// TODO: Version independent mappings
ItemMapping mapping = Registries.ITEMS.forVersion(MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()).getMapping((String) tag.get("id").getValue());
NbtMapBuilder tagBuilder = NbtMap.builder().putString("Name", mapping.getBedrockIdentifier()).putByte("Count", (byte) tag.get("Count").getValue()).putShort("Damage", (short) mapping.getBedrockData());
tagBuilder.put("tag", NbtMap.builder().build());
return tagBuilder.build();
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class DoubleChestBlockEntityTranslator method updateBlock.
@Override
public void updateBlock(GeyserSession session, int blockState, Vector3i position) {
NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(BlockEntityType.CHEST), position.getX(), position.getY(), position.getZ());
translateTag(tagBuilder, null, blockState);
BlockEntityUtils.updateBlockEntity(session, tagBuilder.build(), position);
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class LecternInventoryTranslator method updateBook.
/**
* Translate the data of the book in the lectern into a block entity tag.
*/
private void updateBook(GeyserSession session, Inventory inventory, GeyserItemStack book) {
LecternContainer lecternContainer = (LecternContainer) inventory;
if (session.isDroppingLecternBook()) {
// We have to enter the inventory GUI to eject the book
ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getId(), 3);
session.sendDownstreamPacket(packet);
session.setDroppingLecternBook(false);
InventoryUtils.closeInventory(session, inventory.getId(), false);
} else if (lecternContainer.getBlockEntityTag() == null) {
CompoundTag tag = book.getNbt();
// Position has to be the last interacted position... right?
Vector3i position = session.getLastInteractionBlockPosition();
// If shouldExpectLecternHandled returns true, this is already handled for us
// shouldRefresh means that we should boot out the client on our side because their lectern GUI isn't updated yet
boolean shouldRefresh = !session.getGeyser().getWorldManager().shouldExpectLecternHandled() && !session.getLecternCache().contains(position);
NbtMap blockEntityTag;
if (tag != null) {
int pagesSize = ((ListTag) tag.get("pages")).size();
ItemData itemData = book.getItemData(session);
NbtMapBuilder lecternTag = getBaseLecternTag(position.getX(), position.getY(), position.getZ(), pagesSize);
lecternTag.putCompound("book", NbtMap.builder().putByte("Count", (byte) itemData.getCount()).putShort("Damage", (short) 0).putString("Name", "minecraft:written_book").putCompound("tag", itemData.getTag()).build());
lecternTag.putInt("page", lecternContainer.getCurrentBedrockPage());
blockEntityTag = lecternTag.build();
} else {
// There is *a* book here, but... no NBT.
NbtMapBuilder lecternTag = getBaseLecternTag(position.getX(), position.getY(), position.getZ(), 1);
NbtMapBuilder bookTag = NbtMap.builder().putByte("Count", (byte) 1).putShort("Damage", (short) 0).putString("Name", "minecraft:writable_book").putCompound("tag", NbtMap.builder().putList("pages", NbtType.COMPOUND, Collections.singletonList(NbtMap.builder().putString("photoname", "").putString("text", "").build())).build());
blockEntityTag = lecternTag.putCompound("book", bookTag.build()).build();
}
// Even with serverside access to lecterns, we don't easily know which lectern this is, so we need to rebuild
// the block entity tag
lecternContainer.setBlockEntityTag(blockEntityTag);
lecternContainer.setPosition(position);
if (shouldRefresh) {
// Update the lectern because it's not updated client-side
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, position);
session.getLecternCache().add(position);
// Close the window - we will reopen it once the client has this data synced
ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getId());
session.sendDownstreamPacket(closeWindowPacket);
InventoryUtils.closeInventory(session, inventory.getId(), false);
}
}
}
Aggregations