Add a job to find enchanted golden apples

This commit is contained in:
2020-09-25 00:03:22 -06:00
parent b723143299
commit 25ce916b43
10 changed files with 163 additions and 11 deletions

View File

@@ -5,6 +5,8 @@ import json
from minecraft.networking.packets import clientbound, serverbound
from protocol import packets
import utils
class DataManager:
def __init__(self, directory):
self.blocks = {}
@@ -80,7 +82,8 @@ class ChunksManager:
def get_chunk(self, x, y, z):
index = (x, y, z)
if not index in self.chunks:
raise ChunkNotLoadedException(index)
return None
#raise ChunkNotLoadedException(index)
return self.chunks[index]
def get_loaded_area(self, ignore_empty=False):
@@ -101,12 +104,27 @@ class ChunksManager:
def get_block_at(self, x, y, z):
c = self.get_chunk(floor(x/16), floor(y/16), floor(z/16))
if not c: return None
return c.get_block_at(x%16, y%16, z%16)
def set_block_at(self, x, y, z, block):
c = self.get_chunk(floor(x/16), floor(y/16), floor(z/16))
if not c: return None
c.set_block_at(x%16, y%16, z%16, block)
def check_loaded(self, position):
#for i in range(441): # TODO: base off render_distance?
x, y, z = utils.pint(position)
player_chunk = (x//16, 1, z//16)
for i in range(121): # TODO: base off render_distance?
offset = utils.spiral(i)
check = utils.padd(player_chunk, offset)
if check not in self.chunks:
return False
return True
class ChunkNotLoadedException(Exception):
def __str__(self):

View File

@@ -312,7 +312,7 @@ class EntityMetadataPacket(Packet):
self.entity_id = VarInt.read(file_object)
self.metadata = []
for _ in range(99):
entry = Entry.read(file_object)
entry = Entry.read(file_object, self.context)
if not entry: break
self.metadata.append(entry)

View File

@@ -133,7 +133,7 @@ class Slot(Type):
Boolean.send(value.present, socket)
VarInt.send(value.item_id, socket)
Byte.send(value.item_count, socket)
TrailingByteArray.send(value.nbt, socket)
Byte.send(0x00, socket)
class Entry(Type):
@@ -157,16 +157,18 @@ class Entry(Type):
def __str__(self):
return str(self.__dict__)
def __repr__(self):
return 'Entry(index={}, type={}, value={}'.format(
return 'Entry(index={}, type={}, value={})'.format(
self.index, self.type, self.value)
@staticmethod
def read(file_object):
def read(file_object, context):
index = UnsignedByte.read(file_object)
if index == 0xff: return None
type = VarInt.read(file_object)
try:
value = Entry.types[type].read(file_object)
except TypeError:
value = Entry.types[type].read_with_context(file_object, context)
except KeyError:
return None
return Entry(index, type, value)