1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

rename code-generator to codegen

This commit is contained in:
mat 2022-05-24 20:28:08 -05:00
parent 04aea6afaf
commit 0a314bca16
10 changed files with 43 additions and 28 deletions

View file

@ -6,6 +6,9 @@ A Rust crate for creating Minecraft bots.
<img src="https://cdn.matdoes.dev/images/flowering_azalea.webp" alt="Azalea" height="200">
</p>
<!-- The line below is automatically read and updated by the migrate script, so don't change it manually. -->
*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

View file

@ -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\]`

13
codegen/README.md Normal file
View file

@ -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.

1
codegen/burger.json Normal file
View file

@ -0,0 +1 @@
{"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-the-latest-release"}

View file

@ -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)

View file

@ -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):

View file

@ -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]