mirror of
https://github.com/mt-mods/unifieddyes.git
synced 2024-09-28 23:20:21 +02:00
Compare commits
17 Commits
2021-03-26
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
de6e2e0e35 | ||
|
3e45f316a3 | ||
|
ecd05bfd90 | ||
|
5af9254c3a | ||
|
36c8bb5f5b | ||
|
96a939c069 | ||
|
878377301f | ||
|
2af4f1fb98 | ||
|
c079888023 | ||
|
ed895734f2 | ||
|
26994e39f2 | ||
|
41dd54d1be | ||
|
608c80662a | ||
|
934ac7180b | ||
|
62526b9a3b | ||
|
521b73d4ed | ||
|
ff3b2d30fa |
18
.github/workflows/luacheck.yml
vendored
Normal file
18
.github/workflows/luacheck.yml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
name: luacheck
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: apt
|
||||||
|
run: sudo apt-get install -y luarocks
|
||||||
|
- name: luacheck install
|
||||||
|
run: luarocks install --local luacheck
|
||||||
|
- name: luacheck run
|
||||||
|
run: $HOME/.luarocks/bin/luacheck ./
|
25
.luacheckrc
Normal file
25
.luacheckrc
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
exclude_files = {".luacheckrc"}
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"minetest", "core",
|
||||||
|
|
||||||
|
--mod provided
|
||||||
|
"unifieddyes",
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
string = {fields = {"split"}},
|
||||||
|
table = {fields = {"copy", "getn"}},
|
||||||
|
|
||||||
|
--luac
|
||||||
|
"math", "table",
|
||||||
|
|
||||||
|
-- Builtin
|
||||||
|
"vector", "ItemStack", "dump", "DIR_DELIM", "VoxelArea", "Settings", "PcgRandom", "VoxelManip", "PseudoRandom",
|
||||||
|
|
||||||
|
--mod produced
|
||||||
|
|
||||||
|
}
|
|
@ -13,4 +13,4 @@ Install: Unzip the distribution file, rename the resultant folder to just "unifi
|
||||||
|
|
||||||
Usage: for detailed usage information, please see [the Unified Dyes Thread](https://forum.minetest.net/viewtopic.php?f=11&t=2178&p=28399) on the Minetest forum.
|
Usage: for detailed usage information, please see [the Unified Dyes Thread](https://forum.minetest.net/viewtopic.php?f=11&t=2178&p=28399) on the Minetest forum.
|
||||||
|
|
||||||
API: the full API is documented here: https://github.com/minetest-mods/unifieddyes/blob/master/API.md
|
API: the full API is documented here: https://github.com/mt-mods/unifieddyes/blob/master/API.md
|
||||||
|
|
60
airbrush.lua
60
airbrush.lua
|
@ -49,7 +49,7 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local palette = nil
|
local palette
|
||||||
local fdir = 0
|
local fdir = 0
|
||||||
if not def or not def.palette then
|
if not def or not def.palette then
|
||||||
minetest.chat_send_player(player_name, "*** That node can't be colored -- it's either undefined or has no palette.")
|
minetest.chat_send_player(player_name, "*** That node can't be colored -- it's either undefined or has no palette.")
|
||||||
|
@ -71,12 +71,15 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
|
||||||
|
|
||||||
local idx, hue = unifieddyes.getpaletteidx(painting_with, palette)
|
local idx, hue = unifieddyes.getpaletteidx(painting_with, palette)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
if (not creative or not creative.is_enabled_for(player_name)) and not inv:contains_item("main", painting_with) then
|
if (not minetest.is_creative_enabled(player_name)) and not inv:contains_item("main", painting_with) then
|
||||||
local suff = ""
|
local suff = ""
|
||||||
if not idx then
|
if not idx then
|
||||||
suff = " Besides, "..string.sub(painting_with, 5).." can't be applied to that node."
|
suff = " Besides, "..string.sub(painting_with, 5).." can't be applied to that node."
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(player_name, "*** You're in survival mode, and you're out of "..string.sub(painting_with, 5).."."..suff)
|
minetest.chat_send_player(
|
||||||
|
player_name,
|
||||||
|
"*** You're in survival mode, and you're out of "..string.sub(painting_with, 5).."."..suff
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,8 +95,8 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
|
||||||
|
|
||||||
local modname = string.sub(name, 1, string.find(name, ":")-1)
|
local modname = string.sub(name, 1, string.find(name, ":")-1)
|
||||||
local nodename2 = string.sub(name, string.find(name, ":")+1)
|
local nodename2 = string.sub(name, string.find(name, ":")+1)
|
||||||
local oldcolor = "snozzberry"
|
local oldcolor
|
||||||
local newcolor = "razzberry" -- intentionally misspelled ;-)
|
local newcolor
|
||||||
|
|
||||||
if def.ud_color_start and def.ud_color_end then
|
if def.ud_color_start and def.ud_color_end then
|
||||||
oldcolor = string.sub(node.name, def.ud_color_start, def.ud_color_end)
|
oldcolor = string.sub(node.name, def.ud_color_start, def.ud_color_end)
|
||||||
|
@ -123,7 +126,7 @@ function unifieddyes.on_airbrush(itemstack, player, pointed_thing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
minetest.swap_node(pos, {name = name, param2 = fdir + idx})
|
minetest.swap_node(pos, {name = name, param2 = fdir + idx})
|
||||||
if not creative or not creative.is_enabled_for(player_name) then
|
if not minetest.is_creative_enabled(player_name) then
|
||||||
inv:remove_item("main", painting_with)
|
inv:remove_item("main", painting_with)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -144,7 +147,7 @@ function unifieddyes.make_readable_color(color)
|
||||||
local s = string.gsub(color, "_s50", "")
|
local s = string.gsub(color, "_s50", "")
|
||||||
|
|
||||||
-- replace underscores with spaces to make it look nicer
|
-- replace underscores with spaces to make it look nicer
|
||||||
local s = string.gsub(s, "_", " ")
|
s = string.gsub(s, "_", " ")
|
||||||
|
|
||||||
-- capitalize words, you know, looks nicer ;)
|
-- capitalize words, you know, looks nicer ;)
|
||||||
s = string.gsub(s, "(%l)(%w*)", function(a,b) return string.upper(a)..b end)
|
s = string.gsub(s, "(%l)(%w*)", function(a,b) return string.upper(a)..b end)
|
||||||
|
@ -160,7 +163,8 @@ function unifieddyes.make_readable_color(color)
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv, explist)
|
function unifieddyes.make_colored_square(hexcolor, colorname, showall, creative, painting_with, nodepalette, hp, v2,
|
||||||
|
selindic, inv, explist)
|
||||||
|
|
||||||
local dye = "dye:"..colorname
|
local dye = "dye:"..colorname
|
||||||
|
|
||||||
|
@ -216,7 +220,7 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local painting_with = unifieddyes.player_selected_dye[player_name] or unifieddyes.player_current_dye[player_name]
|
local painting_with = unifieddyes.player_selected_dye[player_name] or unifieddyes.player_current_dye[player_name]
|
||||||
local creative = creative and creative.is_enabled_for(player_name)
|
local creative = minetest.is_creative_enabled(player_name)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local nodepalette = "extended"
|
local nodepalette = "extended"
|
||||||
local showall = unifieddyes.player_showall[player_name]
|
local showall = unifieddyes.player_showall[player_name]
|
||||||
|
@ -226,7 +230,10 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
|
|
||||||
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
|
local last_right_click = unifieddyes.player_last_right_clicked[player_name]
|
||||||
if last_right_click then
|
if last_right_click then
|
||||||
if last_right_click.def and last_right_click.def.palette then
|
if not last_right_click.def then
|
||||||
|
last_right_click.def = {}
|
||||||
|
last_right_click.undef = true
|
||||||
|
elseif last_right_click.def.palette then
|
||||||
if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then
|
if last_right_click.def.palette == "unifieddyes_palette_colorwallmounted.png" then
|
||||||
nodepalette = "wallmounted"
|
nodepalette = "wallmounted"
|
||||||
elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" then
|
elseif last_right_click.def.palette == "unifieddyes_palette_extended.png" then
|
||||||
|
@ -240,7 +247,9 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not last_right_click.def.groups
|
if last_right_click.undef then
|
||||||
|
t[#t+1] = "label[0.5,8.25;"..S("(Right-clicked an undefined node, showing all colors)").."]"
|
||||||
|
elseif not last_right_click.def.groups
|
||||||
or not last_right_click.def.groups.ud_param2_colorable
|
or not last_right_click.def.groups.ud_param2_colorable
|
||||||
or not last_right_click.def.palette
|
or not last_right_click.def.palette
|
||||||
or not string.find(last_right_click.def.palette, "unifieddyes_palette_") then
|
or not string.find(last_right_click.def.palette, "unifieddyes_palette_") then
|
||||||
|
@ -275,7 +284,8 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
|
|
||||||
local hexcolor = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
|
local hexcolor = string.format("%02x", r2)..string.format("%02x", g2)..string.format("%02x", b2)
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv, explist)
|
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette,
|
||||||
|
hp, v2, selindic, inv, explist)
|
||||||
t[#t+1] = f
|
t[#t+1] = f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -308,7 +318,8 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
|
|
||||||
local hexcolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
local hexcolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv, explist)
|
f, selindic = unifieddyes.make_colored_square(hexcolor, val..hue..sat, showall, creative, painting_with,
|
||||||
|
nodepalette, hp, v2, selindic, inv, explist)
|
||||||
t[#t+1] = f
|
t[#t+1] = f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -330,7 +341,8 @@ function unifieddyes.show_airbrush_form(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local f
|
local f
|
||||||
f, selindic = unifieddyes.make_colored_square(hexgrey, grey, showall, creative, painting_with, nodepalette, hp, v2, selindic, inv, explist)
|
f, selindic = unifieddyes.make_colored_square(hexgrey, grey, showall, creative, painting_with, nodepalette, hp, v2,
|
||||||
|
selindic, inv, explist)
|
||||||
t[#t+1] = f
|
t[#t+1] = f
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -426,7 +438,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
minetest.chat_send_player(player_name, "*** Clicked \"Accept\", but the selected color can't be used on the")
|
minetest.chat_send_player(player_name, "*** Clicked \"Accept\", but the selected color can't be used on the")
|
||||||
minetest.chat_send_player(player_name, "*** node that was right-clicked (and \"Show All\" wasn't in effect).")
|
minetest.chat_send_player(player_name, "*** node that was right-clicked (and \"Show All\" wasn't in effect).")
|
||||||
if unifieddyes.player_current_dye[player_name] then
|
if unifieddyes.player_current_dye[player_name] then
|
||||||
minetest.chat_send_player(player_name, "*** Ignoring it and sticking with "..string.sub(unifieddyes.player_current_dye[player_name], 5)..".")
|
minetest.chat_send_player(player_name, "*** Ignoring it and sticking with "
|
||||||
|
..string.sub(unifieddyes.player_current_dye[player_name], 5)..".")
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name, "*** Ignoring it.")
|
minetest.chat_send_player(player_name, "*** Ignoring it.")
|
||||||
end
|
end
|
||||||
|
@ -442,15 +455,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local s1 = string.sub(minetest.serialize(fields), 11)
|
local color, _ = next(fields)
|
||||||
local s3 = string.sub(s1,1, string.find(s1, '"')-1)
|
|
||||||
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local creative = creative and creative.is_enabled_for(player_name)
|
local creative = minetest.is_creative_enabled(player_name)
|
||||||
local dye = "dye:"..s3
|
local dye = "dye:"..color
|
||||||
|
|
||||||
if (showall or unifieddyes.palette_has_color[nodepalette.."_"..s3]) and
|
if (showall or unifieddyes.palette_has_color[nodepalette.."_"..color]) and
|
||||||
(minetest.registered_items[dye] and (creative or inv:contains_item("main", dye))) then
|
(creative or inv:contains_item("main", dye)) then
|
||||||
unifieddyes.player_selected_dye[player_name] = dye
|
unifieddyes.player_selected_dye[player_name] = dye
|
||||||
unifieddyes.show_airbrush_form(player)
|
unifieddyes.show_airbrush_form(player)
|
||||||
end
|
end
|
||||||
|
@ -477,6 +489,10 @@ minetest.register_tool("unifieddyes:airbrush", {
|
||||||
if pos then node = minetest.get_node(pos) end
|
if pos then node = minetest.get_node(pos) end
|
||||||
if node then def = minetest.registered_items[node.name] end
|
if node then def = minetest.registered_items[node.name] end
|
||||||
|
|
||||||
|
if keys.sneak and def and def.on_rightclick then
|
||||||
|
return def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
|
||||||
|
end
|
||||||
|
|
||||||
unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
|
unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
|
||||||
|
|
||||||
if not keys.aux1 then
|
if not keys.aux1 then
|
||||||
|
@ -491,8 +507,6 @@ minetest.register_tool("unifieddyes:airbrush", {
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name, "*** That node is uncolored.")
|
minetest.chat_send_player(player_name, "*** That node is uncolored.")
|
||||||
end
|
end
|
||||||
elseif def.on_rightclick then
|
|
||||||
return def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
minetest.register_alias("dye:light_red", "dye:pink")
|
if minetest.get_modpath("dye") then
|
||||||
minetest.register_alias("dye:medium_orange", "dye:brown")
|
minetest.register_alias("dye:light_red", "dye:pink")
|
||||||
|
minetest.register_alias("dye:medium_orange", "dye:brown")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_alias("unifieddyes:black", "dye:black")
|
minetest.register_alias("unifieddyes:black", "dye:black")
|
||||||
minetest.register_alias("unifieddyes:dark_grey", "dye:dark_grey")
|
minetest.register_alias("unifieddyes:dark_grey", "dye:dark_grey")
|
||||||
|
|
177
api.lua
177
api.lua
|
@ -1,7 +1,5 @@
|
||||||
-- This file supplies the majority of Unified Dyes' API
|
-- This file supplies the majority of Unified Dyes' API
|
||||||
|
|
||||||
local S = minetest.get_translator("unifieddyes")
|
|
||||||
|
|
||||||
unifieddyes.player_current_dye = {}
|
unifieddyes.player_current_dye = {}
|
||||||
unifieddyes.player_selected_dye = {}
|
unifieddyes.player_selected_dye = {}
|
||||||
unifieddyes.player_last_right_clicked = {}
|
unifieddyes.player_last_right_clicked = {}
|
||||||
|
@ -23,11 +21,14 @@ minetest.register_on_placenode(
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local param2
|
|
||||||
if not string.find(itemstack:to_string(), "palette_index") then
|
if not string.find(itemstack:to_string(), "palette_index") then
|
||||||
|
local param2
|
||||||
|
local color = 0
|
||||||
|
|
||||||
if def.palette == "unifieddyes_palette_extended.png"
|
if def.palette == "unifieddyes_palette_extended.png"
|
||||||
and def.paramtype2 == "color" then
|
and def.paramtype2 == "color" then
|
||||||
param2 = 240
|
param2 = 240
|
||||||
|
color = 240
|
||||||
elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
|
elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
|
||||||
and def.paramtype2 == "colorwallmounted" then
|
and def.paramtype2 == "colorwallmounted" then
|
||||||
param2 = newnode.param2 % 8
|
param2 = newnode.param2 % 8
|
||||||
|
@ -38,55 +39,135 @@ minetest.register_on_placenode(
|
||||||
|
|
||||||
if param2 then
|
if param2 then
|
||||||
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
|
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
|
||||||
|
minetest.get_meta(pos):set_int("palette_index", color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.palette ~= "" then
|
|
||||||
minetest.get_meta(pos):set_int("palette_index", param2 or 240)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
-- The complementary function: strip-off the color if the node being dug is still white/neutral
|
-- The complementary function: strip-off the color if the node being dug is still white/neutral
|
||||||
|
-- adapted from
|
||||||
|
-- https://github.com/minetest/minetest/blob/fe8d04d0b3c2e3af7c406fb6527f1b5230a30137/builtin/game/item.lua#L460-L562
|
||||||
|
local function node_dig_without_color(pos, node, digger)
|
||||||
|
if not digger then return false end
|
||||||
|
local diggername = digger:get_player_name()
|
||||||
|
|
||||||
local function move_item(item, pos, inv, digger, fix_color)
|
local def = ItemStack(node.name):get_definition()
|
||||||
if not (digger and digger:is_player()) then return end
|
-- Copy pos because the callback could modify it
|
||||||
local creative = creative_mode or minetest.check_player_privs(digger, "creative")
|
if not def.diggable or (def.can_dig and not def.can_dig(vector.copy(pos), digger)) then
|
||||||
item = unifieddyes.fix_bad_color_info(item, fix_color)
|
minetest.log("info", diggername .. " tried to dig "
|
||||||
if inv:room_for_item("main", item)
|
.. node.name .. " which is not diggable "
|
||||||
and (not creative or not inv:contains_item("main", item, true)) then
|
.. minetest.pos_to_string(pos))
|
||||||
inv:add_item("main", item)
|
return false
|
||||||
elseif not creative then
|
|
||||||
minetest.item_drop(ItemStack(item), digger, pos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if minetest.is_protected(pos, diggername) then
|
||||||
|
minetest.log("action", diggername
|
||||||
|
.. " tried to dig " .. node.name
|
||||||
|
.. " at protected position "
|
||||||
|
.. minetest.pos_to_string(pos))
|
||||||
|
minetest.record_protection_violation(pos, diggername)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log('action', diggername .. " digs "
|
||||||
|
.. node.name .. " at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
|
local wielded = digger and digger:get_wielded_item()
|
||||||
|
local drops = {node.name} -- this is instead of asking minetest to generate the node drops
|
||||||
|
|
||||||
|
if wielded then
|
||||||
|
local wdef = wielded:get_definition()
|
||||||
|
local tp = wielded:get_tool_capabilities()
|
||||||
|
local dp = minetest.get_dig_params(def and def.groups, tp, wielded:get_wear())
|
||||||
|
if wdef and wdef.after_use then
|
||||||
|
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
|
||||||
|
else
|
||||||
|
-- Wear out tool
|
||||||
|
if not minetest.is_creative_enabled(diggername) then
|
||||||
|
wielded:add_wear(dp.wear)
|
||||||
|
if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
|
||||||
|
minetest.sound_play(wdef.sound.breaks, {
|
||||||
|
pos = pos,
|
||||||
|
gain = 0.5
|
||||||
|
}, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
digger:set_wielded_item(wielded)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check to see if metadata should be preserved.
|
||||||
|
if def and def.preserve_metadata then
|
||||||
|
local oldmeta = minetest.get_meta(pos):to_table().fields
|
||||||
|
-- Copy pos and node because the callback can modify them.
|
||||||
|
local pos_copy = vector.copy(pos)
|
||||||
|
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
|
||||||
|
local drop_stacks = {}
|
||||||
|
for k, v in pairs(drops) do
|
||||||
|
drop_stacks[k] = ItemStack(v)
|
||||||
|
end
|
||||||
|
drops = drop_stacks
|
||||||
|
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle drops
|
||||||
|
minetest.handle_node_drops(pos, drops, digger)
|
||||||
|
|
||||||
|
local oldmetadata
|
||||||
|
if def and def.after_dig_node then
|
||||||
|
oldmetadata = minetest.get_meta(pos):to_table()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remove node and update
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
|
||||||
|
-- Play sound if it was done by a player
|
||||||
|
if diggername ~= "" and def and def.sounds and def.sounds.dug then
|
||||||
|
minetest.sound_play(def.sounds.dug, {
|
||||||
|
pos = pos,
|
||||||
|
exclude_player = diggername,
|
||||||
|
}, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Run callback
|
||||||
|
if def and def.after_dig_node then
|
||||||
|
-- Copy pos and node because callback can modify them
|
||||||
|
local pos_copy = vector.copy(pos)
|
||||||
|
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
|
||||||
|
def.after_dig_node(pos_copy, node_copy, oldmetadata, digger)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Run script hook
|
||||||
|
for _, callback in ipairs(minetest.registered_on_dignodes) do
|
||||||
|
local origin = minetest.callback_origins[callback]
|
||||||
|
minetest.set_last_run_mod(origin.mod)
|
||||||
|
|
||||||
|
-- Copy pos and node because callback can modify them
|
||||||
|
local pos_copy = vector.copy(pos)
|
||||||
|
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
|
||||||
|
callback(pos_copy, node_copy, digger)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function unifieddyes.on_dig(pos, node, digger)
|
function unifieddyes.on_dig(pos, node, digger)
|
||||||
if not digger then return end
|
local param2 = minetest.get_node(pos).param2
|
||||||
local playername = digger:get_player_name()
|
|
||||||
if minetest.is_protected(pos, playername) then
|
|
||||||
minetest.record_protection_violation(pos, playername)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local oldparam2 = minetest.get_node(pos).param2
|
|
||||||
local def = minetest.registered_items[node.name]
|
local def = minetest.registered_items[node.name]
|
||||||
local fix_color
|
local del_color
|
||||||
|
|
||||||
if def.paramtype2 == "color" and oldparam2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
|
if def.paramtype2 == "color" and param2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
|
||||||
fix_color = 240
|
del_color = true
|
||||||
elseif def.paramtype2 == "color" and oldparam2 == 0 and def.palette == "unifieddyes_palette_extended.png" then
|
elseif (def.paramtype2 == "colorwallmounted" or def.paramtype2 == "colorfacedir")
|
||||||
fix_color = 0
|
and minetest.strip_param2_color(param2, def.paramtype2) == 0
|
||||||
elseif def.paramtype2 == "colorwallmounted" and math.floor(oldparam2 / 8) == 0 and def.palette == "unifieddyes_palette_colorwallmounted.png" then
|
and string.find(def.palette, "unifieddyes_palette_")
|
||||||
fix_color = 0
|
then
|
||||||
elseif def.paramtype2 == "colorfacedir" and math.floor(oldparam2 / 32) == 0 and string.find(def.palette, "unifieddyes_palette_") then
|
del_color = true
|
||||||
fix_color = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = digger:get_inventory()
|
if del_color then
|
||||||
if fix_color then
|
return node_dig_without_color(pos, node, digger)
|
||||||
move_item(node.name, pos, inv, digger, fix_color)
|
|
||||||
else
|
else
|
||||||
return minetest.node_dig(pos, node, digger)
|
return minetest.node_dig(pos, node, digger)
|
||||||
end
|
end
|
||||||
|
@ -117,6 +198,7 @@ function unifieddyes.generate_split_palette_nodes(name, def, drop)
|
||||||
def2.palette = "unifieddyes_palette_"..color.."s.png"
|
def2.palette = "unifieddyes_palette_"..color.."s.png"
|
||||||
def2.paramtype2 = "colorfacedir"
|
def2.paramtype2 = "colorfacedir"
|
||||||
def2.groups.ud_param2_colorable = 1
|
def2.groups.ud_param2_colorable = 1
|
||||||
|
def2.is_ground_content = false
|
||||||
|
|
||||||
if drop then
|
if drop then
|
||||||
def2.drop = {
|
def2.drop = {
|
||||||
|
@ -132,14 +214,11 @@ end
|
||||||
|
|
||||||
-- This helper function creates a colored itemstack
|
-- This helper function creates a colored itemstack
|
||||||
|
|
||||||
function unifieddyes.fix_bad_color_info(item, paletteidx)
|
|
||||||
local stack=minetest.itemstring_with_color(item, paletteidx)
|
|
||||||
return string.gsub(stack, "u0001color", "u0001palette_index")
|
|
||||||
end
|
|
||||||
|
|
||||||
function unifieddyes.make_colored_itemstack(item, palette, color)
|
function unifieddyes.make_colored_itemstack(item, palette, color)
|
||||||
local paletteidx = unifieddyes.getpaletteidx(color, palette)
|
local paletteidx = unifieddyes.getpaletteidx(color, palette)
|
||||||
return unifieddyes.fix_bad_color_info(item, paletteidx), paletteidx
|
local stack = ItemStack(item)
|
||||||
|
stack:get_meta():set_int("palette_index", paletteidx)
|
||||||
|
return stack:to_string(),paletteidx
|
||||||
end
|
end
|
||||||
|
|
||||||
-- these helper functions register all of the recipes needed to create colored
|
-- these helper functions register all of the recipes needed to create colored
|
||||||
|
@ -147,7 +226,7 @@ end
|
||||||
|
|
||||||
local function register_c(craft, h, sat, val)
|
local function register_c(craft, h, sat, val)
|
||||||
local hue = (type(h) == "table") and h[1] or h
|
local hue = (type(h) == "table") and h[1] or h
|
||||||
local color = ""
|
local color
|
||||||
if val then
|
if val then
|
||||||
if craft.palette == "wallmounted" then
|
if craft.palette == "wallmounted" then
|
||||||
color = val..hue..sat
|
color = val..hue..sat
|
||||||
|
@ -288,9 +367,9 @@ end
|
||||||
|
|
||||||
function unifieddyes.get_hsv(name) -- expects a node/item name
|
function unifieddyes.get_hsv(name) -- expects a node/item name
|
||||||
local hue = ""
|
local hue = ""
|
||||||
local a,b
|
local a
|
||||||
for _, i in ipairs(unifieddyes.HUES_EXTENDED) do
|
for _, i in ipairs(unifieddyes.HUES_EXTENDED) do
|
||||||
a,b = string.find(name, "_"..i[1])
|
a,_ = string.find(name, "_"..i[1])
|
||||||
if a then
|
if a then
|
||||||
hue = i[1]
|
hue = i[1]
|
||||||
break
|
break
|
||||||
|
@ -328,8 +407,6 @@ end
|
||||||
|
|
||||||
function unifieddyes.getpaletteidx(color, palette_type)
|
function unifieddyes.getpaletteidx(color, palette_type)
|
||||||
|
|
||||||
local origcolor = color
|
|
||||||
|
|
||||||
if string.sub(color,1,4) == "dye:" then
|
if string.sub(color,1,4) == "dye:" then
|
||||||
color = string.sub(color,5,-1)
|
color = string.sub(color,5,-1)
|
||||||
elseif string.sub(color,1,12) == "unifieddyes:" then
|
elseif string.sub(color,1,12) == "unifieddyes:" then
|
||||||
|
@ -383,7 +460,8 @@ function unifieddyes.getpaletteidx(color, palette_type)
|
||||||
elseif color == "pink" then return 56,7
|
elseif color == "pink" then return 56,7
|
||||||
elseif color == "blue" and shade == "light" then return 40,5
|
elseif color == "blue" and shade == "light" then return 40,5
|
||||||
elseif unifieddyes.gpidx_hues_wallmounted[color] and unifieddyes.gpidx_shades_wallmounted[shade] then
|
elseif unifieddyes.gpidx_hues_wallmounted[color] and unifieddyes.gpidx_shades_wallmounted[shade] then
|
||||||
return (unifieddyes.gpidx_shades_wallmounted[shade] * 64 + unifieddyes.gpidx_hues_wallmounted[color] * 8), unifieddyes.gpidx_hues_wallmounted[color]
|
return (unifieddyes.gpidx_shades_wallmounted[shade] * 64 + unifieddyes.gpidx_hues_wallmounted[color] * 8),
|
||||||
|
unifieddyes.gpidx_hues_wallmounted[color]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if color == "brown" then
|
if color == "brown" then
|
||||||
|
@ -399,7 +477,8 @@ function unifieddyes.getpaletteidx(color, palette_type)
|
||||||
end
|
end
|
||||||
elseif palette_type == "extended" then
|
elseif palette_type == "extended" then
|
||||||
if unifieddyes.gpidx_hues_extended[color] and unifieddyes.gpidx_shades_extended[shade] then
|
if unifieddyes.gpidx_hues_extended[color] and unifieddyes.gpidx_shades_extended[shade] then
|
||||||
return (unifieddyes.gpidx_hues_extended[color] + unifieddyes.gpidx_shades_extended[shade]*24), unifieddyes.gpidx_hues_extended[color]
|
return (unifieddyes.gpidx_hues_extended[color] + unifieddyes.gpidx_shades_extended[shade]*24),
|
||||||
|
unifieddyes.gpidx_hues_extended[color]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -91,24 +91,6 @@ for i = 1, 14 do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local default_dyes = {
|
|
||||||
"black",
|
|
||||||
"blue",
|
|
||||||
"brown",
|
|
||||||
"cyan",
|
|
||||||
"dark_green",
|
|
||||||
"dark_grey",
|
|
||||||
"green",
|
|
||||||
"grey",
|
|
||||||
"magenta",
|
|
||||||
"orange",
|
|
||||||
"pink",
|
|
||||||
"red",
|
|
||||||
"violet",
|
|
||||||
"white",
|
|
||||||
"yellow"
|
|
||||||
}
|
|
||||||
|
|
||||||
-- reverse lookups for getpaletteidx()
|
-- reverse lookups for getpaletteidx()
|
||||||
|
|
||||||
unifieddyes.gpidx_aliases = {
|
unifieddyes.gpidx_aliases = {
|
||||||
|
|
|
@ -56,11 +56,11 @@ for _, h in ipairs(unifieddyes.HUES_EXTENDED) do
|
||||||
local g3 = math.floor(p+(g2-p)*0.5)
|
local g3 = math.floor(p+(g2-p)*0.5)
|
||||||
local b3 = math.floor(p+(b2-p)*0.5)
|
local b3 = math.floor(p+(b2-p)*0.5)
|
||||||
|
|
||||||
local color = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
local ccolor = string.format("%02x", r3)..string.format("%02x", g3)..string.format("%02x", b3)
|
||||||
|
|
||||||
minetest.register_craftitem(":dye:"..val..hue.."_s50", {
|
minetest.register_craftitem(":dye:"..val..hue.."_s50", {
|
||||||
description = S(desc.." (low saturation)"),
|
description = S(desc.." (low saturation)"),
|
||||||
inventory_image = "unifieddyes_dye.png^[colorize:#"..color..":200",
|
inventory_image = "unifieddyes_dye.png^[colorize:#"..ccolor..":200",
|
||||||
groups = { dye=1, not_in_creative_inventory=1 },
|
groups = { dye=1, not_in_creative_inventory=1 },
|
||||||
})
|
})
|
||||||
minetest.register_alias("unifieddyes:"..val..hue.."_s50", "dye:"..val..hue.."_s50")
|
minetest.register_alias("unifieddyes:"..val..hue.."_s50", "dye:"..val..hue.."_s50")
|
||||||
|
@ -87,19 +87,21 @@ for y = 1, 14 do -- colors 0 and 15 are black and white, default dyes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.override_item("dye:grey", {
|
if minetest.get_modpath("dye") then
|
||||||
|
minetest.override_item("dye:grey", {
|
||||||
inventory_image = "unifieddyes_dye.png^[colorize:#888888:200",
|
inventory_image = "unifieddyes_dye.png^[colorize:#888888:200",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.override_item("dye:dark_grey", {
|
minetest.override_item("dye:dark_grey", {
|
||||||
inventory_image = "unifieddyes_dye.png^[colorize:#444444:200",
|
inventory_image = "unifieddyes_dye.png^[colorize:#444444:200",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craftitem(":dye:light_grey", {
|
minetest.register_craftitem(":dye:light_grey", {
|
||||||
description = S("Light grey Dye"),
|
description = S("Light grey Dye"),
|
||||||
inventory_image = "unifieddyes_dye.png^[colorize:#cccccc:200",
|
inventory_image = "unifieddyes_dye.png^[colorize:#cccccc:200",
|
||||||
groups = { dye=1, not_in_creative_inventory=1 },
|
groups = { dye=1, not_in_creative_inventory=1 },
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
-- build a table of color <-> palette associations to reduce the need for
|
-- build a table of color <-> palette associations to reduce the need for
|
||||||
-- realtime lookups with getpaletteidx()
|
-- realtime lookups with getpaletteidx()
|
||||||
|
|
6
init.lua
6
init.lua
|
@ -31,9 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
unifieddyes = {}
|
unifieddyes = {}
|
||||||
|
|
||||||
local creative_mode = minetest.settings:get_bool("creative_mode")
|
|
||||||
|
|
||||||
local S = minetest.get_translator("unifieddyes")
|
|
||||||
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
dofile(modpath.."/color-tables.lua")
|
dofile(modpath.."/color-tables.lua")
|
||||||
|
@ -42,4 +39,5 @@ dofile(modpath.."/airbrush.lua")
|
||||||
dofile(modpath.."/dyes-crafting.lua")
|
dofile(modpath.."/dyes-crafting.lua")
|
||||||
dofile(modpath.."/aliases.lua")
|
dofile(modpath.."/aliases.lua")
|
||||||
|
|
||||||
print(S("[UnifiedDyes] Loaded!"))
|
print("[UnifiedDyes] Loaded!")
|
||||||
|
unifieddyes.init = true
|
4
mod.conf
4
mod.conf
|
@ -1,4 +1,4 @@
|
||||||
name = unifieddyes
|
name = unifieddyes
|
||||||
description = Unified Dyes expands the standard dye set from 15 to 90 colors.
|
description = Unified Dyes expands the standard dye set from 15 to 90 colors.
|
||||||
depends = default, dye, basic_materials
|
optional_depends = default, dye, basic_materials
|
||||||
min_minetest_version = 5.2.0
|
min_minetest_version = 5.5.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user