CloudburstMC / Protocol

A protocol library for Minecraft Bedrock Edition
https://git.io/ProtocolLib
Apache License 2.0
312 stars 94 forks source link

AvailableCommands Flags #42

Closed bundabrg closed 4 years ago

bundabrg commented 4 years ago

I've noticed that the flags are set and retrieved different in the serializer/deserializer.

When deserializing the flags are set using:

            for (int i = 0; i < 8; i++) {
                if (((flagsByte >>> i) & 0xf) != 0) {
                    flags.add(CommandData.Flag.values()[i]);
                }
            }

When serializing:

                for (CommandData.Flag flag : commandData.getFlags()) {
                    flags |= 1 << flag.ordinal();
                }

Serializing will set the bits of each flag to 1. So if its value is 3 then the 3rd bit is set.

Deserializing will set a flag and every flag below its position to 1 (due to the & 0xf and the !=0).

SupremeMortal commented 4 years ago

Fixed in 2.6.0-SNAPSHOT