Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv
.replit
replit.nix
.idea
63 changes: 0 additions & 63 deletions CMD Converter+/FolderConveter.py

This file was deleted.

5 changes: 0 additions & 5 deletions CMD Converter+/new/test1.mcfunction

This file was deleted.

4 changes: 0 additions & 4 deletions CMD Converter+/new/test2.mcfunction

This file was deleted.

3 changes: 0 additions & 3 deletions CMD Converter+/new/test3.mcfunction

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions CMD Converter+/old/test1.mcfunction

This file was deleted.

4 changes: 0 additions & 4 deletions CMD Converter+/old/test2.mcfunction

This file was deleted.

3 changes: 0 additions & 3 deletions CMD Converter+/old/test3.mcfunction

This file was deleted.

Binary file removed CMD Converter/CommandConverter.exe
Binary file not shown.
53 changes: 0 additions & 53 deletions CMD Converter/SourceCode.py

This file was deleted.

1 change: 0 additions & 1 deletion CMD Converter/new_commands.txt

This file was deleted.

1 change: 0 additions & 1 deletion CMD Converter/old_commands.txt

This file was deleted.

20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
117 changes: 117 additions & 0 deletions converter.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions new/test.mcfunction
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions old/test.mcfunction
Original file line number Diff line number Diff line change
@@ -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