fix: there isn't a scheduler yet when registering
This commit is contained in:
parent
ef8ffac391
commit
8655c5ebde
1 changed files with 12 additions and 13 deletions
|
@ -18,11 +18,14 @@ class GameWorld(Scaffold):
|
||||||
vehicle_id : Optional[int]
|
vehicle_id : Optional[int]
|
||||||
world : World
|
world : World
|
||||||
|
|
||||||
|
_last_steer_vehicle : float
|
||||||
|
|
||||||
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.vehicle_id = None
|
||||||
|
self._last_steer_vehicle = time()
|
||||||
|
|
||||||
@self.on_packet(PacketSetPassengers)
|
@self.on_packet(PacketSetPassengers)
|
||||||
async def player_enters_vehicle_cb(packet:PacketSetPassengers):
|
async def player_enters_vehicle_cb(packet:PacketSetPassengers):
|
||||||
|
@ -58,15 +61,11 @@ class GameWorld(Scaffold):
|
||||||
self.position.y + packet.dY,
|
self.position.y + packet.dY,
|
||||||
self.position.z + packet.dZ
|
self.position.z + packet.dZ
|
||||||
)
|
)
|
||||||
self.logger.info(
|
self.logger.debug(
|
||||||
"Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (relMove vehicle)",
|
"Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (relMove vehicle)",
|
||||||
self.position.x, self.position.y, self.position.z
|
self.position.x, self.position.y, self.position.z
|
||||||
)
|
)
|
||||||
|
if time() - self._last_steer_vehicle >= 5:
|
||||||
@self.scheduler.scheduled_job('interval', seconds=5, name='send steer vehicle if riding a vehicle')
|
|
||||||
async def steer_vehicle_cb():
|
|
||||||
if self.vehicle_id is None:
|
|
||||||
return
|
|
||||||
await self.dispatcher.write(
|
await self.dispatcher.write(
|
||||||
PacketSteerVehicle(
|
PacketSteerVehicle(
|
||||||
self.dispatcher.proto,
|
self.dispatcher.proto,
|
||||||
|
|
Loading…
Reference in a new issue