Skip to content

Commit

Permalink
feat: version 1.21 rc1 + item showcase build automation
Browse files Browse the repository at this point in the history
  • Loading branch information
atomic-junky committed Jun 11, 2024
1 parent 0bc0dfd commit 153aff1
Show file tree
Hide file tree
Showing 89 changed files with 228 additions and 48 deletions.
Binary file added docs/_media/assets/ui_displayer_footer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_media/assets/ui_displayer_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_media/assets/ui_displayer_slots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_media/showcase/item_showcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions docs/_scripts/build_item_showcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import glob
import math

from PIL import Image


UI_HEADER = Image.open("../_media/assets/ui_displayer_header.png", "RGBA")
UI_SLOTS = Image.open("../_media/assets/ui_displayer_slots.png", "RGBA")
UI_FOOTER = Image.open("../_media/assets/ui_displayer_footer.png", "RGBA")
ITEMS_LOCATION = "../../tasty_supplies/src/assets/tasty_supplies/textures/item/*.png"

item_textures = []


def main():
_load_item_textures()
im = _build_displayer()
im = _append_items(im)

new_size = tuple(i * 3 for i in im.size)
im = im.resize(new_size, Image.Resampling.NEAREST)

im.save("../_media/showcase/item_showcase.png")


def _load_item_textures():
paths = glob.glob(ITEMS_LOCATION)
paths.sort()

for path in paths:
texture = Image.open(path)
item_textures.append(texture)


def _build_displayer():
col = 9
raw = math.ceil(len(item_textures)/col)

header_size = UI_HEADER.size
slots_size = UI_SLOTS.size
footer_size = UI_FOOTER.size

im_height = header_size[1] + (slots_size[1]*raw) + footer_size[1]
im = Image.new("RGBA", (header_size[0], im_height), (0, 0, 0))

Image.Image.paste(im, UI_HEADER, (0, 0))

for r in range(raw):
Image.Image.paste(im, UI_SLOTS, (
0, header_size[1] + slots_size[1]*r
))

Image.Image.paste(im, UI_FOOTER, (0, im_height-footer_size[1]))

return im


def _append_items(im):
padding = (7, UI_HEADER.size[1])

for texture in item_textures:
index = item_textures.index(texture)
raw = math.floor(index/9)
col = index - raw*9

mask = _create_a_mask(texture)

im.paste(texture, (
padding[0] + col*(16+1) + col+1,
padding[1] + raw*(16+1) + raw+1
), mask)

return im


def _create_a_mask(im: Image):
return im.convert('LA')


if __name__ == '__main__':
main()
132 changes: 132 additions & 0 deletions docs/_scripts/build_recipes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import glob
import io
import math
import json
import requests

from PIL import Image


CRAFTING_TABLE_BG = Image.open("../_media/recipes/blank_recipes/blank_crafting_table_recipe.png").convert("RGBA")
FURNACE_TABLE_BG = Image.open("../_media/recipes/blank_recipes/blank_furnace_recipe.png").convert("RGBA")
CUTTING_BOARD_BG = Image.open("../_media/recipes/blank_recipes/blank_cutting_board_recipe.png").convert("RGBA")
RECIPES_LOCATION = "../../tasty_supplies/src/data/tasty_supplies/recipes/*.json"
ITEMS_LOCATION = "../../tasty_supplies/src/assets/tasty_supplies/textures/item"

MC_TEXTURES_URL = "https://minecraft.wiki/images/Invicon_"

recipes_data = []


def main():
_load_recipes_data()

for recipe in recipes_data:
match _get_recipe_type(recipe):
case "crafting_shapeless":
im = _build_crafting_shapeless(recipe)
im.show()
case "crafting_shaped":
# _build_crafting_shaped(recipe)
pass


def _upscale(im, factor):
return im.resize(tuple(i * factor for i in im.size), Image.Resampling.NEAREST)

def _build_crafting_shapeless(recipe):
im = _upscale(CRAFTING_TABLE_BG.copy(), 2)
padding = (58, 32)

ingredients = recipe["ingredients"]
is_2x2 = len(ingredients) <= 4

index = 0
for item in ingredients:
raw = math.floor(index/(2 if is_2x2 else 3))
col = index - raw*(2 if is_2x2 else 3)

if not item.get("item"):
texture = _get_item_texture("minecraft:barrier")
else:
texture = _get_item_texture(item["item"])
mask = _create_a_mask(texture)

im.paste(texture, (
padding[0] + col*(32+2) + col+2,
padding[1] + raw*(32+2) + raw+2
), mask)

index += 1

custom_model_data = _get_custom_model_data(recipe["result"])
result_texture = _get_item_texture(recipe["result"]["id"], custom_model_data)
mask = _create_a_mask(result_texture)
im.paste(texture, (124, 35), mask)

return im.convert("RGBA")


def _get_item_texture(item: str, custom_model_data: int = -1):
if custom_model_data == -1:
im = _get_minecraft_texture(item)
else:
item_name = item.removeprefix("tasty_supplies:")
im = Image.open(f"{ITEMS_LOCATION}/{item_name}.png")

im = im.resize((32, 32), Image.Resampling.NEAREST)
return im


def _get_custom_texture(custom_model_data: int):
pass


def _get_minecraft_texture(item: str):
item_name = item.removeprefix("minecraft:")
item_name = item_name.replace("_", " ")
item_name = item_name.title()
item_name = item_name.replace(" ", "_")

url = f"{MC_TEXTURES_URL}{item_name}.png"

res = requests.get(url, stream=True)
if not res.ok:
return

im = Image.open(res.raw)
im = im.convert("RGBA")

return im


def _get_custom_model_data(recipe):
if recipe.get("components"):
return recipe["components"]["custom_model_data"]

return -1


def _load_recipes_data():
paths = glob.glob(RECIPES_LOCATION)

for recipe in paths:
if recipe.endswith("reversed.json"):
continue

f = open(recipe)
data = json.load(f)

recipes_data.append(data)


def _get_recipe_type(recipe):
return recipe["type"].removeprefix("minecraft:")


def _create_a_mask(im: Image):
return im.convert('LA')


if __name__ == '__main__':
main()
5 changes: 4 additions & 1 deletion docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
**Tasty Supplies** is datapack that add a lot of new food, recipes and even cooking mechanics in Minecraft by remaining Vanilla. <br>
You'll be able to prepare a wide variety of delicious dishes from cookies to salad and pies.

For now, the datapack is in early development and there are still many features and recipes to be added. To keep track of what's new and to keep an eye on the progress of the project, you can star the project on [GitHub](https://github.com/atomic-junky/tasty-supplies).
If you want to keep track of what's new and to keep an eye on the progress of the project, you can star the project on [GitHub](https://github.com/atomic-junky/tasty-supplies).

All the items added by Tasty Supplies:<br>
![item showcase](./_media/showcase/item_showcase.png)

## Installation and Requirements

Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
beet[image] >= 0.104.1
mecha >= 0.92.0
# beet[image] >= 0.107.0
git+https://github.com/atomic-junky/beet.git
mecha >= 0.94.2
requests >= 2.31.0
8 changes: 4 additions & 4 deletions tasty_supplies/beet.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"version": "0.10.1",
"version": "0.11",
"author": "Atomic Junky",
"output": "build",
"data_pack": {
"name": "Tasty_Supplies_-_Data_Pack",
"pack_format": 41,
"supported_formats": {"min_inclusive": 39, "max_inclusive": 41},
"pack_format": 48,
"supported_formats": {"min_inclusive": 48, "max_inclusive": 48},
"load": ["src"]
},
"resource_pack": {
"name": "Tasty_Supplies_-_Resource_Pack",
"pack_format": 32,
"pack_format": 34,
"load": ["src"]
},
"pipeline": [
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"nutrition": 1,
"saturation": 6,
"can_always_eat": true,
"using_converts_to": {
"id": "minecraft:bucket"
},
"effects": [
{
"effect": {
Expand Down

0 comments on commit 153aff1

Please sign in to comment.