Search in sources :

Example 6 with BlockEntityDataPacket

use of com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket in project JukeboxMC by LucGamesYT.

the class BlockEntity method update.

public void update(Player player) {
    BlockEntityDataPacket blockEntityDataPacket = new BlockEntityDataPacket();
    blockEntityDataPacket.setBlockPosition(this.block.getLocation().toVector3i());
    blockEntityDataPacket.setData(this.toCompound().build());
    player.sendPacket(blockEntityDataPacket);
}
Also used : BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)

Example 7 with BlockEntityDataPacket

use of com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket in project Geyser by GeyserMC.

the class BeaconInventoryTranslator method updateProperty.

@Override
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
    // FIXME?: Beacon graphics look weird after inputting an item. This might be a Bedrock bug, since it resets to nothing
    // on BDS
    BeaconContainer beaconContainer = (BeaconContainer) inventory;
    switch(key) {
        case 0:
            // Power - beacon doesn't use this, and uses the block position instead
            break;
        case 1:
            beaconContainer.setPrimaryId(value == -1 ? 0 : value);
            break;
        case 2:
            beaconContainer.setSecondaryId(value == -1 ? 0 : value);
            break;
    }
    // Send a block entity data packet update to the fake beacon inventory
    Vector3i position = inventory.getHolderPosition();
    NbtMapBuilder builder = NbtMap.builder().putInt("x", position.getX()).putInt("y", position.getY()).putInt("z", position.getZ()).putString("CustomName", inventory.getTitle()).putString("id", "Beacon").putInt("primary", beaconContainer.getPrimaryId()).putInt("secondary", beaconContainer.getSecondaryId());
    BlockEntityDataPacket packet = new BlockEntityDataPacket();
    packet.setBlockPosition(position);
    packet.setData(builder.build());
    session.sendUpstreamPacket(packet);
}
Also used : BeaconContainer(org.geysermc.geyser.inventory.BeaconContainer) Vector3i(com.nukkitx.math.vector.Vector3i) BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 8 with BlockEntityDataPacket

use of com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket in project Geyser by GeyserMC.

the class DoubleChestInventoryTranslator method prepareInventory.

@Override
public void prepareInventory(GeyserSession session, Inventory inventory) {
    // See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
    if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
        int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
        String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
        if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest")) && !javaBlockString[1].contains("type=single")) {
            inventory.setHolderPosition(session.getLastInteractionBlockPosition());
            ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
            NbtMapBuilder tag = NbtMap.builder().putString("id", "Chest").putInt("x", session.getLastInteractionBlockPosition().getX()).putInt("y", session.getLastInteractionBlockPosition().getY()).putInt("z", session.getLastInteractionBlockPosition().getZ()).putString("CustomName", inventory.getTitle()).putString("id", "Chest");
            DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId);
            DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue, session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ());
            BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
            dataPacket.setData(tag.build());
            dataPacket.setBlockPosition(session.getLastInteractionBlockPosition());
            session.sendUpstreamPacket(dataPacket);
            return;
        }
    }
    Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP);
    Vector3i pairPosition = position.add(Vector3i.UNIT_X);
    int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState);
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(position);
    blockPacket.setRuntimeId(bedrockBlockId);
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
    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);
    session.sendUpstreamPacket(dataPacket);
    blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(pairPosition);
    blockPacket.setRuntimeId(bedrockBlockId);
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
    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);
    session.sendUpstreamPacket(dataPacket);
    inventory.setHolderPosition(position);
}
Also used : Container(org.geysermc.geyser.inventory.Container) Vector3i(com.nukkitx.math.vector.Vector3i) NbtMap(com.nukkitx.nbt.NbtMap) DoubleChestValue(org.geysermc.geyser.level.block.DoubleChestValue) BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 9 with BlockEntityDataPacket

use of com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket in project Geyser by GeyserMC.

the class BlockInventoryHolder method setCustomName.

protected void setCustomName(GeyserSession session, Vector3i position, Inventory inventory, int javaBlockState) {
    NbtMap tag = NbtMap.builder().putInt("x", position.getX()).putInt("y", position.getY()).putInt("z", position.getZ()).putString("CustomName", inventory.getTitle()).build();
    BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
    dataPacket.setData(tag);
    dataPacket.setBlockPosition(position);
    session.sendUpstreamPacket(dataPacket);
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) BlockEntityDataPacket(com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)

Aggregations

BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)9 Vector3i (com.nukkitx.math.vector.Vector3i)2 NbtMap (com.nukkitx.nbt.NbtMap)2 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)2 UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)2 ArrayList (java.util.ArrayList)1 BeaconContainer (org.geysermc.geyser.inventory.BeaconContainer)1 Container (org.geysermc.geyser.inventory.Container)1 DoubleChestValue (org.geysermc.geyser.level.block.DoubleChestValue)1 BlockSignChangeEvent (org.jukeboxmc.event.block.BlockSignChangeEvent)1 Vector (org.jukeboxmc.math.Vector)1 World (org.jukeboxmc.world.World)1