diff --git a/README.md b/README.md index c9942141..d3ebdf51 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ A Rust crate for creating Minecraft bots. Azalea

+ +*Currently supported Minecraft version: `1.18.2`.* + I named this Azalea because it sounds like a cool word and this is a cool library. This project was heavily inspired by PrismarineJS. ## Why diff --git a/code-generator/README.md b/code-generator/README.md deleted file mode 100644 index a6c60c47..00000000 --- a/code-generator/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Tools for automatically generating code to help with updating Minecraft versions. - -The directory name doesn't start with `azalea-` because it's not a Rust crate. - -## Usage - -Generate packet:\ -`python main.py [packet id] [clientbound or serverbound] \[game/handshake/login/status\]` diff --git a/code-generator/.gitignore b/codegen/.gitignore similarity index 100% rename from code-generator/.gitignore rename to codegen/.gitignore diff --git a/codegen/README.md b/codegen/README.md new file mode 100644 index 00000000..fa00b63f --- /dev/null +++ b/codegen/README.md @@ -0,0 +1,13 @@ +Tools for automatically generating code to help with updating Minecraft versions. + +The directory name doesn't start with `azalea-` because it's not a Rust crate. + +## Usage + +Generate packet:\ +`python newpacket.py [packet id] [clientbound or serverbound] \[game/handshake/login/status\]`\ +This will create a new file in the `azalea-protocol/src/packets/\[state\] directory`. You will probably have to manually fix up the auto generated code. + +Migrate to a new Minecraft version:\ +`python migrate.py [new version]`\ +This updates all the packet ids in `azalea-protocol/src/packets/mod.rs` and creates all the new packets. diff --git a/codegen/burger.json b/codegen/burger.json new file mode 100644 index 00000000..4fa39aa3 --- /dev/null +++ b/codegen/burger.json @@ -0,0 +1 @@ +{"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-the-latest-release"} \ No newline at end of file diff --git a/code-generator/lib/version.py b/codegen/lib/download.py similarity index 69% rename from code-generator/lib/version.py rename to codegen/lib/download.py index f50ab461..284591ab 100644 --- a/code-generator/lib/version.py +++ b/codegen/lib/download.py @@ -1,16 +1,24 @@ -from mappings import Mappings +from .mappings import Mappings import requests import json import os +# make sure the downloads directory exists +if not os.path.exists('downloads'): + os.mkdir('downloads') -def download_burger(): - print('\033[92mDownloading Burger...\033[m') - os.system( - 'cd downloads && git clone https://github.com/pokechu22/Burger && cd Burger && git pull') - print('\033[92mInstalling dependencies...\033[m') - os.system('cd downloads/Burger && pip install six jawa') +def get_burger(): + if not os.path.exists('downloads/Burger'): + with open('burger.json', 'w') as f: + json.dump(requests.get( + 'https://api.github.com/repos/Burger/Burger/releases/latest').json(), f) + print('\033[92mDownloading Burger...\033[m') + os.system( + 'cd downloads && git clone https://github.com/pokechu22/Burger && cd Burger && git pull') + + print('\033[92mInstalling dependencies...\033[m') + os.system('cd downloads/Burger && pip install six jawa') def get_version_manifest(): @@ -49,32 +57,33 @@ def get_client_jar(version_id: str): package_data = get_version_data(version_id) print('\033[92mDownloading client jar...\033[m') client_jar_url = package_data['downloads']['client']['url'] - with open('client.jar', 'wb') as f: + with open(f'downloads/client-{version_id}.jar', 'wb') as f: f.write(requests.get(client_jar_url).content) def get_burger_data_for_version(version_id: str): if not os.path.exists(f'downloads/burger-{version_id}.json'): + get_burger() get_client_jar(version_id) os.system( f'cd downloads/Burger && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json' ) - with open(f'burger-{version_id}.json', 'r') as f: + with open(f'downloads/burger-{version_id}.json', 'r') as f: return json.load(f) def get_mappings_for_version(version_id: str): - if not os.path.exists(f'downloads/mappings-{version_id}.json'): + if not os.path.exists(f'downloads/mappings-{version_id}.txt'): package_data = get_version_data(version_id) client_mappings_url = package_data['downloads']['client_mappings']['url'] mappings_text = requests.get(client_mappings_url).text - with open(f'downloads/mappings-{version_id}.json', 'w') as f: + with open(f'downloads/mappings-{version_id}.txt', 'w') as f: f.write(mappings_text) else: - with open(f'downloads/mappings-{version_id}.json', 'r') as f: + with open(f'downloads/mappings-{version_id}.txt', 'r') as f: mappings_text = f.read() return Mappings.parse(mappings_text) diff --git a/code-generator/lib/mappings.py b/codegen/lib/mappings.py similarity index 100% rename from code-generator/lib/mappings.py rename to codegen/lib/mappings.py diff --git a/code-generator/lib/packetcodegen.py b/codegen/lib/packetcodegen.py similarity index 98% rename from code-generator/lib/packetcodegen.py rename to codegen/lib/packetcodegen.py index 3d453a4e..b4c6a83b 100644 --- a/code-generator/lib/packetcodegen.py +++ b/codegen/lib/packetcodegen.py @@ -1,6 +1,5 @@ -from utils import to_snake_case, to_camel_case -from mappings import Mappings -import os +from .utils import to_snake_case, to_camel_case +from .mappings import Mappings def burger_type_to_rust_type(burger_type): diff --git a/code-generator/lib/utils.py b/codegen/lib/utils.py similarity index 100% rename from code-generator/lib/utils.py rename to codegen/lib/utils.py diff --git a/code-generator/main.py b/codegen/newpacket.py similarity index 69% rename from code-generator/main.py rename to codegen/newpacket.py index 54ad3946..f4dc172e 100644 --- a/code-generator/main.py +++ b/codegen/newpacket.py @@ -1,11 +1,9 @@ -from .lib import version, packetcodegen -import requests -import json +from lib import download, packetcodegen # type: ignore import sys import os -mappings = version.get_mappings_for_version('1.18.2') -burger_data = version.get_burger_data_for_version('1.18.2') +mappings = download.get_mappings_for_version('1.18.2') +burger_data = download.get_burger_data_for_version('1.18.2') burger_packets_data = burger_data[0]['packets']['packet'] packet_id, direction, state = int(sys.argv[1]), sys.argv[2], sys.argv[3]