Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing ClientboundSetEntityDataPacket #169

Open
mikeshadow1452 opened this issue Aug 26, 2024 · 0 comments
Open

Parsing ClientboundSetEntityDataPacket #169

mikeshadow1452 opened this issue Aug 26, 2024 · 0 comments

Comments

@mikeshadow1452
Copy link

I'm trying to get the Vec from ClientboundSetEntityDataPacket.packed_items that the server sends me when I update an item and rotate that item in the frame (data in this packet). I am trying to use TryFrom for this:

async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
    match event {
        Event::Packet(packet) => match *packet {
            ClientboundGamePacket::SetEntityData( ref p)=>{
                match Vec::<EntityDataValue>::try_from(p.clone().packed_items) {
                    Ok(value) => {println!("{:#?}", value)}
                    Err(e) => {println!("{}", e)}
                }
            }
            _ => {}
        }
        _ => {}
    }
    Ok(())
}

But I get the error Index 8 is too big.
I have studied the TryFrom code and came to the conclusion that this check is not needed here or is written incorrectly:

if item.index as usize > len {
    return Err(format!("Index {} is too big", item.index));
}

In the protocol it says

Updates one or more metadata properties for an existing entity. Any properties not included in the Metadata field are left unchanged

From this we can conclude that not all fields are always sent and their number does not necessarily equal the maximum index in the packet.
Can you fix this or explain how to properly parse such packets?

The packet I received
ClientboundSetEntityDataPacket {
    id: 6,
    packed_items: EntityMetadataItems(
        [
            EntityDataItem {
                index: 8,
                value: ItemStack(
                    Present(
                        ItemSlotData {
                            count: 1,
                            kind: FilledMap,
                            components: {
                                MapId,
                                CustomData,
                            },
                        },
                    ),
                ),
            },
            EntityDataItem {
                index: 9,
                value: Int(
                    2,
                ),
            },
        ],
    ),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant