feat: process world (default off)

This commit is contained in:
əlemi 2022-07-03 00:06:15 +02:00
parent a563984e48
commit 48590d56bd
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -1,28 +1,28 @@
import asyncio
import uuid
import datetime
import asyncio
from time import time
from typing import Dict, List
from aiocraft.mc.definitions import BlockPos
from aiocraft.mc.proto.play.clientbound import PacketPosition
from aiocraft.mc.proto.play.clientbound import PacketPosition, PacketMapChunk, PacketBlockChange, PacketMultiBlockChange
from aiocraft.mc.proto.play.serverbound import PacketTeleportConfirm
from aiocraft import Chunk, World # TODO these imports will hopefully change!
from ..scaffold import Scaffold
from ..events import ConnectedEvent
class GameWorld(Scaffold):
position : BlockPos
# TODO world
world : World
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.position = BlockPos(0, 0, 0)
@self.on(ConnectedEvent)
async def connected_cb(_):
self.tablist.clear()
@self.on_packet(PacketPosition)
async def player_rubberband_cb(packet:PacketPosition):
self.position = BlockPos(packet.x, packet.y, packet.z)
@ -36,3 +36,27 @@ class GameWorld(Scaffold):
teleportId=packet.teleportId
)
)
if self.cfg.getboolean("process_world", fallback=False):
self.world = World()
@self.on_packet(PacketMapChunk)
async def map_chunk_cb(packet:PacketMapChunk):
assert isinstance(packet.bitMap, int)
packet.blockEntities
c = Chunk(packet.x, packet.z, packet.bitMap, packet.groundUp)
c.read(packet.chunkData)
self.world.put(c, packet.x, packet.z, not packet.groundUp)
@self.on_packet(PacketBlockChange)
async def block_change_cb(packet:PacketBlockChange):
self.world.put_block(packet.location[0], packet.location[1], packet.location[2], packet.id)
@self.on_packet(PacketMultiBlockChange)
async def multi_block_change_cb(packet:PacketMultiBlockChange):
chunk_x_off = packet.chunkX * 16
chunk_z_off = packet.chunkZ * 16
for entry in packet.records:
x_off = (entry['horizontalPos'] >> 4 ) & 15
z_off = entry['horizontalPos'] & 15
self.world.put_block(x_off + chunk_x_off, entry['y'], z_off + chunk_z_off, entry['blockId'])