diff options
author | Dániel Juhász <juhdanad@gmail.com> | 2017-06-24 18:58:01 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-08-14 12:52:13 +0100 |
commit | 71b02d626f4a9629e0f282adef908eedc8ed252a (patch) | |
tree | e3c62c3e490ac27b60f611a43a7cc3a2704d7d2f /builtin | |
parent | 4493d47a51dee4c785c009897ee4702850921503 (diff) | |
download | minetest-71b02d626f4a9629e0f282adef908eedc8ed252a.tar.gz minetest-71b02d626f4a9629e0f282adef908eedc8ed252a.tar.bz2 minetest-71b02d626f4a9629e0f282adef908eedc8ed252a.zip |
Make dropped items colorable
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/game/item.lua | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 59ec5ff65..b416a34b0 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -155,6 +155,24 @@ function core.yaw_to_dir(yaw) return {x = -math.sin(yaw), y = 0, z = math.cos(yaw)} end +function core.is_colored_paramtype(ptype) + return (ptype == "color") or (ptype == "colorfacedir") or + (ptype == "colorwallmounted") +end + +function core.strip_param2_color(param2, paramtype2) + if not core.is_colored_paramtype(paramtype2) then + return nil + end + if paramtype2 == "colorfacedir" then + param2 = math.floor(param2 / 32) * 32 + elseif paramtype2 == "colorwallmounted" then + param2 = math.floor(param2 / 8) * 8 + end + -- paramtype2 == "color" requires no modification. + return param2 +end + function core.get_node_drops(node, toolname) -- Compatibility, if node is string local nodename = node @@ -166,24 +184,17 @@ function core.get_node_drops(node, toolname) end local def = core.registered_nodes[nodename] local drop = def and def.drop + local ptype = def and def.paramtype2 + -- get color, if there is color (otherwise nil) + local palette_index = core.strip_param2_color(param2, ptype) if drop == nil then -- default drop - local stack = ItemStack(nodename) - if def then - local type = def.paramtype2 - if (type == "color") or (type == "colorfacedir") or - (type == "colorwallmounted") then - local meta = stack:get_meta() - local color_part = param2 - if (type == "colorfacedir") then - color_part = math.floor(color_part / 32) * 32; - elseif (type == "colorwallmounted") then - color_part = math.floor(color_part / 8) * 8; - end - meta:set_int("palette_index", color_part) - end + if palette_index then + local stack = ItemStack(nodename) + stack:get_meta():set_int("palette_index", palette_index) + return {stack:to_string()} end - return {stack:to_string()} + return {nodename} elseif type(drop) == "string" then -- itemstring drop return {drop} @@ -218,6 +229,12 @@ function core.get_node_drops(node, toolname) if good_rarity and good_tool then got_count = got_count + 1 for _, add_item in ipairs(item.items) do + -- add color, if necessary + if item.inherit_color and palette_index then + local stack = ItemStack(add_item) + stack:get_meta():set_int("palette_index", palette_index) + add_item = stack:to_string() + end got_items[#got_items+1] = add_item end if drop.max_items ~= nil and got_count == drop.max_items then |