[unifieddyes] Update to Git commit 8b20a06:

https://github.com/minetest-mods/unifieddyes/tree/8b20a06
master
AntumDeluge 2017-06-04 16:20:57 -07:00
parent 3a32b6a938
commit b16869ddb6
2 changed files with 109 additions and 19 deletions

View File

@ -57,7 +57,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
* [moreores][] ([zlib][lic.moreores] / [CC BY-SA][lic.ccbysa3.0]) -- version: [0842b4f Git][ver.moreores] *2017-03-21* ([patched][patch.moreores])
* [quartz][] ([MIT][lic.quartz]) -- version: [00ca4eb Git][ver.quartz] *2017-02-28* ([patched][patch.quartz])
* [rainbow_ore][] ([LGPL][lic.rainbow_ore]) -- version: [6e77693 Git][ver.rainbow_ore] *2015-11-02* ([patched][patch.rainbow_ore])
* [unifieddyes][] ([GPL][lic.gpl2.0]) -- version: [70b1f9f Git][ver.unifieddyes] *2017-02-26* ([patched][patch.unifieddyes])
* [unifieddyes][] ([GPL][lic.gpl2.0]) -- version: [8b20a06 Git][ver.unifieddyes] *2017-06-04*
* mobiles/aggressive/
* [mobs_goblins][] ([CC-BY-SA / CC-BY / CC0][lic.mobs_goblins]) -- version: [a346f85 Git][ver.mobs_goblins] *2015-09-12* ([patched][patch.mobs_goblins])
* [mobs_monster][] ([MIT][lic.mobs_monster]) -- version: [f6d0e01 Git][ver.mobs_monster] *2017-04-27*
@ -480,7 +480,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[ver.tools_obsidian]: https://github.com/Dragonop/tools_obsidian/tree/f77fd79
[ver.trampoline]: https://github.com/AntumDeluge/mtmod-trampoline/tree/ab1c289
[ver.trash_can]: https://github.com/minetest-mods/trash_can/tree/5fd3df7
[ver.unifieddyes]: https://github.com/minetest-mods/unifieddyes/tree/70b1f9f
[ver.unifieddyes]: https://github.com/minetest-mods/unifieddyes/tree/8b20a06
[ver.vector_extras]: https://github.com/HybridDog/vector_extras/tree/472deb6
[ver.walking_light]: https://github.com/petermaloney/walking_light/tree/594bc62
[ver.wardrobe]: https://github.com/prestidigitator/minetest-mod-wardrobe/tree/c48b011
@ -547,7 +547,6 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[patch.spidermob]: https://github.com/AntumDeluge/mtmod-spidermob/tree/89b9bc4
[patch.technic]: https://github.com/AntumDeluge/mtmod-technic/tree/661c23d
[patch.trash_can]: https://github.com/AntumDeluge/mtmod-trash_can/tree/5a92bf4
[patch.unifieddyes]: https://github.com/AntumDeluge/mtmod-unifieddyes/tree/0e575d9
[patch.walking_light]: https://github.com/AntumDeluge/mtmod-walking_light/tree/8084572
[patch.windmill]: https://github.com/AntumDeluge/mtmod-windmill/tree/7756ab4
[patch.workbench]: https://github.com/AntumDeluge/mtmod-workbench/tree/b964323

View File

@ -30,8 +30,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
--=====================================================================
unifieddyes = {}
unifieddyes.last_used_dye = {}
unifieddyes.last_dyed_node = {}
local creative_mode = minetest.setting_getbool("creative_mode")
local creative_mode = minetest.settings:get_bool("creative_mode")
-- Boilerplate to support localized strings if intllib mod is installed.
local S
@ -134,22 +136,79 @@ local default_dyes = {
"yellow"
}
-- this tiles the "extended" palette sideways and then crops it to 256x1
-- to convert it from human readable to something the engine can use as a palette.
--
-- in machine-readable form, the selected color is:
-- [hue] - [shade]*24 for the light colors, or
-- [hue] + [saturation]*24 + [shade]*48 for the dark colors, or
-- 240 + [shade] for the greys, 0 = white.
-- automatically recolor a placed node to match the last-used dye
-- should be called in the node's `after_place_node` callback.
function unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
local playername = placer:get_player_name()
local stackname = itemstack:get_name()
if unifieddyes.last_dyed_node[playername] ~= stackname then
if unifieddyes.last_used_dye[playername] then
minetest.chat_send_player(playername, "Switched to \""..stackname.."\" while auto-coloring, color reset to neutral.")
end
unifieddyes.last_used_dye[playername] = nil
unifieddyes.last_dyed_node[playername] = nil
end
unifieddyes.last_dyed_node[playername] = stackname
if unifieddyes.last_used_dye[playername] then
local lastdye = unifieddyes.last_used_dye[playername]
local inv = placer:get_inventory()
if (lastdye and lastdye ~= "" and inv:contains_item("main", lastdye.." 1")) or creative_mode then
local nodedef = minetest.registered_nodes[stackname]
local newname = nodedef.ud_replacement_node or stackname
local node = minetest.get_node(pos)
local palette_type = true -- default to 89-color split, because the others are easier to check for.
local oldfdir = node.param2 % 32
if nodedef.palette == "unifieddyes_palette.png" then
palette_type = false
oldfdir = 0
elseif nodedef.palette == "unifieddyes_palette_colorwallmounted.png" then
palette_type = "wallmounted"
oldfdir = node.param2 % 8
elseif nodedef.palette == "unifieddyes_palette_extended.png" then
palette_type = "extended"
oldfdir = 0
end
local paletteidx, hue = unifieddyes.getpaletteidx(lastdye, palette_type)
if palette_type == true then newname = string.gsub(newname, "_grey", "_"..unifieddyes.HUES[hue]) end
minetest.set_node(pos, { name = newname, param2 = oldfdir + paletteidx })
local meta = minetest.get_meta(pos)
meta:set_string("dye", lastdye)
if not creative_mode then
inv:remove_item("main", lastdye.." 1")
end
else
minetest.chat_send_player(playername, "Ran out of "..unifieddyes.last_used_dye[playername]..", resetting to neutral.")
unifieddyes.last_used_dye[playername] = nil
end
end
end
minetest.register_on_leaveplayer(function(player)
local playername = player:get_player_name()
unifieddyes.last_used_dye[playername] = nil
unifieddyes.last_dyed_node[playername] = nil
end)
-- code borrowed from homedecor
-- call this function to reset the rotation of a "wallmounted" object on place
function unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
local node = minetest.get_node(pos)
local yaw = placer:get_look_horizontal()
local dir = minetest.yaw_to_dir(yaw-1.5)
local dir = minetest.yaw_to_dir(yaw) -- -1.5)
local pitch = placer:get_look_vertical()
local fdir = minetest.dir_to_wallmounted(dir)
@ -168,7 +227,7 @@ end
function unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
local node = minetest.get_node(pos)
local yaw = placer:get_look_horizontal()
local dir = minetest.yaw_to_dir(yaw)
local dir = minetest.yaw_to_dir(yaw+1.5)
local fdir = minetest.dir_to_wallmounted(dir)
minetest.swap_node(pos, { name = node.name, param2 = fdir })
end
@ -473,6 +532,16 @@ function unifieddyes.getpaletteidx(color, palette_type)
end
end
-- if your node was once 89-color and uses an LBM to convert to the 256-color palette,
-- call this in that node def's on_construct:
function unifieddyes.on_construct(pos)
local meta = minetest.get_meta(pos)
meta:set_string("palette", "ext")
end
-- call this in your node's after_dig_node to get the last-used dye back.
function unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
local prevdye
@ -492,18 +561,30 @@ function unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end
function unifieddyes.on_use(itemstack, player, pointed_thing)
local stackname = itemstack:get_name()
local playername = player:get_player_name()
if pointed_thing and pointed_thing.type == "node" then
if minetest.is_protected(unifieddyes.select_node(pointed_thing), playername)
and not minetest.check_player_privs(playername, "protection_bypass") then
minetest.chat_send_player(playername, "Sorry, someone else owns that spot.")
return
end
end
if pointed_thing and pointed_thing.type == "object" then
pointed_thing.ref:punch(player, 0, itemstack:get_tool_capabilities())
return player:get_wielded_item() -- punch may modified the wielded item, load the new and return it
end
if not (pointed_thing and pointed_thing.type == "node") then return end -- if "using" the dye not on a node
if not (pointed_thing and pointed_thing.type == "node") then return end -- if "using" the dye on nothing at all (e.g. air)
local pos = minetest.get_pointed_thing_position(pointed_thing)
local node = minetest.get_node(pos)
local nodedef = minetest.registered_nodes[node.name]
local playername = player:get_player_name()
if not nodedef then return end -- target was an unknown node, just bail out
-- if the node has an on_punch defined, bail out and call that instead, unless "sneak" is pressed.
if not player:get_player_control().sneak then
@ -513,6 +594,14 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
end
end
if player:get_player_control().sneak then
if unifieddyes.last_used_dye[playername] then
minetest.chat_send_player(playername, "Shift-punched a node, switching back to neutral color." )
end
unifieddyes.last_used_dye[playername] = nil
return
end
-- if the target is unknown, has no groups defined, or isn't UD-colorable, just bail out
if not (nodedef and nodedef.groups and nodedef.groups.ud_param2_colorable) then
minetest.chat_send_player(playername, "That node can't be colored.")
@ -532,19 +621,21 @@ function unifieddyes.on_use(itemstack, player, pointed_thing)
palette_type = "wallmounted"
end
print(palette_type)
if minetest.is_protected(pos, playername) and not minetest.check_player_privs(playername, {protection_bypass=true}) then
minetest.record_protection_violation(pos, playername)
return
end
local stackname = itemstack:get_name()
local pos2 = unifieddyes.select_node(pointed_thing)
local paletteidx, hue = unifieddyes.getpaletteidx(stackname, palette_type)
if paletteidx then
if unifieddyes.last_used_dye[playername] ~= stackname then
minetest.chat_send_player(playername, "Color "..stackname.." selected, auto-coloring activated." )
unifieddyes.last_used_dye[playername] = stackname
end
local meta = minetest.get_meta(pos)
local prevdye = meta:get_string("dye")
local inv = player:get_inventory()