diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..158b57f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +venv +.replit +replit.nix +.idea \ No newline at end of file diff --git a/CMD Converter+/FolderConveter.py b/CMD Converter+/FolderConveter.py deleted file mode 100644 index 2ee4e66..0000000 --- a/CMD Converter+/FolderConveter.py +++ /dev/null @@ -1,63 +0,0 @@ -#Convert Old Bedrock 1.18 and lower /execute commands to New Bedrock 1.19+ -#Made by L0VE MC aka Love#1000 -#Published by Odin Network -import os - -def fix_t_format(command): - command = command.replace("~ ~ ~", "~~~") - command = command.replace("~ ~~", "~~~") - command = command.replace("~~ ~", "~~~") - return command - -def translate(command): - command = command.replace("execute @p","execute as @p") - command = command.replace("execute @a","execute as @a") - command = command.replace("execute @r","execute as @r") - command = command.replace("execute @e","execute as @e") - command = command.replace("execute @s","execute as @s") - command = command.replace("~~~","at @s run") - return command - -def main(command): - command = fix_t_format(command) - command = translate(command) - return(command) - -def show(total_converted, total_not, err_lines, file, line_count): - print(f"----------------\n{file} was converted.\nExecute Commands: {total_converted}\nSkipped Lines: {total_not}\nTotal Lines: {line_count}\n") - if err_lines != []: - print(f"Check lines {err_lines} for errors (/fills, /particles and /summons can bug out sometimes)\n") - -path_of_the_directory= '.\old' - -for filename in os.listdir(path_of_the_directory): - f = os.path.join(path_of_the_directory,filename) - if os.path.isfile(f): - filename=f.replace(".\old\\","") - f = f.replace(".\old\\","") - if ".mcfunction" in f: - with open(f'.\\new\\{f}', 'w') as file: - with open(f'.\old\\{f}', 'r') as f: - exe_commands = 0 - non_exe = 0 - line_count = 0 - error_lines = [] - for line in f: - line_count += 1 - if 'execute' in line: - exe_commands += 1 - file.write(main(line)) - if "fill" in line: - error_lines += [f"{str(line_count)}"] - if "summon" in line: - error_lines += [f"{str(line_count)}"] - if "particle" in line: - error_lines += [f"{str(line_count)}"] - else: - non_exe += 1 - file.write(line) - show(exe_commands,non_exe,error_lines,filename,line_count) - else: - print(f"\n{f} was skipped because it is not a .mcfunction\n") - -close = input("----------------\nType anything to close...") diff --git a/CMD Converter+/new/test1.mcfunction b/CMD Converter+/new/test1.mcfunction deleted file mode 100644 index d3a168f..0000000 --- a/CMD Converter+/new/test1.mcfunction +++ /dev/null @@ -1,5 +0,0 @@ -#test 1 -execute as @a at @s run effect @s haste 10 10 true -execute as @r at @s run say hello -execute as @a at @s run summon test at @s run -execute as @r at @s run fill at @s run \ No newline at end of file diff --git a/CMD Converter+/new/test2.mcfunction b/CMD Converter+/new/test2.mcfunction deleted file mode 100644 index dfe7312..0000000 --- a/CMD Converter+/new/test2.mcfunction +++ /dev/null @@ -1,4 +0,0 @@ -#test 2 -execute as @a at @s run effect @s haste 10 10 true -execute as @r at @s run say hello -#execute test \ No newline at end of file diff --git a/CMD Converter+/new/test3.mcfunction b/CMD Converter+/new/test3.mcfunction deleted file mode 100644 index 4624247..0000000 --- a/CMD Converter+/new/test3.mcfunction +++ /dev/null @@ -1,3 +0,0 @@ -#test 3 -execute as @a at @s run effect @s haste 10 15 -execute as @r at @s run say hello \ No newline at end of file diff --git a/CMD Converter+/old/placeholdder.txt b/CMD Converter+/old/placeholdder.txt deleted file mode 100644 index e69de29..0000000 diff --git a/CMD Converter+/old/test1.mcfunction b/CMD Converter+/old/test1.mcfunction deleted file mode 100644 index 1d3384f..0000000 --- a/CMD Converter+/old/test1.mcfunction +++ /dev/null @@ -1,5 +0,0 @@ -#test 1 -execute @a ~ ~ ~ effect @s haste 10 10 true -execute @r ~ ~ ~ say hello -execute @a ~ ~ ~ summon test ~ ~ ~ -execute @r ~ ~ ~ fill ~ ~ ~ \ No newline at end of file diff --git a/CMD Converter+/old/test2.mcfunction b/CMD Converter+/old/test2.mcfunction deleted file mode 100644 index 469172e..0000000 --- a/CMD Converter+/old/test2.mcfunction +++ /dev/null @@ -1,4 +0,0 @@ -#test 2 -execute @a ~ ~ ~ effect @s haste 10 10 true -execute @r ~ ~ ~ say hello -#execute test \ No newline at end of file diff --git a/CMD Converter+/old/test3.mcfunction b/CMD Converter+/old/test3.mcfunction deleted file mode 100644 index c972679..0000000 --- a/CMD Converter+/old/test3.mcfunction +++ /dev/null @@ -1,3 +0,0 @@ -#test 3 -execute @a ~ ~ ~ effect @s haste 10 15 -execute @r ~ ~ ~ say hello \ No newline at end of file diff --git a/CMD Converter/CommandConverter.exe b/CMD Converter/CommandConverter.exe deleted file mode 100644 index f2bf631..0000000 Binary files a/CMD Converter/CommandConverter.exe and /dev/null differ diff --git a/CMD Converter/SourceCode.py b/CMD Converter/SourceCode.py deleted file mode 100644 index ed85044..0000000 --- a/CMD Converter/SourceCode.py +++ /dev/null @@ -1,53 +0,0 @@ -#Convert Old Bedrock 1.18 and lower /execute commands to New Bedrock 1.19+ -#Made by L0VE MC aka Love#1000 -#Published by Odin Network - -def fix_t_format(command): #Formats ~'s - command = command.replace("~ ~ ~", "~~~") - command = command.replace("~ ~~", "~~~") - command = command.replace("~~ ~", "~~~") - return command - -def translate(command): #Translates to 1.19 execute commands - command = command.replace("execute @p","execute as @p") - command = command.replace("execute @a","execute as @a") - command = command.replace("execute @r","execute as @r") - command = command.replace("execute @e","execute as @e") - command = command.replace("execute @s","execute as @s") - command = command.replace("~~~","at @s run") - return command - -def main(command): #Fixes the format then runs the translate function - command = fix_t_format(command) - command = translate(command) - return(command) - -with open('new_commands.txt', 'w') as file: #Opens the new command file - with open('old_commands.txt', 'r') as f: #Opens the old command file - exe_commands = 0 - non_exe = 0 #Setting some vars for output and debugging - line_count = 0 - error_lines = [] - for line in f: #Loops through the lines in the old command file - line_count += 1 - if 'execute' in line: #Checks if the commands is a /execute command - exe_commands += 1 - file.write(main(line)) #Writes the formatted line to the new commands file - if "fill" in line: #Checks if the command is a /fill or /summon - error_lines += [f"{str(line_count)}"] #Lets the person know there could be an error - if "summon" in line: #Checks if the command is a /fill or /summon - error_lines += [f"{str(line_count)}"] #Lets the person know there could be an error - else: - non_exe += 1 - file.write(line) #Writes the same command line because its not a /execute command - -print(""" -░██╗░░░░░░░██╗░█████╗░░█████╗░░██████╗██╗░░██╗██╗ -░██║░░██╗░░██║██╔══██╗██╔══██╗██╔════╝██║░░██║██║ -░╚██╗████╗██╔╝██║░░██║██║░░██║╚█████╗░███████║██║ -░░████╔═████║░██║░░██║██║░░██║░╚═══██╗██╔══██║╚═╝ -░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝██████╔╝██║░░██║██╗ -░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░╚═════╝░╚═╝░░╚═╝╚═╝ -""") #Whoosh! - -close = input(f"Converted: {exe_commands}\nSkipped Lines: {non_exe}\nCheck lines {error_lines} for errors (/fills and /summons can bug out sometimes)") #Prints data to user \ No newline at end of file diff --git a/CMD Converter/new_commands.txt b/CMD Converter/new_commands.txt deleted file mode 100644 index 985b16b..0000000 --- a/CMD Converter/new_commands.txt +++ /dev/null @@ -1 +0,0 @@ -#New commands will appear here \ No newline at end of file diff --git a/CMD Converter/old_commands.txt b/CMD Converter/old_commands.txt deleted file mode 100644 index c99b933..0000000 --- a/CMD Converter/old_commands.txt +++ /dev/null @@ -1 +0,0 @@ -#Paste your functions here (you can remove this line) \ No newline at end of file diff --git a/README.md b/README.md index 134a98b..1e69e38 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ -# Execute-Command-Converter -Converts commands from old Minecraft bedrock versions to the new (java) format. -Just paste your function into the old_commands.txt and then run the exe or python file. +# Bedrock Command Converter +This is a Python script that converts Bedrock Edition commands from version 1.18 and lower to version 1.19. + +## Features +The script supports the following Bedrock commands and features: + +* **execute** commands +* **detect** commands +* **fill**, **summon**, and other similar commands + +The script can also handle **`execute`** commands with positions other than the triple tilde (`~~~`) and can format positions for consistent spacing. + +## Usage +1. Clone the repository to your local machine or download the script files. +2. Place the Bedrock command files you want to convert in the **`old`** directory. +3. Run the script by running the converter.py file. The converted files will be generated in the **`new`** directory. +4. The converted files will have the same name as the original files. diff --git a/converter.py b/converter.py new file mode 100644 index 0000000..50c0de4 --- /dev/null +++ b/converter.py @@ -0,0 +1,117 @@ +# Convert Old Bedrock 1.18 and lower /execute commands to New Bedrock 1.19 +# Made by L0VE MC aka Love#1000 +# Published by Odin Network + +import os + +## CONSTANTS ### +SOURCE_DIRECTORY_PATH = "./old" +OUT_DIRECTORY_PATH = "./new" + + +def convert_selector(command: str) -> list[str]: + """ + Converts /execute commands that use player selectors to the new selector syntax. + + Args: + command (str): The command to convert. + + Returns: + str: The tokens of the converted command. + """ + return command.replace("execute @p", "execute as @p") \ + .replace("execute @a", "execute as @a") \ + .replace("execute @r", "execute as @r") \ + .replace("execute @e", "execute as @e") \ + .replace("execute @s", "execute as @s").split() + + +def format_command(command: str) -> list[str]: + """ + Formats the position (x, y, z) for consistent spacing. + + Args: + command (str): The command to format. + + Returns: + list[str]: A list of the formatted command's parts. + """ + command_data = convert_selector(command) + + index = 0 + while index < len(command_data): + if '~' in command_data[index] and '~' in command_data[index + 1]: + command_data[index] += command_data[index + 1] + del command_data[index + 1] + elif '~' in command_data[index] and '~' in command_data[index - 1]: + command_data[index - 1] += command_data[index] + del command_data[index] + index += 1 + return command_data + + +def add_run(command_data: list[str], index: int, offset: int) -> None: + """ + Adds the "run" keyword to a command after the execute subcommand. + + Args: + command_data (list[str]): The list of command parts to modify. + index (int): The index of the execute subcommand in the list. + offset (int): The offset from the execute subcommand where the "run" keyword should be added. + """ + index += 1 + while index < len(command_data): + if command_data[index].lstrip('-').isdigit() or '~' in command_data[index]: + index += 1 + else: + break + if not command_data[index] == 'detect': + command_data[index + offset] = 'run ' + command_data[index + offset] + + +def convert(command: str) -> str: + """ + Converts a single /execute command from the old format to the new format. + + Args: + command (str): The command to convert. + + Returns: + str: The converted command. + """ + if not command.startswith('execute'): + return command.rstrip('\n') + command_data = format_command(command) + for index, token in enumerate(command_data): + if token == 'execute' or token == 'run execute': + if command_data[index + 3] == '~~~': + command_data[index + 3] = command_data[index + 3].replace('~~~', 'at @s run') + else: + command_data[index + 3] = 'positioned ' + command_data[index + 3] + add_run(command_data, index + 3, 0) + elif token == 'detect': + command_data[index] = 'if block' + if command_data[index - 1] == 'at @s run': command_data[index - 1] = 'at @s' + add_run(command_data, index, 2) + return " ".join(command_data) + + +def convert_file(source_path: str, out_path: str) -> None: + with open(source_path, "r") as source_file: + with open(out_path, "w") as out_file: + for command in source_file: + converted_command = convert(command) + if converted_command: + out_file.write(converted_command + "\n") + + +def main(): + for file_name in os.listdir(SOURCE_DIRECTORY_PATH): + if not file_name.endswith("mcfunction"): continue + source = os.path.join(SOURCE_DIRECTORY_PATH, file_name) + out = os.path.join(OUT_DIRECTORY_PATH, file_name) + convert_file(source, out) + + +if __name__ == "__main__": + main() diff --git a/new/test.mcfunction b/new/test.mcfunction new file mode 100644 index 0000000..ab1dec3 --- /dev/null +++ b/new/test.mcfunction @@ -0,0 +1,8 @@ +# working +execute as @s at @s run summon armor_stand bobby +execute as @a positioned 12 23 24 run say test with numbers +execute as @s at @s run execute as @a ~12~23~ say hey +execute as @s at @s run detect ~~-1~ air 0 execute as @s ~~~ detect ~~12~ stone -1 say stone +execute as @s at @s run detect ~~-1~ air 0 execute as @s ~~~ detect 23 34 45 stone -1 say new test lol +execute as @a positioned ~~-1~ detect 23 2234 -34 air -1 say air +# testing diff --git a/old/test.mcfunction b/old/test.mcfunction new file mode 100644 index 0000000..451fbc4 --- /dev/null +++ b/old/test.mcfunction @@ -0,0 +1,9 @@ +# working +execute @s ~~~ summon armor_stand bobby +execute @a 12 23 24 say test with numbers +execute @s ~~~ execute @a ~ 12~23 ~ say hey +execute @s ~~~ detect ~~-1~ air 0 execute @s ~ ~ ~ detect ~ ~12 ~ stone -1 say stone +execute @s ~~~ detect ~~-1~ air 0 execute @s ~ ~ ~ detect 23 34 45 stone -1 say new test lol +execute @a ~ ~-1~ detect 23 2234 -34 air -1 say air + +# testing \ No newline at end of file