Fix gapple bugs and unload far chunks

This commit is contained in:
2020-09-25 15:51:36 -06:00
parent 25ce916b43
commit fa9d597483
5 changed files with 62 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
import os
from math import floor
import json
import time
from minecraft.networking.packets import clientbound, serverbound
from protocol import packets
@@ -112,11 +113,10 @@ class ChunksManager:
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?
def check_loaded(self, position, steps):
x, y, z = utils.pint(position)
player_chunk = (x//16, 1, z//16)
for i in range(121): # TODO: base off render_distance?
for i in range(steps): # TODO: base off render_distance?
offset = utils.spiral(i)
check = utils.padd(player_chunk, offset)
@@ -125,6 +125,24 @@ class ChunksManager:
return True
def unload_chunks(self, position):
start = time.time()
x, y, z = utils.pint(position)
player_chunk = (x//16, 0, z//16)
loaded_chunks = list(self.chunks.keys())
count = 0
for chunk in loaded_chunks:
check = (chunk[0], 0, chunk[2])
if utils.phyp_king(player_chunk, check) > 16:
del self.chunks[chunk]
count += 1
if count:
print('unloaded', count, 'chunks in', time.time()-start, 's')
class ChunkNotLoadedException(Exception):
def __str__(self):