Move packet handlers into Game class
This commit is contained in:
37
bot.py
37
bot.py
@@ -20,13 +20,12 @@ from minecraft.networking.connection import Connection
|
||||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
|
||||
from protocol.managers import DataManager, ChunksManager, ChatManager, ChunkNotLoadedException
|
||||
from protocol.packets import TimeUpdatePacket, SetSlotPacket
|
||||
|
||||
from bunch import Bunch
|
||||
from panda3d.core import LPoint3f, LVector3f
|
||||
|
||||
import packet_handlers
|
||||
importlib.reload(packet_handlers)
|
||||
import game
|
||||
importlib.reload(game)
|
||||
import blocks
|
||||
importlib.reload(blocks)
|
||||
import utils
|
||||
@@ -135,6 +134,8 @@ def tick(global_state):
|
||||
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=l.pitch, yaw=l.yaw, on_ground=(not in_air))
|
||||
g.connection.write_packet(packet, force=True)
|
||||
|
||||
g.game.tick()
|
||||
|
||||
|
||||
def init(global_state):
|
||||
g = global_state
|
||||
@@ -149,10 +150,7 @@ def init(global_state):
|
||||
l.yaw = 360
|
||||
l.pitch = 0
|
||||
|
||||
#l.break = None
|
||||
#l.break_time = 0
|
||||
#l.break_timeout = 0
|
||||
#l.break_finished_packet = None
|
||||
l.breaking = None
|
||||
|
||||
#l.jobstate = JobStates(connection, player_info)
|
||||
#l.jobstate.run()
|
||||
@@ -178,34 +176,11 @@ def bot(global_state):
|
||||
|
||||
g.connection.connect()
|
||||
|
||||
def packet_wrapper(handler):
|
||||
def wrapper(packet):
|
||||
handler(packet, g)
|
||||
return wrapper
|
||||
|
||||
g.chunks.register(g.connection)
|
||||
|
||||
def x(p):
|
||||
print(p)
|
||||
|
||||
h = packet_wrapper(packet_handlers.handle_block_change)
|
||||
g.connection.register_packet_listener(h, clientbound.play.BlockChangePacket)
|
||||
|
||||
h = packet_wrapper(packet_handlers.handle_join_game)
|
||||
g.connection.register_packet_listener(h, clientbound.play.JoinGamePacket)
|
||||
|
||||
h = packet_wrapper(packet_handlers.handle_position_and_look)
|
||||
g.connection.register_packet_listener(h, clientbound.play.PlayerPositionAndLookPacket)
|
||||
|
||||
g.chat = ChatManager(g)
|
||||
h = packet_wrapper(packet_handlers.handle_chat)
|
||||
g.chat.set_handler(h)
|
||||
|
||||
h = packet_wrapper(packet_handlers.handle_time_update)
|
||||
g.connection.register_packet_listener(h, TimeUpdatePacket)
|
||||
|
||||
h = packet_wrapper(packet_handlers.handle_set_slot)
|
||||
g.connection.register_packet_listener(h, SetSlotPacket)
|
||||
g.game = game.Game(g)
|
||||
|
||||
try:
|
||||
while not g.pos:
|
||||
|
Reference in New Issue
Block a user