feat: also follow vehicle movement

This commit is contained in:
əlemi 2023-03-14 21:05:19 +01:00
parent 36a2fece2f
commit bcdb5a6694
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 48 additions and 8 deletions

View file

@ -74,6 +74,7 @@ class GameState(Scaffold):
@self.on_packet(PacketLogin)
async def player_joining_cb(packet:PacketLogin):
self.entity_id = packet.entityId
self.gamemode = Gamemode(packet.gameMode)
if isinstance(packet.dimension, dict):
self.dimension = Dimension.OVERWORLD # TODO wtf???

View file

@ -1,28 +1,66 @@
import asyncio
import json
import uuid
import datetime
import asyncio
from time import time
from typing import Dict, List
from typing import Optional
from aiocraft.mc.definitions import BlockPos
from aiocraft.mc.proto.play.clientbound import PacketPosition, PacketMapChunk, PacketBlockChange, PacketMultiBlockChange
from aiocraft.mc.proto.play.clientbound import (
PacketPosition, PacketMapChunk, PacketBlockChange, PacketMultiBlockChange, PacketSetPassengers,
PacketEntityTeleport, PacketRelEntityMove
)
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
vehicle_id : Optional[int]
world : World
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.position = BlockPos(0, 0, 0)
self.vehicle_id = None
@self.on_packet(PacketSetPassengers)
async def player_enters_vehicle_cb(packet:PacketSetPassengers):
if self.vehicle_id is None: # might get mounted on a vehicle
for entity_id in packet.passengers:
if entity_id == self.entity_id:
self.vehicle_id = packet.entityId
else: # might get dismounted from vehicle
if packet.entityId == self.vehicle_id:
if self.entity_id not in packet.passengers:
self.vehicle_id = None
@self.on_packet(PacketEntityTeleport)
async def entity_rubberband_cb(packet:PacketEntityTeleport):
if self.vehicle_id is None:
return
if self.vehicle_id != packet.entityId:
return
self.position = BlockPos(packet.x, packet.y, packet.z)
self.logger.info(
"Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (vehicle)",
self.position.x, self.position.y, self.position.z
)
@self.on_packet(PacketRelEntityMove)
async def entity_relative_move_cb(packet:PacketRelEntityMove):
if self.vehicle_id is None:
return
if self.vehicle_id != packet.entityId:
return
self.position = BlockPos(
self.position.x + packet.dX,
self.position.y + packet.dY,
self.position.z + packet.dZ
)
self.logger.info(
"Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (relMove vehicle)",
self.position.x, self.position.y, self.position.z
)
@self.on_packet(PacketPosition)
async def player_rubberband_cb(packet:PacketPosition):

View file

@ -23,6 +23,7 @@ class Scaffold(
Runnable,
MinecraftClient,
):
entity_id : int
config: ConfigParser