Compare commits
No commits in common. "9966e88e9ca9547f822956081200201875ab040e" and "71918953c2a0a2bcf97f5572a5102d0a4550350d" have entirely different histories.
9966e88e9c
...
71918953c2
|
@ -6,14 +6,18 @@ from minecraft.networking.types import (
|
||||||
multi_attribute_alias, Vector, UnsignedLong
|
multi_attribute_alias, Vector, UnsignedLong
|
||||||
)
|
)
|
||||||
|
|
||||||
from ....types.nbt import Nbt
|
from ....types import nbt
|
||||||
|
|
||||||
class ChunkDataPacket(Packet):
|
class ChunkDataPacket(Packet):
|
||||||
id = 0x20
|
@staticmethod
|
||||||
|
def get_id(context):
|
||||||
|
return 0x20 # FIXME
|
||||||
|
|
||||||
packet_name = 'chunk data'
|
packet_name = 'chunk data'
|
||||||
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)
|
||||||
|
@ -23,13 +27,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(VarInt.read(file_object))
|
self.biomes.append(Integer.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()
|
||||||
|
|
||||||
|
@ -100,11 +104,13 @@ 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)/bits_used)
|
l1 = int((i*self.bpb)/64)
|
||||||
offset = (i*self.bpb)%bits_used
|
offset = (i*self.bpb)%64
|
||||||
|
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]
|
||||||
|
|
27
start.py
27
start.py
|
@ -5,26 +5,13 @@ import sys
|
||||||
import re
|
import re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from custom.managers import DataManager, ChunksManager
|
|
||||||
from custom.networking.packets.clientbound.play import chunk_data
|
|
||||||
|
|
||||||
import minecraft.networking.packets
|
|
||||||
|
|
||||||
def get_packets(old_get_packets):
|
|
||||||
def wrapper(func, context):
|
|
||||||
print('Monkey-patched.')
|
|
||||||
packets = func(context)
|
|
||||||
packets.add(chunk_data.ChunkDataPacket)
|
|
||||||
return packets
|
|
||||||
return lambda x: wrapper(old_get_packets, x)
|
|
||||||
|
|
||||||
minecraft.networking.packets.clientbound.play.get_packets = get_packets(minecraft.networking.packets.clientbound.play.get_packets)
|
|
||||||
|
|
||||||
from minecraft import authentication
|
from minecraft import authentication
|
||||||
from minecraft.exceptions import YggdrasilError
|
from minecraft.exceptions import YggdrasilError
|
||||||
from minecraft.networking.connection import Connection
|
from minecraft.networking.connection import Connection
|
||||||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||||
|
|
||||||
|
from custom.managers import DataManager, ChunksManager
|
||||||
|
|
||||||
|
|
||||||
def get_options():
|
def get_options():
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
|
@ -124,18 +111,12 @@ def main():
|
||||||
print("Message (%s): %s" % (
|
print("Message (%s): %s" % (
|
||||||
chat_packet.field_string('position'), chat_packet.json_data))
|
chat_packet.field_string('position'), chat_packet.json_data))
|
||||||
|
|
||||||
#chunks = ChunksManager(mcdata)
|
chunks = ChunksManager(mcdata)
|
||||||
#chunks.register(connection)
|
chunks.register(connection)
|
||||||
|
|
||||||
connection.register_packet_listener(
|
connection.register_packet_listener(
|
||||||
print_chat, clientbound.play.ChatMessagePacket)
|
print_chat, clientbound.play.ChatMessagePacket)
|
||||||
|
|
||||||
def handle_chunk(chunk_packet):
|
|
||||||
print(chunk_packet)
|
|
||||||
|
|
||||||
def register(self, connection):
|
|
||||||
connection.register_packet_listener(handle_chunk, chunk_data.ChunkDataPacket)
|
|
||||||
|
|
||||||
connection.connect()
|
connection.connect()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user