feat: also follow vehicle movement
This commit is contained in:
parent
36a2fece2f
commit
bcdb5a6694
3 changed files with 48 additions and 8 deletions
|
@ -74,6 +74,7 @@ class GameState(Scaffold):
|
||||||
|
|
||||||
@self.on_packet(PacketLogin)
|
@self.on_packet(PacketLogin)
|
||||||
async def player_joining_cb(packet:PacketLogin):
|
async def player_joining_cb(packet:PacketLogin):
|
||||||
|
self.entity_id = packet.entityId
|
||||||
self.gamemode = Gamemode(packet.gameMode)
|
self.gamemode = Gamemode(packet.gameMode)
|
||||||
if isinstance(packet.dimension, dict):
|
if isinstance(packet.dimension, dict):
|
||||||
self.dimension = Dimension.OVERWORLD # TODO wtf???
|
self.dimension = Dimension.OVERWORLD # TODO wtf???
|
||||||
|
|
|
@ -1,28 +1,66 @@
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import uuid
|
|
||||||
import datetime
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from time import time
|
from typing import Optional
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
from aiocraft.mc.definitions import BlockPos
|
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.mc.proto.play.serverbound import PacketTeleportConfirm
|
||||||
from aiocraft import Chunk, World # TODO these imports will hopefully change!
|
from aiocraft import Chunk, World # TODO these imports will hopefully change!
|
||||||
|
|
||||||
from ..scaffold import Scaffold
|
from ..scaffold import Scaffold
|
||||||
from ..events import ConnectedEvent
|
|
||||||
|
|
||||||
class GameWorld(Scaffold):
|
class GameWorld(Scaffold):
|
||||||
position : BlockPos
|
position : BlockPos
|
||||||
|
vehicle_id : Optional[int]
|
||||||
world : World
|
world : World
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.position = BlockPos(0, 0, 0)
|
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)
|
@self.on_packet(PacketPosition)
|
||||||
async def player_rubberband_cb(packet:PacketPosition):
|
async def player_rubberband_cb(packet:PacketPosition):
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Scaffold(
|
||||||
Runnable,
|
Runnable,
|
||||||
MinecraftClient,
|
MinecraftClient,
|
||||||
):
|
):
|
||||||
|
entity_id : int
|
||||||
|
|
||||||
config: ConfigParser
|
config: ConfigParser
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue