Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeUtan committed May 27, 2020
2 parents 4639ad3 + ab0ecd1 commit f3b131e
Show file tree
Hide file tree
Showing 306 changed files with 1,879 additions and 5,686 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.datapack
build/__pycache__
*.pyc
34 changes: 0 additions & 34 deletions build/datapack_utils.py

This file was deleted.

18 changes: 18 additions & 0 deletions build/generate_base_item_models.py
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=(',', ':'))
34 changes: 0 additions & 34 deletions build/generate_fix_hat.py

This file was deleted.

63 changes: 63 additions & 0 deletions build/generate_hat_loot_tables.py
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=(',', ':'))
77 changes: 77 additions & 0 deletions build/generate_special_hat_loot_tables.py
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')
67 changes: 0 additions & 67 deletions build/loot_table.py

This file was deleted.

17 changes: 17 additions & 0 deletions build/minify_functions.py
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)
17 changes: 17 additions & 0 deletions build/minify_json_files.py
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=[',', ':'])
Loading

0 comments on commit f3b131e

Please sign in to comment.