pyCraft
pyCraft copied to clipboard
Custom packets broken
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