pass some values, check blocks above and below at intervals

This commit is contained in:
əlemi 2022-01-15 01:59:14 +01:00
parent 0ef56df704
commit 5672a4ad36

View file

@ -12,6 +12,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
from aiocraft.client import MinecraftClient from aiocraft.client import MinecraftClient
from aiocraft.mc.packet import Packet from aiocraft.mc.packet import Packet
from aiocraft.mc.types import Context
from aiocraft.mc.definitions import Difficulty, Dimension, Gamemode, BlockPos from aiocraft.mc.definitions import Difficulty, Dimension, Gamemode, BlockPos
from aiocraft.mc.proto.play.clientbound import ( from aiocraft.mc.proto.play.clientbound import (
@ -88,7 +89,6 @@ class Treepuncher(MinecraftClient):
self.tablist = {} self.tablist = {}
self._register_handlers()
self.modules = [] self.modules = []
tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzname() # APScheduler will complain if I don't specify a timezone... tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzname() # APScheduler will complain if I don't specify a timezone...
@ -96,6 +96,8 @@ class Treepuncher(MinecraftClient):
logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING) # So it's way less spammy logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING) # So it's way less spammy
self.scheduler.start(paused=True) self.scheduler.start(paused=True)
self._register_handlers()
@property @property
def name(self) -> str: def name(self) -> str:
if self.online_mode and self.token: if self.online_mode and self.token:
@ -287,8 +289,15 @@ class Treepuncher(MinecraftClient):
@self.on_packet(PacketMapChunk) @self.on_packet(PacketMapChunk)
async def process_chunk_packet(packet:PacketMapChunk): async def process_chunk_packet(packet:PacketMapChunk):
chunk = Chunk(packet.x, packet.z, packet.bitMap) chunk = Chunk(packet.x, packet.z, packet.bitMap, ground_up_continuous=packet.groundUp)
chunk.read(io.BytesIO(packet.chunkData)) # self._logger.info("Processing chunk buffer of length %d", len(packet.chunkData))
chunk.read(io.BytesIO(packet.chunkData), Context(overworld=self.dimension == Dimension.OVERWORLD))
self.world.put(chunk, x=packet.x, z=packet.z) self.world.put(chunk, x=packet.x, z=packet.z)
@self.scheduler.scheduled_job('interval', seconds=15)
async def check_blocks_under_self():
for i in range(-5, 5):
block = self.world.get(self.position.x, self.position.y-i, self.position.z)
self._logger.info("Block %d positions below self : %d", i, block)