Update ChunkDataPacket to 1.16.2

This commit is contained in:
Tanner Collin 2020-09-06 00:50:47 -06:00
parent 303612fcf1
commit 9966e88e9c

View File

@ -6,7 +6,7 @@ from minecraft.networking.types import (
multi_attribute_alias, Vector, UnsignedLong multi_attribute_alias, Vector, UnsignedLong
) )
from ....types import nbt from ....types.nbt import Nbt
class ChunkDataPacket(Packet): class ChunkDataPacket(Packet):
id = 0x20 id = 0x20
@ -14,7 +14,6 @@ class ChunkDataPacket(Packet):
fields = 'x', 'bit_mask_y', 'z', 'full_chunk' fields = 'x', 'bit_mask_y', 'z', 'full_chunk'
def read(self, file_object): def read(self, file_object):
print('reading chunk')
self.x = Integer.read(file_object) self.x = Integer.read(file_object)
self.z = Integer.read(file_object) self.z = Integer.read(file_object)
self.full_chunk = Boolean.read(file_object) self.full_chunk = Boolean.read(file_object)
@ -24,13 +23,13 @@ class ChunkDataPacket(Packet):
if self.full_chunk: if self.full_chunk:
biomes_length = VarInt.read(file_object) biomes_length = VarInt.read(file_object)
for i in range(biomes_length): for i in range(biomes_length):
self.biomes.append(Integer.read(file_object)) self.biomes.append(VarInt.read(file_object))
size = VarInt.read(file_object) size = VarInt.read(file_object)
self.data = file_object.read(size) self.data = file_object.read(size)
size_entities = VarInt.read(file_object) size_entities = VarInt.read(file_object)
self.entities = [] self.entities = []
for i in range(size_entities): #for i in range(size_entities):
self.entities.append(Nbt.read(file_object)) # self.entities.append(Nbt.read(file_object))
self.decode_chunk_data() self.decode_chunk_data()
@ -101,13 +100,11 @@ class Chunk:
self.blocks = [] self.blocks = []
mask = (1 << self.bpb)-1 mask = (1 << self.bpb)-1
bits_used = int(64 / self.bpb) * self.bpb
for i in range(4096): for i in range(4096):
l1 = int((i*self.bpb)/64) l1 = int((i*self.bpb)/bits_used)
offset = (i*self.bpb)%64 offset = (i*self.bpb)%bits_used
l2 = int(((i+1)*self.bpb-1)/64)
n = longs[l1] >> offset n = longs[l1] >> offset
if l2>l1:
n |= longs[l2] << (64-offset)
n &= mask n &= mask
if self.palette: if self.palette:
n = self.palette[n] n = self.palette[n]