Skip to content

Instantly share code, notes, and snippets.

@onnowhere
Last active November 12, 2020 10:03
Show Gist options
  • Save onnowhere/66c439cf7088d370827c374a68033ed1 to your computer and use it in GitHub Desktop.
Save onnowhere/66c439cf7088d370827c374a68033ed1 to your computer and use it in GitHub Desktop.
Converts /replaceitem to 1.17 /item format. Put in datapack root folder and run. Searches all mcfunction files inside ./data/*
import os
import re
def convert_replaceitem(fread):
changed = False
for i,command in enumerate(fread):
if command.startswith("replaceitem"):
# Regex credit to Dieuwt on the MinecraftCommands Discord
fread[i] = re.sub(r'replaceitem (entity @.[^[]*? .*? |entity @.\[.*?\] .*? |block (.*? ){4})', r'item \1replace ', command)
changed = True
return fread, changed
for root, subdirs, files in os.walk("./data"):
for file in files:
filepath = os.path.join(root, file)
if os.path.splitext(filepath)[-1] == ".mcfunction":
with open(filepath, 'r') as f:
fread = f.readlines()
gread, changed = convert_replaceitem(fread)
if changed:
with open(filepath, 'w') as g:
g.write("".join(gread))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment