From a8e98399608c6cf5cf6276b7458ad1233d7dedfa Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Wed, 6 Jun 2018 05:53:38 +0300 Subject: spray --- technic/tools/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/technic/tools/init.lua b/technic/tools/init.lua index db5ac7d..7445dc3 100644 --- a/technic/tools/init.lua +++ b/technic/tools/init.lua @@ -20,6 +20,8 @@ dofile(path.."/lawn_trimmer.lua") dofile(path.."/walking_tractor.lua") dofile(path.."/planter.lua") +dofile(path.."/spray_painter.lua") + if minetest.get_modpath("screwdriver") then -- compatibility alias minetest.register_alias("technic:screwdriver", "screwdriver:screwdriver") -- cgit v1.2.3 From c9311be25fca739ef142d7a35691172acdc55b4b Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Wed, 6 Jun 2018 05:55:55 +0300 Subject: spray painter --- technic/textures/technic_paint.png | Bin 0 -> 182 bytes technic/tools/spray_painter.lua | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 technic/textures/technic_paint.png create mode 100644 technic/tools/spray_painter.lua diff --git a/technic/textures/technic_paint.png b/technic/textures/technic_paint.png new file mode 100644 index 0000000..b052757 Binary files /dev/null and b/technic/textures/technic_paint.png differ diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua new file mode 100644 index 0000000..f68dfd5 --- /dev/null +++ b/technic/tools/spray_painter.lua @@ -0,0 +1,64 @@ +local S = technic.getter + +local spray_painter_max_charge = 10000 +local spray_painter_charge_per_application = 1 + +minetest.register_node ("technic:paint_layer", { + description = S("Paint"), + drawtype = "nodebox", + tiles = {"technic_paint.png^[colorize:#FF0000"}, + node_box = { + type = "wallmounted", + wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5}, + wall_top = {-0.5, 0.499, -0.5, 0.5, 0.5, 0.5}, + wall_side = {-0.5, -0.5, -0.5, -0.499, 0.5, 0.5}, + }, +-- node_box = { +-- type = "fixed", +-- fixed = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5}, +-- }, + drop = "", + groups = {attached_node = 1}, + paramtype2 = "wallmounted", +-- on_place = minetest.rotate_node, +}) + + + +local function spray_paint(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + local meta = minetest.deserialize(itemstack:get_metadata()) + if not meta or not meta.charge or + meta.charge < spray_painter_charge_per_application then + return + end + + local name = user:get_player_name() + if minetest.is_protected(pointed_thing.under, name) then + minetest.record_protection_violation(pointed_thing.under, name) + return + end + +-- minetest.place_node(pointed_thing.above, {name = "technic:paint_layer"}) + minetest.rotate_node(ItemStack({name = "technic:paint_layer"}), user, pointed_thing) + + if not technic.creative_mode then + technic.set_RE_wear(itemstack, meta.charge - spray_painter_charge_per_application, spray_painter_max_charge) + itemstack:set_metadata(minetest.serialize(meta)) + end + return itemstack + +end + +technic.register_power_tool("technic:spray_painter", spray_painter_max_charge) +minetest.register_tool("technic:spray_painter", { + description = S("Spray Painter"), + inventory_image = "technic_spray_painter.png", + stack_max = 1, + wear_represents = "technic_RE_charge", + on_refill = technic.refill_RE_charge, + on_use = spray_paint, +}) \ No newline at end of file -- cgit v1.2.3 From b124a7278ce7edfd7504d23e51181827337381f2 Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Wed, 6 Jun 2018 05:56:45 +0300 Subject: spray painter --- extranodes/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extranodes/init.lua b/extranodes/init.lua index f0d2a49..d98c12a 100644 --- a/extranodes/init.lua +++ b/extranodes/init.lua @@ -21,7 +21,7 @@ if minetest.get_modpath("bakedclay") then end -- register procedurally-generated arcs -if minetest.get_modpath("technic") then +if minetest.get_modpath("pkarcs") then pkarcs.register_node("technic:marble") pkarcs.register_node("technic:granite") end -- cgit v1.2.3 From 9fbbb5f71e391ae0bf052766184a16e7e20dcf90 Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Fri, 8 Jun 2018 06:52:30 +0300 Subject: more --- technic/tools/spray_painter.lua | 50 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua index f68dfd5..0c139a3 100644 --- a/technic/tools/spray_painter.lua +++ b/technic/tools/spray_painter.lua @@ -19,16 +19,21 @@ minetest.register_node ("technic:paint_layer", { -- }, drop = "", groups = {attached_node = 1}, + paramtype = "light", paramtype2 = "wallmounted", -- on_place = minetest.rotate_node, }) - local function spray_paint(itemstack, user, pointed_thing) if pointed_thing.type ~= "node" then return itemstack end + + local target = minetest.get_node_or_nil(pointed_thing.above) + if not target or target.name ~= "air" then + return itemstack + end local meta = minetest.deserialize(itemstack:get_metadata()) if not meta or not meta.charge or @@ -42,8 +47,47 @@ local function spray_paint(itemstack, user, pointed_thing) return end --- minetest.place_node(pointed_thing.above, {name = "technic:paint_layer"}) - minetest.rotate_node(ItemStack({name = "technic:paint_layer"}), user, pointed_thing) + minetest.chat_send_all("below: " .. minetest.serialize(pointed_thing.under)) + minetest.chat_send_all("above: " .. minetest.serialize(pointed_thing.above)) +-- minetest.swap_node(pointed_thing.above, {name = "default:dirt"}) +-- minetest.swap_node(pointed_thing.under, {name = "default:cobble"}) + local rrr = vector.subtract(pointed_thing.under, pointed_thing.above) + minetest.chat_send_all(minetest.serialize(rrr)) + local xxx = minetest.dir_to_wallmounted(rrr) + minetest.chat_send_all(minetest.serialize(xxx)) +-- local t = {x = pointed_thing.above.x, y = pointed_thing.above.y, z = pointed_thing.above.z} +-- minetest.chat_send_all("--->" .. minetest.serialize(t)) +-- minetest.place_node(t, {name = "technic:paint_layer", param2 = xxx}) + minetest.swap_node(pointed_thing.above, {name = "technic:paint_layer", param2 = xxx}) + +-- minetest.rotate_node(ItemStack({name = "technic:paint_layer"}), user, pointed_thing) + +-- local player_pos = user:getpos() +-- local player_name = user:get_player_name() +-- local dir = user:get_look_dir() +-- +-- local start_pos = vector.new(player_pos) +-- -- Adjust to head height +-- start_pos.y = start_pos.y + 1.6 +-- local last_air = {} +-- for pos in technic.trace_node_ray(start_pos, dir, 5) do +-- local node = minetest.get_node_or_nil(pos) +-- minetest.chat_send_all(minetest.serialize(pos) .. node.name) +-- if not node then +-- break +-- end +-- if node.name == "air" then +-- last_air.x = pos.x +-- last_air.y = pos.y +-- last_air.z = pos.z +-- else +-- minetest.chat_send_all("---------> " .. minetest.serialize(last_air)) +-- minetest.place_node(last_air, {name = "default:dirt"}) +-- break +-- end +-- minetest.chat_send_all(minetest.serialize(last_air)) +-- +-- end if not technic.creative_mode then technic.set_RE_wear(itemstack, meta.charge - spray_painter_charge_per_application, spray_painter_max_charge) -- cgit v1.2.3 From 187c028128d38d4c7e9032b49d3222ec761427ce Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Sun, 10 Jun 2018 14:22:11 +0300 Subject: properly working --- technic/textures/technic_paint_palette.png | Bin 0 -> 293 bytes technic/tools/spray_painter.lua | 108 +++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 technic/textures/technic_paint_palette.png diff --git a/technic/textures/technic_paint_palette.png b/technic/textures/technic_paint_palette.png new file mode 100644 index 0000000..b4bc32f Binary files /dev/null and b/technic/textures/technic_paint_palette.png differ diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua index 0c139a3..20ea964 100644 --- a/technic/tools/spray_painter.lua +++ b/technic/tools/spray_painter.lua @@ -3,10 +3,23 @@ local S = technic.getter local spray_painter_max_charge = 10000 local spray_painter_charge_per_application = 1 +local color_modes = { + {name = S("Red"), index = 1, n = 2, ct = {"c91818", "730505"}}, + {name = S("Yellow and Orange"), index = 3, n = 4, ct = {"fcf611", "ffc20b", "e0601a", "b52607"}}, + {name = S("Green and Dark Green"), index = 7, n = 4, ct = {"67eb1c", "4bb71c", "2b7b00", "154f00"}}, + {name = S("Blue and Violet"), index = 11, n = 4, ct = {"00519d", "003376", "480680", "3b0367"}}, + {name = S("Pink and Magenta"), index = 15, n = 4, ct = {"ffa5a5", "ff7272", "d80481", "a90145"}}, + {name = S("Cyan"), index = 19, n = 2, ct = {"00959d", "00676f"}}, + {name = S("Brown"), index = 21, n = 2, ct = {"6c3800", "391a00"}}, + {name = S("White and Grey"), index = 23, n = 4, ct = {"eeeeee", "b8b8b8", "9c9c9c", "5c5c5c"}}, + {name = S("Dark Grey and Black"), index = 27, n = 4, ct = {"494949", "292929", "222222", "1b1b1b"}} -- 2 middle colors are swapped +} + minetest.register_node ("technic:paint_layer", { description = S("Paint"), drawtype = "nodebox", - tiles = {"technic_paint.png^[colorize:#FF0000"}, +-- tiles = {"technic_paint.png^[colorize:#FF0000"}, + tiles = {"technic_paint.png"}, node_box = { type = "wallmounted", wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5}, @@ -18,19 +31,74 @@ minetest.register_node ("technic:paint_layer", { -- fixed = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5}, -- }, drop = "", - groups = {attached_node = 1}, + groups = {attached_node = 1, dig_immediate = 2}, paramtype = "light", - paramtype2 = "wallmounted", + paramtype2 = "colorwallmounted", + palette = "technic_paint_palette.png", -- on_place = minetest.rotate_node, }) +local function spray_painter_setmode(user, itemstack, meta) + local player_name = user:get_player_name() + + if not meta then + meta = {mode = nil} + end + if not meta.mode then + minetest.chat_send_player(player_name, + S("Use while sneaking to change Spray Painter modes.")) + meta.mode = 0 + end + + meta.mode = meta.mode % 9 + 1 + + minetest.chat_send_player(player_name, + S("Spray Painter: %s"):format(color_modes[meta.mode].name)) + itemstack:set_name("technic:spray_painter_" .. meta.mode); + itemstack:set_metadata(minetest.serialize(meta)) + return itemstack +end + local function spray_paint(itemstack, user, pointed_thing) + + local meta = minetest.deserialize(itemstack:get_metadata()) + local keys = user:get_player_control() + + if not meta or not meta.mode or keys.sneak then + return spray_painter_setmode(user, itemstack, meta) + end + if pointed_thing.type ~= "node" then return itemstack end - local target = minetest.get_node_or_nil(pointed_thing.above) + + local target = minetest.get_node_or_nil(pointed_thing.under) + + if target and target.name == "technic:paint_layer" then + local p2 = target.param2 +-- local p2 = meta:get_int("param2") + local orientation = p2 % 8 + local cindex = (p2 - orientation) / 8 + local new_cindex = cindex + 1 + if new_cindex < color_modes[meta.mode].index - 1 then + new_cindex = color_modes[meta.mode].index - 1 + end + if new_cindex > color_modes[meta.mode].index + (color_modes[meta.mode].n - 1) - 1 then + new_cindex = color_modes[meta.mode].index - 1 + end + minetest.chat_send_all("---> " .. tostring(orientation) .. " --- " .. tostring(cindex)) + +-- minetest.swap_node(pointed_thing.under, {name = target.name, param2 = (cindex + 1)*8 + orientation}) + minetest.swap_node(pointed_thing.under, {name = target.name, param2 = new_cindex*8 + orientation}) + + return itemstack + end + + + target = minetest.get_node_or_nil(pointed_thing.above) + if not target or target.name ~= "air" then return itemstack end @@ -47,6 +115,8 @@ local function spray_paint(itemstack, user, pointed_thing) return end + + minetest.chat_send_all("below: " .. minetest.serialize(pointed_thing.under)) minetest.chat_send_all("above: " .. minetest.serialize(pointed_thing.above)) -- minetest.swap_node(pointed_thing.above, {name = "default:dirt"}) @@ -58,7 +128,7 @@ local function spray_paint(itemstack, user, pointed_thing) -- local t = {x = pointed_thing.above.x, y = pointed_thing.above.y, z = pointed_thing.above.z} -- minetest.chat_send_all("--->" .. minetest.serialize(t)) -- minetest.place_node(t, {name = "technic:paint_layer", param2 = xxx}) - minetest.swap_node(pointed_thing.above, {name = "technic:paint_layer", param2 = xxx}) + minetest.swap_node(pointed_thing.above, {name = "technic:paint_layer", param2 = (color_modes[meta.mode].index - 1) * 8 + xxx}) -- minetest.rotate_node(ItemStack({name = "technic:paint_layer"}), user, pointed_thing) @@ -105,4 +175,32 @@ minetest.register_tool("technic:spray_painter", { wear_represents = "technic_RE_charge", on_refill = technic.refill_RE_charge, on_use = spray_paint, +}) + + +for i = 1, 9 do + technic.register_power_tool("technic:spray_painter_" .. i, spray_painter_max_charge) + minetest.register_tool("technic:spray_painter_" .. i, { + description = S("Spray Painter: %s"):format(color_modes[i].name), + inventory_image = "technic_spray_painter.png^technic_tool_mode" .. i .. ".png", + wield_image = "technic_spray_painter.png", + wear_represents = "technic_RE_charge", + on_refill = technic.refill_RE_charge, + groups = {not_in_creative_inventory = 1}, + on_use = spray_paint, + }) +end + + +-- Provide a crafting recipe +local trigger = minetest.get_modpath("mesecons_button") and "mesecons_button:button_off" + or "default:mese_crystal_fragment" + +minetest.register_craft({ + output = 'technic:spray_painter', + recipe = { + {'default:stick', 'default:stick', trigger}, + {'technic:motor', 'default:stick', 'technic:battery'}, + {'technic:stainless_steel_ingot', 'default:stick', 'default:stick'}, + } }) \ No newline at end of file -- cgit v1.2.3 From d33401e13dce6768cefb57423fce9ddcba8a05ee Mon Sep 17 00:00:00 2001 From: h-v-smacker Date: Sun, 10 Jun 2018 15:25:37 +0300 Subject: adding sound and extra checks --- technic/sounds/technic_spray_painter.ogg | Bin 0 -> 19629 bytes technic/textures/technic_spray_painter.png | Bin 0 -> 457 bytes technic/tools/spray_painter.lua | 128 +++++++++++++---------------- 3 files changed, 56 insertions(+), 72 deletions(-) create mode 100644 technic/sounds/technic_spray_painter.ogg create mode 100644 technic/textures/technic_spray_painter.png diff --git a/technic/sounds/technic_spray_painter.ogg b/technic/sounds/technic_spray_painter.ogg new file mode 100644 index 0000000..3541ab9 Binary files /dev/null and b/technic/sounds/technic_spray_painter.ogg differ diff --git a/technic/textures/technic_spray_painter.png b/technic/textures/technic_spray_painter.png new file mode 100644 index 0000000..99d1f07 Binary files /dev/null and b/technic/textures/technic_spray_painter.png differ diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua index 20ea964..cea42b4 100644 --- a/technic/tools/spray_painter.lua +++ b/technic/tools/spray_painter.lua @@ -1,7 +1,14 @@ +-- This is a decorative tool to paint exposed surfaces in some basic colors +-- can be used to cover up unpleasant areas (e.g. cobblestone walls) +-- or to mark areas with colors (colored paths on floors, color lines on walls) +-- Colors are grouped together in 9 modes. The HEX values are taken from the dye +-- textures from dye mod of minetest_game. Within every mode, the colors are cycled from +-- brighter to darker hue on every subsequent application of the tool. + local S = technic.getter local spray_painter_max_charge = 10000 -local spray_painter_charge_per_application = 1 +local spray_painter_cpa = 10 local color_modes = { {name = S("Red"), index = 1, n = 2, ct = {"c91818", "730505"}}, @@ -18,7 +25,6 @@ local color_modes = { minetest.register_node ("technic:paint_layer", { description = S("Paint"), drawtype = "nodebox", --- tiles = {"technic_paint.png^[colorize:#FF0000"}, tiles = {"technic_paint.png"}, node_box = { type = "wallmounted", @@ -26,22 +32,17 @@ minetest.register_node ("technic:paint_layer", { wall_top = {-0.5, 0.499, -0.5, 0.5, 0.5, 0.5}, wall_side = {-0.5, -0.5, -0.5, -0.499, 0.5, 0.5}, }, --- node_box = { --- type = "fixed", --- fixed = {-0.5, -0.5, -0.5, 0.5, -0.499, 0.5}, --- }, drop = "", - groups = {attached_node = 1, dig_immediate = 2}, + groups = {attached_node = 1, dig_immediate = 2, not_in_creative_inventory = 1}, paramtype = "light", paramtype2 = "colorwallmounted", palette = "technic_paint_palette.png", --- on_place = minetest.rotate_node, }) local function spray_painter_setmode(user, itemstack, meta) local player_name = user:get_player_name() - + if not meta then meta = {mode = nil} end @@ -65,20 +66,43 @@ local function spray_paint(itemstack, user, pointed_thing) local meta = minetest.deserialize(itemstack:get_metadata()) local keys = user:get_player_control() + if user.get_pos == nil then + -- we are held in a node breaker and it will not work + return itemstack + end + if not meta or not meta.mode or keys.sneak then return spray_painter_setmode(user, itemstack, meta) end + if not meta or not meta.charge or meta.charge < spray_painter_cpa then + return itemstack + end + + if pointed_thing.type ~= "node" then return itemstack end + minetest.sound_play("technic_spray_painter", { + pos = pos, + gain = 0.4, + }) + + -- player needs to own both the wall and its surface + if minetest.is_protected(pointed_thing.under, user:get_player_name()) or + minetest.is_protected(pointed_thing.above, user:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, name) + return itemstack + end local target = minetest.get_node_or_nil(pointed_thing.under) + -- if the tool is pointed at a layer of paint -> cycling colors + if target and target.name == "technic:paint_layer" then + local p2 = target.param2 --- local p2 = meta:get_int("param2") local orientation = p2 % 8 local cindex = (p2 - orientation) / 8 local new_cindex = cindex + 1 @@ -88,14 +112,22 @@ local function spray_paint(itemstack, user, pointed_thing) if new_cindex > color_modes[meta.mode].index + (color_modes[meta.mode].n - 1) - 1 then new_cindex = color_modes[meta.mode].index - 1 end - minetest.chat_send_all("---> " .. tostring(orientation) .. " --- " .. tostring(cindex)) --- minetest.swap_node(pointed_thing.under, {name = target.name, param2 = (cindex + 1)*8 + orientation}) - minetest.swap_node(pointed_thing.under, {name = target.name, param2 = new_cindex*8 + orientation}) + minetest.swap_node(pointed_thing.under, { + name = target.name, + param2 = new_cindex*8 + orientation + }) + + if not technic.creative_mode then + meta.charge = meta.charge - spray_painter_cpa + technic.set_RE_wear(itemstack, meta.charge, spray_painter_max_charge) + itemstack:set_metadata(minetest.serialize(meta)) + end return itemstack end + -- otherwise, spray some paint anew target = minetest.get_node_or_nil(pointed_thing.above) @@ -103,64 +135,16 @@ local function spray_paint(itemstack, user, pointed_thing) return itemstack end - local meta = minetest.deserialize(itemstack:get_metadata()) - if not meta or not meta.charge or - meta.charge < spray_painter_charge_per_application then - return - end - - local name = user:get_player_name() - if minetest.is_protected(pointed_thing.under, name) then - minetest.record_protection_violation(pointed_thing.under, name) - return - end - - - - minetest.chat_send_all("below: " .. minetest.serialize(pointed_thing.under)) - minetest.chat_send_all("above: " .. minetest.serialize(pointed_thing.above)) --- minetest.swap_node(pointed_thing.above, {name = "default:dirt"}) --- minetest.swap_node(pointed_thing.under, {name = "default:cobble"}) - local rrr = vector.subtract(pointed_thing.under, pointed_thing.above) - minetest.chat_send_all(minetest.serialize(rrr)) - local xxx = minetest.dir_to_wallmounted(rrr) - minetest.chat_send_all(minetest.serialize(xxx)) --- local t = {x = pointed_thing.above.x, y = pointed_thing.above.y, z = pointed_thing.above.z} --- minetest.chat_send_all("--->" .. minetest.serialize(t)) --- minetest.place_node(t, {name = "technic:paint_layer", param2 = xxx}) - minetest.swap_node(pointed_thing.above, {name = "technic:paint_layer", param2 = (color_modes[meta.mode].index - 1) * 8 + xxx}) + local diff = vector.subtract(pointed_thing.under, pointed_thing.above) + local wdr = minetest.dir_to_wallmounted(diff) + minetest.swap_node(pointed_thing.above, { + name = "technic:paint_layer", + param2 = (color_modes[meta.mode].index - 1) * 8 + wdr + }) --- minetest.rotate_node(ItemStack({name = "technic:paint_layer"}), user, pointed_thing) - --- local player_pos = user:getpos() --- local player_name = user:get_player_name() --- local dir = user:get_look_dir() --- --- local start_pos = vector.new(player_pos) --- -- Adjust to head height --- start_pos.y = start_pos.y + 1.6 --- local last_air = {} --- for pos in technic.trace_node_ray(start_pos, dir, 5) do --- local node = minetest.get_node_or_nil(pos) --- minetest.chat_send_all(minetest.serialize(pos) .. node.name) --- if not node then --- break --- end --- if node.name == "air" then --- last_air.x = pos.x --- last_air.y = pos.y --- last_air.z = pos.z --- else --- minetest.chat_send_all("---------> " .. minetest.serialize(last_air)) --- minetest.place_node(last_air, {name = "default:dirt"}) --- break --- end --- minetest.chat_send_all(minetest.serialize(last_air)) --- --- end - if not technic.creative_mode then - technic.set_RE_wear(itemstack, meta.charge - spray_painter_charge_per_application, spray_painter_max_charge) + meta.charge = meta.charge - spray_painter_cpa + technic.set_RE_wear(itemstack, meta.charge, spray_painter_max_charge) itemstack:set_metadata(minetest.serialize(meta)) end return itemstack @@ -199,8 +183,8 @@ local trigger = minetest.get_modpath("mesecons_button") and "mesecons_button:but minetest.register_craft({ output = 'technic:spray_painter', recipe = { - {'default:stick', 'default:stick', trigger}, - {'technic:motor', 'default:stick', 'technic:battery'}, - {'technic:stainless_steel_ingot', 'default:stick', 'default:stick'}, + {'pipeworks:tube_1', 'technic:stainless_steel_ingot', 'technic:battery'}, + {'', 'vessels:steel_bottle', trigger}, + {'dye:red', 'dye:green', 'dye:blue'}, } }) \ No newline at end of file -- cgit v1.2.3