summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2025-03-27 17:13:44 -0400
committerB. Stack <bgstack15@gmail.com>2025-03-27 17:13:44 -0400
commit72656e86a9892d9535cdf8c79c4738aa11310d5a (patch)
tree9d98e8a23e66c7ce211601985e7b16e3901c0d4d
parentload pouches from player inv at login time (diff)
downloadinventory_pouches-combined.tar.gz
inventory_pouches-combined.tar.bz2
inventory_pouches-combined.zip
add dyes to minetest_gamecombined
-rwxr-xr-xcolor_helper.py47
-rw-r--r--src/coloured.lua28
2 files changed, 71 insertions, 4 deletions
diff --git a/color_helper.py b/color_helper.py
new file mode 100755
index 0000000..5b6e719
--- /dev/null
+++ b/color_helper.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# File: color_helper.py
+# Location: https://bgstack15.ddns.net/cgit/inventory_pouches
+# Author: bgstack15
+# Startdate: 2025-03-27-5 15:01
+# Title: Print Color Strings for Dyes
+# Purpose: print out dye colors based on texture images for minetest_game
+# Project: inventory_pouches
+# History:
+# Usage: ./color_helper.py ~/.var/app/net.minetest.Minetest/.minetest/games/minetest_game
+# Reference:
+# https://stackoverflow.com/questions/3380726/converting-an-rgb-color-tuple-to-a-hexidecimal-string/43572620#43572620
+# Improve:
+# Dependencies:
+# dep-devuan: python3-pil
+import os, sys
+from PIL import Image
+
+def rgba2hex(rgba):
+ return "#{:02x}{:02x}{:02x}".format(rgba[0],rgba[1],rgba[2])
+
+def get_color_from_texture_file(infile):
+ key = os.path.basename(infile).replace("_",":",1).replace(".png","")
+ with Image.open(infile) as im:
+ pix = im.load()
+ # grab a useful pixel
+ value = pix[8,8]
+ return ' {"' + key + '","' + rgba2hex(value) + '"},'
+ return None
+
+def print_texture_files(directory):
+ x = 0
+ directory = directory.rstrip("/")
+ if os.path.basename(directory) == "minetest_game":
+ directory = directory + "/mods/dye"
+ for root, subdir, files in os.walk(directory):
+ for i in files:
+ x = x + 1
+ if x == 1:
+ print("inventory_pouches.dye_color_pairs = {")
+ if i.endswith(".png"):
+ print(get_color_from_texture_file(os.path.join(root,i)))
+ if x > 0:
+ print("}")
+
+# pass either path to minetest_game or its mods/dye
+print_texture_files(sys.argv[1])
diff --git a/src/coloured.lua b/src/coloured.lua
index 4e0684f..25d53b0 100644
--- a/src/coloured.lua
+++ b/src/coloured.lua
@@ -22,6 +22,25 @@ inventory_pouches.dye_color_pairs = {
{"mcl_dyes:white",mcl_colors.WHITE},
{"mcl_dyes:yellow",mcl_colors.YELLOW},
}
+elseif minetest.get_modpath("dye") then
+ -- made with color_helper.py
+ inventory_pouches.dye_color_pairs = {
+ {"dye:dark_grey","#494949"},
+ {"dye:red","#c91818"},
+ {"dye:grey","#9c9c9c"},
+ {"dye:white","#eeeeee"},
+ {"dye:green","#67eb1c"},
+ {"dye:dark_green","#2b7b00"},
+ {"dye:brown","#6c3800"},
+ {"dye:pink","#ffa5a5"},
+ {"dye:black","#292929"},
+ {"dye:violet","#480680"},
+ {"dye:orange","#e0601a"},
+ {"dye:magenta","#d80481"},
+ {"dye:yellow","#fcf611"},
+ {"dye:cyan","#00959d"},
+ {"dye:blue","#00519d"},
+ }
end
@@ -60,11 +79,11 @@ local function craft_colored_pouch(itemstack, player, old_craft_grid, craft_inv)
local color_idx = unifieddyes.getpaletteidx("dye:" .. dye_name_match, "extended")
meta:set_int("palette_index", color_idx)
- -- Handle Minecraft-like dyes
- elseif minetest.get_modpath("mcl_dyes") then
+ -- Handle Minecraft-like and minetest_game
+ elseif minetest.get_modpath("mcl_dyes") or minetest.get_modpath("dye") then
for _, dye_entry in ipairs(inventory_pouches.dye_color_pairs) do
local entry_dye_name, color_string = unpack(dye_entry)
- if dye_name_match == entry_dye_name:match(":(%w+)$") then
+ if dye_name_match == entry_dye_name:match(":([%w_]+)$") then
meta:set_string("color", color_string)
break
end
@@ -97,7 +116,8 @@ minetest.register_on_craft(craft_colored_pouch)
-- Register crafting recipes for colored pouches
-if minetest.get_modpath("mcl_dyes") then
+-- Handle Minecraft-like and minetest_game
+if minetest.get_modpath("mcl_dyes") or minetest.get_modpath("dye") then
for _, entry in ipairs(inventory_pouches.dye_color_pairs) do
local dye_name, _ = unpack(entry)
craft_def = {
bgstack15