mirror of
https://github.com/TeamMidnightDust/BetterLeavesLite.git
synced 2025-12-14 19:55:08 +01:00
Add mod compatibility and edge-case handling
Why does every mod have to do things differently :((
This commit is contained in:
128
gen-pack.py
128
gen-pack.py
@@ -11,7 +11,12 @@ import shutil
|
||||
from PIL import Image
|
||||
from distutils.dir_util import copy_tree
|
||||
|
||||
def autoGen(notint_overrides):
|
||||
def autoGen(jsonData):
|
||||
notint_overrides = jsonData["noTint"]
|
||||
block_texture_overrides = jsonData["blockTextures"]
|
||||
overlay_textures = jsonData["overlayTextures"]
|
||||
block_id_overrides = jsonData["blockIds"]
|
||||
leaves_with_carpet = jsonData["leavesWithCarpet"]
|
||||
print("Generating assets...")
|
||||
if (os.path.exists("./assets")): shutil.rmtree("./assets")
|
||||
copy_tree("./base/assets/", "./assets/")
|
||||
@@ -20,8 +25,14 @@ def autoGen(notint_overrides):
|
||||
for infile in files:
|
||||
if infile.endswith(".png") and (len(root.split("/")) > 3):
|
||||
namespace = root.split("/")[3]
|
||||
block_id = infile.replace(".png", "")
|
||||
print(namespace+":"+block_id)
|
||||
block_name = infile.replace(".png", "")
|
||||
if (namespace+":block/"+block_name) in overlay_textures.values(): continue # We don't want to generate assets for overlay textures
|
||||
|
||||
print(namespace+":"+block_name)
|
||||
texture_prefix = ""
|
||||
if (len(root.split("/")) > 6):
|
||||
texture_prefix = root.split("/")[6]+"/"
|
||||
print("-> Prefix: "+ texture_prefix);
|
||||
|
||||
# Generate textures
|
||||
outfolder = root.replace("assets", "").replace("input", "assets")
|
||||
@@ -50,17 +61,49 @@ def autoGen(notint_overrides):
|
||||
except IOError:
|
||||
print("Error while generating texture for '%s'" % infile)
|
||||
|
||||
# Generate blockstates & models
|
||||
# Set block id and apply overrides
|
||||
block_id = namespace+":"+block_name
|
||||
if block_id in block_id_overrides:
|
||||
block_id = block_id_overrides[block_id]
|
||||
|
||||
# Set texture id and apply overrides
|
||||
texture_id = namespace+":block/"+block_name
|
||||
|
||||
has_texture_override = (block_id) in block_texture_overrides
|
||||
if has_texture_override:
|
||||
texture_id = block_texture_overrides[block_id]
|
||||
print ("-> Texture Override: "+texture_id)
|
||||
else:
|
||||
if (texture_prefix != ""):
|
||||
texture_id = namespace+":block/"+texture_prefix+block_name
|
||||
|
||||
base_model = "leaves"
|
||||
|
||||
# Check if the block appears in the notint overrides
|
||||
if (namespace+":"+block_id) in notint_overrides:
|
||||
generateBlockstateAndModel(namespace, block_id, True)
|
||||
generateItemModel(namespace, block_id)
|
||||
hasNoTint = block_id in notint_overrides
|
||||
if hasNoTint:
|
||||
base_model = "leaves_notint"
|
||||
print ("-> No tint")
|
||||
else:
|
||||
generateBlockstateAndModel(namespace, block_id, False)
|
||||
|
||||
def generateBlockstateAndModel(mod_namespace, block_name, notint):
|
||||
# Check if the block has an additional overlay texture
|
||||
overlay_texture_id = ""
|
||||
if block_id in overlay_textures:
|
||||
base_model = "leaves_overlay"
|
||||
overlay_texture_id = overlay_textures[block_id]
|
||||
print ("-> Has overlay texture: "+overlay_texture_id)
|
||||
|
||||
# Generate blockstates & models
|
||||
generateBlockstateAndModel(block_id, base_model, texture_id, overlay_texture_id)
|
||||
generateItemModel(block_id, has_texture_override)
|
||||
|
||||
if (block_id) in leaves_with_carpet:
|
||||
carpet_id = leaves_with_carpet[block_id]
|
||||
generateCarpetAssets(carpet_id, hasNoTint, texture_id)
|
||||
print (f"-> Also generating leaf carpet: {carpet_id}")
|
||||
|
||||
def generateBlockstateAndModel(block_id, base_model, texture_id, overlay_texture_id):
|
||||
mod_namespace = block_id.split(":")[0]
|
||||
block_name = block_id.split(":")[1]
|
||||
|
||||
# Create structure for blockstate file
|
||||
block_state_file = f"assets/{mod_namespace}/blockstates/{block_name}.json"
|
||||
@@ -86,34 +129,79 @@ def generateBlockstateAndModel(mod_namespace, block_name, notint):
|
||||
if not os.path.exists("assets/{}/models/block/".format(mod_namespace)):
|
||||
os.makedirs("assets/{}/models/block/".format(mod_namespace))
|
||||
|
||||
base_model = "leaves"
|
||||
if (notint):
|
||||
base_model = "leaves_notint"
|
||||
# Create the four individual leaf models
|
||||
for i in range(1, 5):
|
||||
# Create structure for block model file
|
||||
block_model_file = f"assets/{mod_namespace}/models/block/{block_name}{i}.json"
|
||||
block_model_data = {
|
||||
"parent": f"block/{base_model}{i}",
|
||||
"parent": f"betterleaves:block/{base_model}{i}",
|
||||
"textures": {
|
||||
"all": f"{mod_namespace}:block/{block_name}"
|
||||
"all": f"{texture_id}"
|
||||
}
|
||||
}
|
||||
if (overlay_texture_id != ""):
|
||||
block_model_data["textures"]["overlay"] = overlay_texture_id
|
||||
with open(block_model_file, "w") as f:
|
||||
json.dump(block_model_data, f, indent=4)
|
||||
|
||||
def generateItemModel(mod_namespace, block_name):
|
||||
def generateItemModel(block_id, override_block_texture=False):
|
||||
mod_namespace = block_id.split(":")[0]
|
||||
block_name = block_id.split(":")[1]
|
||||
|
||||
# Create models folder if it doesn't exist already
|
||||
if not os.path.exists("assets/{}/models/item/".format(mod_namespace)):
|
||||
os.makedirs("assets/{}/models/item/".format(mod_namespace))
|
||||
|
||||
item_model_file = f"assets/{mod_namespace}/models/item/{block_name}.json"
|
||||
item_model_data = {
|
||||
"parent": f"{mod_namespace}:block/{block_name}1"
|
||||
}
|
||||
|
||||
if override_block_texture: # Used for items that have a different texture than the block model
|
||||
item_model_data = {
|
||||
"parent": f"{mod_namespace}:block/{block_name}1",
|
||||
"textures": {
|
||||
"all": f"{mod_namespace}:block/{block_name}"
|
||||
}
|
||||
}
|
||||
else: # By default, the regular block model is used
|
||||
item_model_data = {
|
||||
"parent": f"{mod_namespace}:block/{block_name}1"
|
||||
}
|
||||
|
||||
with open(item_model_file, "w") as f:
|
||||
json.dump(item_model_data, f, indent=4)
|
||||
|
||||
def generateCarpetAssets(carpet_id, notint, texture_id):
|
||||
mod_namespace = carpet_id.split(":")[0]
|
||||
block_name = carpet_id.split(":")[1]
|
||||
|
||||
# Create structure for blockstate file
|
||||
block_state_file = f"assets/{mod_namespace}/blockstates/{block_name}.json"
|
||||
block_state_data = {
|
||||
"variants": {
|
||||
"": []
|
||||
}
|
||||
}
|
||||
# Add four rotations for the carpet model
|
||||
block_state_data["variants"][""] += { "model": f"{mod_namespace}:block/{block_name}" }, { "model": f"{mod_namespace}:block/{block_name}", "y": 90 }, { "model": f"{mod_namespace}:block/{block_name}", "y": 180 }, { "model": f"{mod_namespace}:block/{block_name}", "y": 270 },
|
||||
|
||||
# Write blockstate file
|
||||
with open(block_state_file, "w") as f:
|
||||
json.dump(block_state_data, f, indent=4)
|
||||
|
||||
base_model = "leaf_carpet"
|
||||
if (notint):
|
||||
base_model = "leaf_carpet_notint"
|
||||
|
||||
# Create structure for block model file
|
||||
block_model_file = f"assets/{mod_namespace}/models/block/{block_name}.json"
|
||||
block_model_data = {
|
||||
"parent": f"betterleaves:block/{base_model}",
|
||||
"textures": {
|
||||
"wool": f"{texture_id}"
|
||||
}
|
||||
}
|
||||
with open(block_model_file, "w") as f:
|
||||
json.dump(block_model_data, f, indent=4)
|
||||
|
||||
# See https://stackoverflow.com/a/1855118
|
||||
def zipdir(path, ziph):
|
||||
# ziph is zipfile handle
|
||||
@@ -150,6 +238,6 @@ if __name__ == '__main__':
|
||||
data = json.load(f)
|
||||
f.close()
|
||||
|
||||
autoGen(data['noTint']);
|
||||
autoGen(data);
|
||||
makeZip(args.version);
|
||||
|
||||
Reference in New Issue
Block a user