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

Custom packets broken #248

Open
NovaProtocol opened this issue May 12, 2022 · 0 comments
Open

Custom packets broken #248

NovaProtocol opened this issue May 12, 2022 · 0 comments

Comments

@NovaProtocol
Copy link

NovaProtocol commented May 12, 2022

I think custom packets are broken or something

This is the original

class BlockChangePacket(Packet):
    @staticmethod
    def get_id(context):
        return 0x0C if context.protocol_later_eq(755) else \
               0x0B if context.protocol_later_eq(721) else \
               0x0C if context.protocol_later_eq(550) else \
               0x0B if context.protocol_later_eq(332) else \
               0x0C if context.protocol_later_eq(318) else \
               0x0B if context.protocol_later_eq(67) else \
               0x24 if context.protocol_later_eq(62) else \
               0x23

    packet_name = 'block change'
    definition = [
        {'location': Position},
        {'block_state_id': VarInt}]
    block_state_id = 0

    # For protocols before 347: an accessor for (block_state_id >> 4).
    @property
    def blockId(self):
        return self.block_state_id >> 4

    @blockId.setter
    def blockId(self, block_id):
        self.block_state_id = (self.block_state_id & 0xF) | (block_id << 4)

    # For protocols before 347: an accessor for (block_state_id & 0xF).
    @property
    def blockMeta(self):
        return self.block_state_id & 0xF

    @blockMeta.setter
    def blockMeta(self, meta):
        self.block_state_id = (self.block_state_id & ~0xF) | (meta & 0xF)

    # This alias is retained for backward compatibility.
    blockStateId = attribute_alias('block_state_id')

And this is literally the same code but moved to an external file

    class BlockChangePacket(Packet):
        @staticmethod
        def get_id(context):
            return 0x0C if context.protocol_later_eq(755) else \
                0x0B if context.protocol_later_eq(721) else \
                0x0C if context.protocol_later_eq(550) else \
                0x0B if context.protocol_later_eq(332) else \
                0x0C if context.protocol_later_eq(318) else \
                0x0B if context.protocol_later_eq(67) else \
                0x24 if context.protocol_later_eq(62) else \
                0x23

        packet_name = 'block change'
        definition = [
            {'location': Position},
            {'block_state_id': VarInt}]
        block_state_id = 0

        # For protocols before 347: an accessor for (block_state_id >> 4).
        @property
        def blockId(self):
            return self.block_state_id >> 4

        @blockId.setter
        def blockId(self, block_id):
            self.block_state_id = (self.block_state_id & 0xF) | (block_id << 4)

        # For protocols before 347: an accessor for (block_state_id & 0xF).
        @property
        def blockMeta(self):
            return self.block_state_id & 0xF

        @blockMeta.setter
        def blockMeta(self, meta):
            self.block_state_id = (self.block_state_id & ~0xF) | (meta & 0xF)

    # This alias is retained for backward compatibility.
    blockStateId = attribute_alias('block_state_id')

In theory, the following code should print both but for some reason, only the 1 prints. I tried tinkering but i can't make it work. Pls help

        def block_listener(spawn_packet):
            print(f"1-{spawn_packet}")

        self.connection.register_packet_listener(block_listener, clientbound.play.BlockChangePacket)

        def block_listener2(spawn_packet):
            print(f"2-{spawn_packet}")

        self.connection.register_packet_listener(block_listener2,minecraft_packets.Clientbound.BlockChangePacket)

Testing this via 1.12.2
Vanilla

Yes, i tried removing the first one and tested other packets. Same

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