Compare commits

..

No commits in common. "db8d8d7b85f99ba39a1a28b2fe8f86f2ef76e8aa" and "514b324156f7731043b9fb27620f495b1d45b0ad" have entirely different histories.

5 changed files with 12 additions and 66 deletions

61
bot.py
View File

@ -2,41 +2,28 @@ if __name__ == '__main__':
print('Run main.py instead.')
exit(1)
import os
import time
import importlib
USERNAME = os.environ['USERNAME']
PASSWORD = os.environ['PASSWORD']
SERVER = os.environ['SERVER']
import monkey_patch # must be before any possible pyCraft imports
USERNAME = ''
PASSWORD = ''
SERVER = ''
from custom.managers import DataManager, ChunksManager, ChatManager
import monkey_patch
from minecraft import authentication
from minecraft.exceptions import YggdrasilError
from minecraft.networking.connection import Connection
from minecraft.networking.packets import Packet, clientbound, serverbound
from custom.networking.packets.clientbound.play.block_change_packet import BlockChangePacket
import packet_handlers
importlib.reload(packet_handlers)
TICK = 0.05
last_tick = time.time()
def tick():
return
def bot(global_state):
g = global_state
if 'mcdata' not in g:
g.mcdata = DataManager('./mcdata')
if not g.connection:
if 'connection' not in g:
auth_token = authentication.AuthenticationToken()
try:
auth_token.authenticate(USERNAME, PASSWORD)
@ -61,38 +48,4 @@ def bot(global_state):
g.connection.connect()
def packet_wrapper(handler):
def wrapper(packet):
print('called')
handler(packet, g)
return wrapper
h = packet_wrapper(packet_handlers.handle_block_change)
g.connection.register_packet_listener(h, BlockChangePacket)
try:
#while not player_info.pos:
# time.sleep(TICK)
#print('Player loaded.')
#x, y, z = pint(player_info.pos)
#while (floor(x/16), floor(y/16), floor(z/16)) not in player_info.chunks.chunks:
# time.sleep(TICK)
#print('Chunks loaded.')
while g.running:
tick()
global last_tick
sleep_time = TICK + last_tick - time.time()
if sleep_time < 0: sleep_time = 0
time.sleep(sleep_time)
last_tick = time.time()
finally:
print('Removing listeners...')
g.connection.packet_listeners = []
g.connection.early_packet_listeners = []
g.connection.outgoing_packet_listeners = []
g.connection.early_outgoing_packet_listeners = []
print('Bot module loaded.')
time.sleep(1)

View File

@ -28,8 +28,8 @@ class ChunkDataPacket(Packet):
self.data = file_object.read(size)
size_entities = VarInt.read(file_object)
self.entities = []
for i in range(size_entities):
self.entities.append(Nbt.read(file_object))
#for i in range(size_entities):
# self.entities.append(Nbt.read(file_object))
self.decode_chunk_data()

View File

@ -12,7 +12,6 @@ from watchdog.events import PatternMatchingEventHandler
import bot
global_state = Bunch()
g = global_state
g.connection = False
@app.route('/')
def hello_world():
@ -25,10 +24,10 @@ reload_timeout = time.time()
def main():
def reload_bot(event):
global reload_timeout
if time.time() - reload_timeout > 2.0:
if time.time() - reload_timeout > 5.0:
reload_timeout = time.time()
print('Reloading...')
g.running = False
importlib.reload(bot)
event_handler = PatternMatchingEventHandler(patterns=['*.py'], ignore_patterns=['./main.py'])
event_handler.on_any_event = reload_bot
@ -39,9 +38,7 @@ def main():
try:
while True:
g.running = True
bot.bot(global_state)
importlib.reload(bot)
except KeyboardInterrupt:
observer.stop()
observer.join()
@ -49,5 +46,4 @@ def main():
if __name__ == '__main__':
threading.Thread(target=app.run).start()
time.sleep(1)
main()

View File

@ -3,7 +3,7 @@ from custom.networking.packets.clientbound.play import chunk_data, block_change_
def get_packets(old_get_packets):
def wrapper(func, context):
print('Monkey-patch worked.')
print('Monkey-patched.')
packets = func(context)
# add any custom packets here

View File

@ -1,3 +0,0 @@
def handle_block_change(p, g):
print('block change:')
print(p)