feat: send SteerVehicle packets every 5s if riding

This is not the best way to do it. Mostly an ad-hoc fix for a tunnel
bore addon...
This commit is contained in:
əlemi 2023-03-16 14:13:36 +01:00
parent bcdb5a6694
commit ef8ffac391

View file

@ -1,5 +1,6 @@
import json import json
from time import time
from typing import Optional from typing import Optional
from aiocraft.mc.definitions import BlockPos from aiocraft.mc.definitions import BlockPos
@ -7,7 +8,7 @@ from aiocraft.mc.proto.play.clientbound import (
PacketPosition, PacketMapChunk, PacketBlockChange, PacketMultiBlockChange, PacketSetPassengers, PacketPosition, PacketMapChunk, PacketBlockChange, PacketMultiBlockChange, PacketSetPassengers,
PacketEntityTeleport, PacketRelEntityMove PacketEntityTeleport, PacketRelEntityMove
) )
from aiocraft.mc.proto.play.serverbound import PacketTeleportConfirm from aiocraft.mc.proto.play.serverbound import PacketTeleportConfirm, PacketSteerVehicle
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
@ -62,6 +63,19 @@ class GameWorld(Scaffold):
self.position.x, self.position.y, self.position.z self.position.x, self.position.y, self.position.z
) )
@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(
PacketSteerVehicle(
self.dispatcher.proto,
forward=0,
sideways=0,
jump=0
)
)
@self.on_packet(PacketPosition) @self.on_packet(PacketPosition)
async def player_rubberband_cb(packet:PacketPosition): async def player_rubberband_cb(packet:PacketPosition):
self.position = BlockPos(packet.x, packet.y, packet.z) self.position = BlockPos(packet.x, packet.y, packet.z)