use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project Geyser by GeyserMC.
the class BlockInventoryHolder method openInventory.
@Override
public void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId());
containerOpenPacket.setType(containerType);
containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
session.sendUpstreamPacket(containerOpenPacket);
}
use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project Geyser by GeyserMC.
the class JavaBlockEntityDataTranslator method translate.
@Override
public void translate(GeyserSession session, ClientboundBlockEntityDataPacket packet) {
final BlockEntityType type = packet.getType();
if (type == null) {
return;
}
BlockEntityTranslator translator = BlockEntityUtils.getBlockEntityTranslator(type);
// The Java block state is used in BlockEntityTranslator.translateTag() to make up for some inconsistencies
// between Java block states and Bedrock block entity data
int blockState;
if (translator instanceof RequiresBlockState) {
blockState = session.getGeyser().getWorldManager().getBlockAt(session, packet.getPosition());
} else {
blockState = BlockStateValues.JAVA_AIR_ID;
}
Position position = packet.getPosition();
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(type, position.getX(), position.getY(), position.getZ(), packet.getNbt(), blockState), packet.getPosition());
// Check for custom skulls.
if (session.getPreferencesCache().showCustomSkulls() && packet.getNbt() != null && packet.getNbt().contains("SkullOwner")) {
SkullBlockEntityTranslator.spawnPlayer(session, packet.getNbt(), position.getX(), position.getY(), position.getZ(), blockState);
}
// TODO 1.18 re-test
if (type == BlockEntityType.COMMAND_BLOCK && session.getOpPermissionLevel() >= 2 && session.getGameMode() == GameMode.CREATIVE && packet.getNbt() != null && packet.getNbt().size() > 5) {
ContainerOpenPacket openPacket = new ContainerOpenPacket();
openPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
openPacket.setId((byte) 1);
openPacket.setType(ContainerType.COMMAND_BLOCK);
openPacket.setUniqueEntityId(-1);
session.sendUpstreamPacket(openPacket);
}
}
Aggregations