-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
306 changed files
with
1,879 additions
and
5,686 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.datapack | ||
build/__pycache__ | ||
*.pyc |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generates the item models which are used as the base for all hats. | ||
# Each model is overwritten with custom hat models depending on the items custom model data. | ||
|
||
import yaml, json | ||
from registry import Registry, Hat | ||
|
||
def minecraft_item_model_overwrite(custom_model_data, model_path): | ||
""" Creates a custom model overwrite for minecraft item models """ | ||
return { "predicate": { "custom_model_data": custom_model_data }, "model": model_path } | ||
|
||
registry = Registry() | ||
hats = list(registry.all_hats()) | ||
overrides = [minecraft_item_model_overwrite(hat.custom_model_data, hat.model_path) for hat in hats] | ||
|
||
for key, item_model in registry.overwritten_item_models.items(): | ||
item_model.model["overrides"] = overrides | ||
with open(item_model.path, "w+") as file: | ||
json.dump(item_model.model, file, separators=(',', ':')) |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import json, os | ||
from registry import Registry, Hat | ||
|
||
def hat_loot_table(hat, base_item): | ||
if hat.category == "*": | ||
translation = f"{hat.name}" | ||
else: | ||
translation = f"{hat.category}.{hat.name}" | ||
|
||
functions = [ | ||
{ | ||
"function": "minecraft:set_name", | ||
"name": { | ||
"translate": f"item.hats.{translation}.name" | ||
} | ||
}, | ||
{ | ||
"function": "set_nbt", | ||
"tag": f'{{CustomModelData:{hat.custom_model_data}, Tags:["is_hat", "hats.hat", "{hat.type}"]}}' | ||
} | ||
] | ||
|
||
# Add lore lines if any exist | ||
if hat.lore: | ||
lines = [{"translate": f"{line}"} for line in hat.lore] | ||
functions.append({ | ||
"function": "minecraft:set_lore", | ||
"lore": lines | ||
}) | ||
|
||
return { | ||
"type": "minecraft:generic", | ||
"pools": [ | ||
{ | ||
"functions": functions, | ||
"rolls": 1, | ||
"entries": [ | ||
{ | ||
"type": "tag", | ||
"name": base_item, | ||
"expand": True | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
registry = Registry() | ||
hats = list(registry.all_hats()) | ||
|
||
for hat in hats: | ||
if hat.category == "*": | ||
rel_path = f"{hat.name}" | ||
else: | ||
rel_path = f"{hat.category}/{hat.name}" | ||
|
||
hat_loot_table_path = f"datapack/data/hats/loot_tables/hat/{rel_path}.json" | ||
with open(hat_loot_table_path, "w+") as file: | ||
json.dump(hat_loot_table(hat, "hats:hat"), file, separators=(',', ':')) | ||
|
||
hat_on_head_loot_table_path = f"datapack/data/hats/loot_tables/hat_on_head/{rel_path}.json" | ||
with open(hat_on_head_loot_table_path, "w+") as file: | ||
json.dump(hat_loot_table(hat, "hats:hat_on_head"), file, separators=(',', ':')) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os, json | ||
from registry import Registry, Hat | ||
|
||
def generate_loot_table_all_for_category(category_name, category_hats, subfolder): | ||
pools = [] | ||
for hat in category_hats: | ||
if hat.category == "*": | ||
rel_path = f"{hat.name}" | ||
else: | ||
rel_path = f"{hat.category}/{hat.name}" | ||
|
||
hat_pool = { | ||
"rolls": 1, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:loot_table", | ||
"name": f"hats:{subfolder}/{rel_path}" | ||
} | ||
] | ||
} | ||
pools.append(hat_pool) | ||
|
||
loot_table_all = { | ||
"type": "minecraft:generic", | ||
"pools": pools | ||
} | ||
|
||
loot_table_all_path = f"datapack/data/hats/loot_tables/{subfolder}/{category_name}/_all.json" | ||
parent_dir = os.path.split(loot_table_all_path)[0] | ||
if not os.path.exists(parent_dir): | ||
os.makedirs(parent_dir) | ||
|
||
with open(loot_table_all_path, "w+") as file: | ||
json.dump(loot_table_all, file) | ||
|
||
def generate_loot_table_rand_for_category(category_name, category_hats, subfolder): | ||
entries = [] | ||
for hat in category_hats: | ||
if hat.category == "*": | ||
rel_path = f"{hat.name}" | ||
else: | ||
rel_path = f"{hat.category}/{hat.name}" | ||
|
||
hat_entry = { | ||
"type": "minecraft:loot_table", | ||
"name": f"hats:{subfolder}/{rel_path}" | ||
} | ||
|
||
entries.append(hat_entry) | ||
|
||
loot_table_rand = { | ||
"type": "minecraft:generic", | ||
"pools": [ | ||
{ | ||
"rolls": 1, | ||
"entries": entries | ||
} | ||
] | ||
} | ||
|
||
loot_table_rand_path = f"datapack/data/hats/loot_tables/{subfolder}/{category_name}/_rand.json" | ||
parent_dir = os.path.split(loot_table_rand_path)[0] | ||
if not os.path.exists(parent_dir): | ||
os.makedirs(parent_dir) | ||
|
||
with open(loot_table_rand_path, "w+") as file: | ||
json.dump(loot_table_rand, file) | ||
|
||
registry = Registry() | ||
|
||
for category_name, category_hats in registry.categories(): | ||
if category_name != "*": | ||
generate_loot_table_all_for_category(category_name, category_hats, 'hat') | ||
generate_loot_table_rand_for_category(category_name, category_hats, 'hat') | ||
|
||
if category_name == 'cats' or category_name == 'villager': | ||
generate_loot_table_rand_for_category(category_name, category_hats, 'hat_on_head') |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
|
||
def get_functions(root): | ||
for root, dirs, files in os.walk(root): | ||
for file in files: | ||
_, extension = os.path.splitext(file) | ||
if extension == '.mcfunction': | ||
yield os.path.join(root, file) | ||
|
||
for function in get_functions('datapack/data/hats/functions'): | ||
print(function) | ||
lines = open(function).readlines() | ||
lines = filter(lambda l: not l.strip().startswith('#'), lines) # Remove comments | ||
lines = filter(lambda l: l.strip(), lines) # Remove blank lines | ||
lines = map(lambda l: l.lstrip(), lines) # Remove whitespace | ||
|
||
open(function, 'w').writelines(lines) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os, json | ||
from itertools import chain | ||
|
||
def get_json_files(root): | ||
for root, dirs, files in os.walk(root): | ||
for file in files: | ||
_, extension = os.path.splitext(file) | ||
if extension == '.json': | ||
yield os.path.join(root, file) | ||
|
||
for json_file in chain(get_json_files('datapack'), get_json_files('resourcepack')): | ||
content = {} | ||
with open(json_file) as file: | ||
content = json.load(file) | ||
|
||
with open(json_file, 'w') as file: | ||
json.dump(content, file, separators=[',', ':']) |
Oops, something went wrong.