|
|
|
@ -69,11 +69,10 @@ class ChunksManager: |
|
|
|
|
|
|
|
|
|
for item_id, locations in chunk.sub_index.items(): |
|
|
|
|
if item_id not in self.index: |
|
|
|
|
self.index[item_id] = [] |
|
|
|
|
|
|
|
|
|
self.index[item_id] = set() |
|
|
|
|
for l in locations: |
|
|
|
|
coords = (dx + l%16, dy + l//256, dz + l%256//16) |
|
|
|
|
self.index[item_id].append(coords) |
|
|
|
|
self.index[item_id].add(coords) |
|
|
|
|
|
|
|
|
|
#self.biomes[(chunk_packet.x, None, chunk_packet.z)] = chunk_packet.biomes # FIXME |
|
|
|
|
if self.loading: |
|
|
|
@ -119,31 +118,24 @@ class ChunksManager: |
|
|
|
|
|
|
|
|
|
if block in blocks.INDEXED_IDS: |
|
|
|
|
if block not in self.index: |
|
|
|
|
self.index[block] = [] |
|
|
|
|
self.index[block].append((x, y, z)) |
|
|
|
|
|
|
|
|
|
def check_loaded(self, position, steps=1): |
|
|
|
|
x, y, z = utils.pint(position) |
|
|
|
|
player_chunk = (x//16, 1, z//16) |
|
|
|
|
for i in range(steps): # 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 |
|
|
|
|
|
|
|
|
|
def unload_chunks(self, position): |
|
|
|
|
x, y, z = utils.pint(position) |
|
|
|
|
player_chunk = (x//16, 0, z//16) |
|
|
|
|
loaded_chunks = list(self.chunks.keys()) |
|
|
|
|
|
|
|
|
|
for chunk in loaded_chunks: |
|
|
|
|
check = (chunk[0], 0, chunk[2]) |
|
|
|
|
if utils.phyp_king(player_chunk, check) > 20: |
|
|
|
|
del self.chunks[chunk] |
|
|
|
|
|
|
|
|
|
self.index[block] = set() |
|
|
|
|
self.index[block].add((x, y, z)) |
|
|
|
|
|
|
|
|
|
def check_loaded(self, chunk_distance): |
|
|
|
|
num = (chunk_distance * 2 + 1) ** 2 |
|
|
|
|
num_subchunks = num * 16 |
|
|
|
|
return len(self.chunks) >= num_subchunks |
|
|
|
|
|
|
|
|
|
def unload_chunk(self, x, z): |
|
|
|
|
for y in range(16): |
|
|
|
|
try: |
|
|
|
|
del self.chunks[(x, y, z)] |
|
|
|
|
except KeyError: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
def unload_all_chunks(self): |
|
|
|
|
self.chunks = {} |
|
|
|
|
self.index = {} |
|
|
|
|
|
|
|
|
|
class ChunkNotLoadedException(Exception): |
|
|
|
|
def __str__(self): |
|
|
|
|