use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project Geyser by GeyserMC.
the class CommandBlockMinecartEntity method interact.
@Override
public InteractionResult interact(Hand hand) {
if (session.canUseCommandBlocks()) {
// Client-side GUI required
ContainerOpenPacket openPacket = new ContainerOpenPacket();
openPacket.setBlockPosition(Vector3i.ZERO);
openPacket.setId((byte) 1);
openPacket.setType(ContainerType.COMMAND_BLOCK);
openPacket.setUniqueEntityId(geyserId);
session.sendUpstreamPacket(openPacket);
return InteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
}
}
use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project Geyser by GeyserMC.
the class DoubleChestInventoryTranslator method openInventory.
@Override
public void openInventory(GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId());
containerOpenPacket.setType(ContainerType.CONTAINER);
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 BedrockInteractTranslator method translate.
@Override
public void translate(GeyserSession session, InteractPacket packet) {
Entity entity;
if (packet.getRuntimeEntityId() == session.getPlayerEntity().getGeyserId()) {
// Player is not in entity cache
entity = session.getPlayerEntity();
} else {
entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
}
if (entity == null)
return;
switch(packet.getAction()) {
case INTERACT:
if (session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
break;
}
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(interactPacket);
break;
case DAMAGE:
ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
session.sendDownstreamPacket(attackPacket);
break;
case LEAVE_VEHICLE:
ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING);
session.sendDownstreamPacket(sneakPacket);
break;
case MOUSEOVER:
// Handle the buttons for mobile - "Mount", etc; and the suggestions for console - "ZL: Mount", etc
if (packet.getRuntimeEntityId() != 0) {
Entity interactEntity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
session.setMouseoverEntity(interactEntity);
if (interactEntity == null) {
return;
}
interactEntity.updateInteractiveTag();
} else {
if (session.getMouseoverEntity() != null) {
// No interactive tag should be sent
session.setMouseoverEntity(null);
session.getPlayerEntity().getDirtyMetadata().put(EntityData.INTERACTIVE_TAG, "");
session.getPlayerEntity().updateBedrockMetadata();
}
}
break;
case OPEN_INVENTORY:
if (session.getOpenInventory() == null) {
Entity ridingEntity = session.getPlayerEntity().getVehicle();
if (ridingEntity instanceof AbstractHorseEntity) {
if (ridingEntity.getFlag(EntityFlag.TAMED)) {
// We should request to open the horse inventory instead
ServerboundPlayerCommandPacket openHorseWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY);
session.sendDownstreamPacket(openHorseWindowPacket);
}
} else {
session.setOpenInventory(session.getPlayerInventory());
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) 0);
containerOpenPacket.setType(ContainerType.INVENTORY);
containerOpenPacket.setUniqueEntityId(-1);
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
session.sendUpstreamPacket(containerOpenPacket);
}
}
break;
}
}
use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project JukeboxMC by LucGamesYT.
the class ContainerInventory method addViewer.
public void addViewer(Player player, Vector position, byte windowId) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setUniqueEntityId(this.holderId);
containerOpenPacket.setId(windowId);
containerOpenPacket.setType(this.getWindowTypeId());
containerOpenPacket.setBlockPosition(position.toVector3i());
player.sendPacket(containerOpenPacket);
super.addViewer(player);
this.onOpen(player);
}
use of com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket in project Geyser by GeyserMC.
the class Generic3X3InventoryTranslator method openInventory.
@Override
public void openInventory(GeyserSession session, Inventory inventory) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) inventory.getId());
// Required for opening the real block - otherwise, if the container type is incorrect, it refuses to open
containerOpenPacket.setType(((Generic3X3Container) inventory).isDropper() ? com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DROPPER : com.nukkitx.protocol.bedrock.data.inventory.ContainerType.DISPENSER);
containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
session.sendUpstreamPacket(containerOpenPacket);
}
Aggregations