Last active
April 8, 2021 08:58
-
-
Save Iltotore/62e12babb64dfda9179a1b4a451c76c6 to your computer and use it in GitHub Desktop.
Shader fix: Excluding dimension (notably for Galacticraft) - Usage: `py shaderfix.py -i <shader> (-z for zip files) (-dims for specific dimensions. Default are GC's dims)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import zipfile | |
class Shaderpack: | |
def __init__(self, path): | |
self.path = path | |
def __enter__(self): | |
return self | |
def __exit__(self, *args): | |
pass | |
def mkdir(self, name): | |
raise RuntimeError("Not implemented") | |
class ShaderDirectory(Shaderpack): | |
def mkdir(self, name): | |
os.mkdir(f"{self.path}/{name}") | |
class ShaderZip(Shaderpack): | |
def __init__(self, path): | |
super().__init__(path) | |
self.opened_file = None | |
def __enter__(self): | |
self.opened_file = zipfile.ZipFile(self.path, mode="a") | |
return self | |
def __exit__(self, *args): | |
if self.opened_file is not None: | |
self.opened_file.close() | |
def mkdir(self, name): | |
info = zipfile.ZipInfo(name) | |
self.opened_file.writestr(info, "") | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-i", required=True, help="Input file") | |
parser.add_argument("-z", action="store_true") | |
parser.add_argument("-d", required=False, | |
help="Comma-separated dimensions (default are Galacticraft's and ExtraPlanets')", | |
default="-28,-27,-26,102,103,104,105,-1505,-20,-65,-64,-1503,-21,-79,-78,-1501,-1506,-1511,-1500,-15,-69,-68,-22,-81,-80,-67,-66,-13,-61,-60,-18,-75,-74,-1509,-1502,-19,-77,-76,-1507,-16,-71,-70,-1508,-1510,-1504,-17,-73,-72,-63,-62") | |
args = parser.parse_args() | |
i = args.i | |
zip_mode = args.z | |
dims = args.d.split(",") | |
if zip_mode: | |
print("Zip mode enabled") | |
print("Opening", i) | |
with (ShaderZip(i) if zip_mode else ShaderDirectory(i)) as pack: | |
print(pack) | |
for dim in dims: | |
print("Excluding dimension", dim) | |
pack.mkdir(f"shaders/{dim}/") | |
print("Finishing...") | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment