Skip to content

Instantly share code, notes, and snippets.

@Jummit
Last active April 24, 2022 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jummit/03057cd3597dfb73d92760f3c1d8e612 to your computer and use it in GitHub Desktop.
Save Jummit/03057cd3597dfb73d92760f3c1d8e612 to your computer and use it in GitHub Desktop.
Generate new Fabric/Forge/Quilt/Architectury mod
#!/usr/bin/env python
"""
Script to help create new modding projects.
Execute this inside the template folder and
fill in the form.
"""
import os
def main():
settings = {
"name": "Mod Name",
"id": "Mod Id",
"description": "Mod Description",
"author": "Author",
"license": "License",
"website": "Website",
"package": "Java Package",
}
defaults = {
"id": lambda info: info["name"].replace(" ", "").lower(),
"package": lambda info: "com." + info["author"].lower() + "." + info["id"],
"license": lambda _: "MIT",
}
info = {}
print("Enter mod info, ^C to quit.")
for setting, description in settings.items():
default = ""
if setting in defaults:
default = defaults[setting](info)
description += f" ({default})"
info[setting] = input(description + ": ") or default
replacements = {
"architectury-example-mod": info["name"].lower().replace(" ", "-"),
"example-mod": info["name"].lower().replace(" ", "-"),
"net/examplemod": info["package"].replace(".", "/"),
"Example Mod": info["name"],
"This is an example description! Tell everyone what your mod is about!": info["description"],
"Me!": info["author"],
"Insert License Here": info["license"],
"net.examplemod": info["package"],
"examplemod": info["name"].replace(" ", "").lower(),
"ExampleMod": info["name"].replace(" ", ""),
}
for root, _, files in os.walk("."):
for file in files:
old = os.path.join(root, file)
if old[0:1] == "./":
continue
new = old
for replacement, to in replacements.items():
new = new.replace(replacement, to)
if old != new:
print(f"{old} -> {new}")
os.renames(old, new)
try:
with open(new) as original:
print(f"Replace in {new}:")
old_content = original.read()
new_content = old_content
for what, to in replacements.items():
if what in new_content:
print(f" {what} -> {to}")
new_content = new_content.replace(what, to)
if old_content != new_content:
print(f"Replace in {new}")
with open(new, "w") as modified:
modified.write(new_content)
except UnicodeDecodeError:
print(f"Can't read {new}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment