Delete old code
This commit is contained in:
parent
6eb7149890
commit
f8caf8f252
110013
old/blocks.json
110013
old/blocks.json
File diff suppressed because it is too large
Load Diff
216
old/blocks.py
216
old/blocks.py
|
@ -1,216 +0,0 @@
|
|||
import json
|
||||
|
||||
with open('blocks.json') as f:
|
||||
BLOCKS = json.load(f)
|
||||
|
||||
AVOID = [
|
||||
'minecraft:lava',
|
||||
'minecraft:water',
|
||||
'minecraft:fire',
|
||||
'minecraft:magma_block',
|
||||
'minecraft:oak_fence',
|
||||
'minecraft:oak_fence_gate',
|
||||
'minecraft:nether_brick_fence',
|
||||
'minecraft:spruce_fence_gate',
|
||||
'minecraft:birch_fence_gate',
|
||||
'minecraft:jungle_fence_gate',
|
||||
'minecraft:acacia_fence_gate',
|
||||
'minecraft:dark_oak_fence_gate',
|
||||
'minecraft:spruce_fence',
|
||||
'minecraft:birch_fence',
|
||||
'minecraft:jungle_fence',
|
||||
'minecraft:acacia_fence',
|
||||
'minecraft:dark_oak_fence',
|
||||
'minecraft:sweet_berry_bush',
|
||||
'minecraft:nether_portal',
|
||||
'minecraft:end_portal',
|
||||
'minecraft:cobblestone_wall',
|
||||
'minecraft:mossy_cobblestone_wall',
|
||||
'minecraft:brick_wall',
|
||||
'minecraft:prismarine_wall',
|
||||
'minecraft:red_sandstone_wall',
|
||||
'minecraft:mossy_stone_brick_wall',
|
||||
'minecraft:granite_wall',
|
||||
'minecraft:stone_brick_wall',
|
||||
'minecraft:nether_brick_wall',
|
||||
'minecraft:andesite_wall',
|
||||
'minecraft:red_nether_brick_wall',
|
||||
'minecraft:sandstone_wall',
|
||||
'minecraft:end_stone_brick_wall',
|
||||
'minecraft:diorite_wall',
|
||||
|
||||
]
|
||||
|
||||
NON_SOLID = [
|
||||
'minecraft:air',
|
||||
'minecraft:powered_rail',
|
||||
'minecraft:detector_rail',
|
||||
'minecraft:grass',
|
||||
'minecraft:fern',
|
||||
'minecraft:dead_bush',
|
||||
'minecraft:seagrass',
|
||||
'minecraft:tall_seagrass',
|
||||
'minecraft:dandelion',
|
||||
'minecraft:poppy',
|
||||
'minecraft:blue_orchid',
|
||||
'minecraft:allium',
|
||||
'minecraft:azure_bluet',
|
||||
'minecraft:red_tulip',
|
||||
'minecraft:orange_tulip',
|
||||
'minecraft:white_tulip',
|
||||
'minecraft:pink_tulip',
|
||||
'minecraft:oxeye_daisy',
|
||||
'minecraft:cornflower',
|
||||
'minecraft:wither_rose',
|
||||
'minecraft:lily_of_the_valley',
|
||||
'minecraft:brown_mushroom',
|
||||
'minecraft:red_mushroom',
|
||||
'minecraft:torch',
|
||||
'minecraft:wall_torch',
|
||||
'minecraft:redstone_wire',
|
||||
'minecraft:wheat',
|
||||
'minecraft:oak_sign',
|
||||
'minecraft:spruce_sign',
|
||||
'minecraft:birch_sign',
|
||||
'minecraft:acacia_sign',
|
||||
'minecraft:jungle_sign',
|
||||
'minecraft:dark_oak_sign',
|
||||
'minecraft:rail',
|
||||
'minecraft:oak_wall_sign',
|
||||
'minecraft:spruce_wall_sign',
|
||||
'minecraft:birch_wall_sign',
|
||||
'minecraft:acacia_wall_sign',
|
||||
'minecraft:jungle_wall_sign',
|
||||
'minecraft:dark_oak_wall_sign',
|
||||
'minecraft:lever',
|
||||
'minecraft:stone_pressure_plate',
|
||||
'minecraft:oak_pressure_plate',
|
||||
'minecraft:spruce_pressure_plate',
|
||||
'minecraft:birch_pressure_plate',
|
||||
'minecraft:jungle_pressure_plate',
|
||||
'minecraft:acacia_pressure_plate',
|
||||
'minecraft:dark_oak_pressure_plate',
|
||||
'minecraft:redstone_torch',
|
||||
'minecraft:redstone_wall_torch',
|
||||
'minecraft:stone_button',
|
||||
'minecraft:sugar_cane',
|
||||
'minecraft:repeater',
|
||||
'minecraft:attached_pumpkin_stem',
|
||||
'minecraft:attached_melon_stem',
|
||||
'minecraft:pumpkin_stem',
|
||||
'minecraft:melon_stem',
|
||||
'minecraft:nether_wart',
|
||||
'minecraft:tripwire_hook',
|
||||
'minecraft:tripwire',
|
||||
'minecraft:carrots',
|
||||
'minecraft:potatoes',
|
||||
'minecraft:oak_button',
|
||||
'minecraft:spruce_button',
|
||||
'minecraft:birch_button',
|
||||
'minecraft:jungle_button',
|
||||
'minecraft:acacia_button',
|
||||
'minecraft:dark_oak_button',
|
||||
'minecraft:light_weighted_pressure_plate',
|
||||
'minecraft:heavy_weighted_pressure_plate',
|
||||
'minecraft:comparator',
|
||||
'minecraft:activator_rail',
|
||||
'minecraft:white_carpet',
|
||||
'minecraft:orange_carpet',
|
||||
'minecraft:magenta_carpet',
|
||||
'minecraft:light_blue_carpet',
|
||||
'minecraft:yellow_carpet',
|
||||
'minecraft:lime_carpet',
|
||||
'minecraft:pink_carpet',
|
||||
'minecraft:gray_carpet',
|
||||
'minecraft:light_gray_carpet',
|
||||
'minecraft:cyan_carpet',
|
||||
'minecraft:purple_carpet',
|
||||
'minecraft:blue_carpet',
|
||||
'minecraft:brown_carpet',
|
||||
'minecraft:green_carpet',
|
||||
'minecraft:red_carpet',
|
||||
'minecraft:black_carpet',
|
||||
'minecraft:sunflower',
|
||||
'minecraft:lilac',
|
||||
'minecraft:rose_bush',
|
||||
'minecraft:peony',
|
||||
'minecraft:tall_grass',
|
||||
'minecraft:large_fern',
|
||||
'minecraft:white_banner',
|
||||
'minecraft:orange_banner',
|
||||
'minecraft:magenta_banner',
|
||||
'minecraft:light_blue_banner',
|
||||
'minecraft:yellow_banner',
|
||||
'minecraft:lime_banner',
|
||||
'minecraft:pink_banner',
|
||||
'minecraft:gray_banner',
|
||||
'minecraft:light_gray_banner',
|
||||
'minecraft:cyan_banner',
|
||||
'minecraft:purple_banner',
|
||||
'minecraft:blue_banner',
|
||||
'minecraft:brown_banner',
|
||||
'minecraft:green_banner',
|
||||
'minecraft:red_banner',
|
||||
'minecraft:black_banner',
|
||||
'minecraft:white_wall_banner',
|
||||
'minecraft:orange_wall_banner',
|
||||
'minecraft:magenta_wall_banner',
|
||||
'minecraft:light_blue_wall_banner',
|
||||
'minecraft:yellow_wall_banner',
|
||||
'minecraft:lime_wall_banner',
|
||||
'minecraft:pink_wall_banner',
|
||||
'minecraft:gray_wall_banner',
|
||||
'minecraft:light_gray_wall_banner',
|
||||
'minecraft:cyan_wall_banner',
|
||||
'minecraft:purple_wall_banner',
|
||||
'minecraft:blue_wall_banner',
|
||||
'minecraft:brown_wall_banner',
|
||||
'minecraft:green_wall_banner',
|
||||
'minecraft:red_wall_banner',
|
||||
'minecraft:black_wall_banner',
|
||||
'minecraft:beetroots',
|
||||
'minecraft:bamboo_sapling',
|
||||
'minecraft:void_air',
|
||||
'minecraft:cave_air',
|
||||
'minecraft:lantern',
|
||||
]
|
||||
SINGLE_SNOW = 3919
|
||||
|
||||
LOGS = [
|
||||
'minecraft:oak_log',
|
||||
'minecraft:spruce_log',
|
||||
'minecraft:birch_log',
|
||||
'minecraft:jungle_log',
|
||||
'minecraft:acacia_log',
|
||||
'minecraft:dark_oak_log',
|
||||
]
|
||||
|
||||
LEAVES = [
|
||||
'minecraft:oak_leaves',
|
||||
'minecraft:spruce_leaves',
|
||||
'minecraft:birch_leaves',
|
||||
'minecraft:jungle_leaves',
|
||||
'minecraft:acacia_leaves',
|
||||
'minecraft:dark_oak_leaves',
|
||||
]
|
||||
|
||||
|
||||
NON_SOLID_IDS = set([SINGLE_SNOW])
|
||||
for block_name in NON_SOLID:
|
||||
for state in BLOCKS[block_name]['states']:
|
||||
NON_SOLID_IDS.add(state['id'])
|
||||
|
||||
AVOID_IDS = set()
|
||||
for block_name in AVOID:
|
||||
for state in BLOCKS[block_name]['states']:
|
||||
AVOID_IDS.add(state['id'])
|
||||
|
||||
LOG_IDS = set()
|
||||
for block_name in LOGS:
|
||||
for state in BLOCKS[block_name]['states']:
|
||||
LOG_IDS.add(state['id'])
|
||||
|
||||
LEAF_IDS = set()
|
||||
for block_name in LEAVES:
|
||||
for state in BLOCKS[block_name]['states']:
|
||||
LEAF_IDS.add(state['id'])
|
1397
old/bot.py
1397
old/bot.py
File diff suppressed because it is too large
Load Diff
|
@ -1,149 +0,0 @@
|
|||
import minecraft.networking.packets
|
||||
|
||||
from minecraft.networking.packets import Packet
|
||||
from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byte, UnsignedByte, Short, TrailingByteArray, Long
|
||||
from minecraft.networking.types.basic import Type
|
||||
|
||||
#def qot(x):
|
||||
# print('qot.')
|
||||
# return set()
|
||||
#
|
||||
#minecraft.networking.packets.clientbound.play.get_packets = qot
|
||||
|
||||
|
||||
class AcknowledgePlayerDiggingPacket(Packet):
|
||||
id = 0x08
|
||||
packet_name = 'acknowledge player digging'
|
||||
definition = [
|
||||
{'location': Position},
|
||||
{'block': VarInt},
|
||||
{'status': VarInt},
|
||||
{'successful': Boolean},
|
||||
]
|
||||
|
||||
class BlockBreakAnimationPacket(Packet):
|
||||
id = 0x09
|
||||
packet_name = 'block break animation'
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'location': Position},
|
||||
{'destroy_stage': Byte},
|
||||
]
|
||||
|
||||
#class WindowItemsPacket(Packet):
|
||||
# id = 0x15
|
||||
# packet_name = 'window items'
|
||||
# definition = [
|
||||
# {'window_id': UnsignedByte},
|
||||
# {'count': Short},
|
||||
# {'destroy_stage': Byte},
|
||||
# ]
|
||||
|
||||
|
||||
class Slot(Type):
|
||||
def __init__(self, present, item_id, item_count, nbt):
|
||||
self.present = present
|
||||
self.item_id = item_id
|
||||
self.item_count = item_count
|
||||
self.nbt = nbt
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
def __repr__(self):
|
||||
return 'Slot(present={}, item_id={}, item_count={}, nbt={}'.format(
|
||||
self.present, self.item_id, self.item_count, self.nbt)
|
||||
|
||||
@staticmethod
|
||||
def read(file_object):
|
||||
present = Boolean.read(file_object)
|
||||
item_id = VarInt.read(file_object) if present else None
|
||||
item_count = Byte.read(file_object) if present else None
|
||||
nbt = TrailingByteArray.read(file_object) if present else None
|
||||
return Slot(present, item_id, item_count, nbt)
|
||||
#a = {}
|
||||
#a['present'] = Boolean.read(file_object)
|
||||
#a['item_id'] = VarInt.read(file_object) if a['present'] else None
|
||||
#a['item_count'] = Byte.read(file_object) if a['present'] else None
|
||||
#a['nbt'] = TrailingByteArray.read(file_object) if a['present'] else None
|
||||
#return a
|
||||
|
||||
@staticmethod
|
||||
def send(value, socket):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
class SetSlotPacket(Packet):
|
||||
id = 0x17
|
||||
packet_name = 'set slot'
|
||||
definition = [
|
||||
{'window_id': Byte},
|
||||
{'slot': Short},
|
||||
{'slot_data': Slot},
|
||||
]
|
||||
|
||||
class TimeUpdatePacket(Packet):
|
||||
id = 0x4F
|
||||
packet_name = 'time update'
|
||||
definition = [
|
||||
{'world_age': Long},
|
||||
{'time_of_day': Long},
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
def get_packets(old_get_packets):
|
||||
def wrapper(func, context):
|
||||
print('Monkey-patched.')
|
||||
packets = func(context)
|
||||
packets.add(AcknowledgePlayerDiggingPacket)
|
||||
packets.add(BlockBreakAnimationPacket)
|
||||
packets.add(SetSlotPacket)
|
||||
packets.add(TimeUpdatePacket)
|
||||
return packets
|
||||
return lambda x: wrapper(old_get_packets, x)
|
||||
|
||||
minecraft.networking.packets.clientbound.play.get_packets = get_packets(minecraft.networking.packets.clientbound.play.get_packets)
|
||||
|
||||
class PlayerDiggingPacket(Packet):
|
||||
# used when player mines / breaks blocks
|
||||
# https://wiki.vg/Protocol#Player_Digging
|
||||
|
||||
id = 0x1A
|
||||
packet_name = 'player digging'
|
||||
|
||||
definition = [
|
||||
{'status': VarInt},
|
||||
{'location': Position},
|
||||
{'face': VarInt},
|
||||
]
|
||||
|
||||
STARTED = 0
|
||||
CANCELLED = 1
|
||||
FINISHED = 2
|
||||
|
||||
# PlayerBlockPlacementPacket.Face is an alias for BlockFace.
|
||||
Face = BlockFace
|
||||
|
||||
|
||||
class PickItemPacket(Packet):
|
||||
# used when player picks item (middle click)
|
||||
# https://wiki.vg/Protocol#Pick_Item
|
||||
|
||||
id = 0x17
|
||||
packet_name = 'pick item'
|
||||
|
||||
definition = [
|
||||
{'slot_to_use': VarInt},
|
||||
]
|
||||
|
||||
class HeldItemChangePacket(Packet):
|
||||
# Sent when the player changes the slot selection
|
||||
# https://wiki.vg/Protocol#Held_Item_Change_.28serverbound.29
|
||||
|
||||
id = 0x23
|
||||
packet_name = 'held item change'
|
||||
|
||||
definition = [
|
||||
{'slot': Short},
|
||||
]
|
31
old/items.py
31
old/items.py
|
@ -1,31 +0,0 @@
|
|||
import json
|
||||
|
||||
with open('registries.json') as f:
|
||||
ITEMS = json.load(f)['minecraft:item']['entries']
|
||||
|
||||
BEDS = [
|
||||
'minecraft:white_bed',
|
||||
'minecraft:orange_bed',
|
||||
'minecraft:magenta_bed',
|
||||
'minecraft:light_blue_bed',
|
||||
'minecraft:yellow_bed',
|
||||
'minecraft:lime_bed',
|
||||
'minecraft:pink_bed',
|
||||
'minecraft:gray_bed',
|
||||
'minecraft:light_gray_bed',
|
||||
'minecraft:cyan_bed',
|
||||
'minecraft:purple_bed',
|
||||
'minecraft:blue_bed',
|
||||
'minecraft:brown_bed',
|
||||
'minecraft:green_bed',
|
||||
'minecraft:red_bed',
|
||||
'minecraft:black_bed',
|
||||
]
|
||||
|
||||
BED_IDS = set()
|
||||
for item_name in BEDS:
|
||||
BED_IDS.add(ITEMS[item_name]['protocol_id'])
|
||||
|
||||
ITEM_NAMES = {}
|
||||
for item_name, item in ITEMS.items():
|
||||
ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name
|
9999
old/registries.json
9999
old/registries.json
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +0,0 @@
|
|||
cryptography>=1.5
|
||||
requests
|
||||
future
|
140
old/start.py
140
old/start.py
|
@ -1,140 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import threading
|
||||
import importlib
|
||||
|
||||
import getpass
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from optparse import OptionParser
|
||||
|
||||
import bot
|
||||
|
||||
from minecraft import authentication
|
||||
from minecraft.exceptions import YggdrasilError
|
||||
from minecraft.networking.connection import Connection
|
||||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
from minecraft.compat import input
|
||||
|
||||
|
||||
get_mod_time = lambda: os.path.getmtime('bot.py')
|
||||
|
||||
class PlayerInfo:
|
||||
eid = None
|
||||
pos = None
|
||||
inv = {}
|
||||
mcdata = None
|
||||
chunks = None
|
||||
|
||||
|
||||
player_info = PlayerInfo()
|
||||
|
||||
|
||||
def get_options():
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-u", "--username", dest="username", default=None,
|
||||
help="username to log in with")
|
||||
|
||||
parser.add_option("-p", "--password", dest="password", default=None,
|
||||
help="password to log in with")
|
||||
|
||||
parser.add_option("-s", "--server", dest="server", default=None,
|
||||
help="server host or host:port "
|
||||
"(enclose IPv6 addresses in square brackets)")
|
||||
|
||||
parser.add_option("-o", "--offline", dest="offline", action="store_true",
|
||||
help="connect to a server in offline mode "
|
||||
"(no password required)")
|
||||
|
||||
parser.add_option("-d", "--dump-packets", dest="dump_packets",
|
||||
action="store_true",
|
||||
help="print sent and received packets to standard error")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if not options.username:
|
||||
options.username = input("Enter your username: ")
|
||||
|
||||
if not options.password and not options.offline:
|
||||
options.password = getpass.getpass("Enter your password (leave "
|
||||
"blank for offline mode): ")
|
||||
options.offline = options.offline or (options.password == "")
|
||||
|
||||
if not options.server:
|
||||
options.server = input("Enter server host or host:port "
|
||||
"(enclose IPv6 addresses in square brackets): ")
|
||||
# Try to split out port and address
|
||||
match = re.match(r"((?P<host>[^\[\]:]+)|\[(?P<addr>[^\[\]]+)\])"
|
||||
r"(:(?P<port>\d+))?$", options.server)
|
||||
if match is None:
|
||||
raise ValueError("Invalid server address: '%s'." % options.server)
|
||||
options.address = match.group("host") or match.group("addr")
|
||||
options.port = int(match.group("port") or 25565)
|
||||
|
||||
return options
|
||||
|
||||
|
||||
def main():
|
||||
global last_mod_time
|
||||
|
||||
options = get_options()
|
||||
|
||||
if options.offline:
|
||||
print("Connecting in offline mode...")
|
||||
connection = Connection(
|
||||
options.address, options.port, username=options.username)
|
||||
else:
|
||||
auth_token = authentication.AuthenticationToken()
|
||||
try:
|
||||
auth_token.authenticate(options.username, options.password)
|
||||
except YggdrasilError as e:
|
||||
print(e)
|
||||
sys.exit()
|
||||
print("Logged in as %s..." % auth_token.username)
|
||||
connection = Connection(
|
||||
options.address, options.port, auth_token=auth_token)
|
||||
|
||||
if options.dump_packets:
|
||||
def print_incoming(packet):
|
||||
if type(packet) is Packet:
|
||||
# This is a direct instance of the base Packet type, meaning
|
||||
# that it is a packet of unknown type, so we do not print it.
|
||||
return
|
||||
print('--> %s' % packet, file=sys.stderr)
|
||||
|
||||
def print_outgoing(packet):
|
||||
print('<-- %s' % packet, file=sys.stderr)
|
||||
|
||||
connection.register_packet_listener(
|
||||
print_incoming, Packet, early=True)
|
||||
connection.register_packet_listener(
|
||||
print_outgoing, Packet, outgoing=True)
|
||||
|
||||
|
||||
connection.connect()
|
||||
|
||||
while True:
|
||||
try:
|
||||
importlib.reload(bot)
|
||||
bot.main(connection, player_info)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Bye!")
|
||||
sys.exit()
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
|
||||
last_mod_time = get_mod_time()
|
||||
print('locking')
|
||||
while get_mod_time() == last_mod_time:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user