diff options
-rw-r--r-- | technic/sounds/technic_spray_painter.ogg | bin | 0 -> 19629 bytes | |||
-rw-r--r-- | technic/textures/technic_paint.png | bin | 0 -> 182 bytes | |||
-rw-r--r-- | technic/textures/technic_paint_palette.png | bin | 0 -> 293 bytes | |||
-rw-r--r-- | technic/textures/technic_spray_painter.png | bin | 0 -> 457 bytes | |||
-rw-r--r-- | technic/tools/init.lua | 2 | ||||
-rw-r--r-- | technic/tools/spray_painter.lua | 190 |
6 files changed, 192 insertions, 0 deletions
diff --git a/technic/sounds/technic_spray_painter.ogg b/technic/sounds/technic_spray_painter.ogg Binary files differnew file mode 100644 index 0000000..3541ab9 --- /dev/null +++ b/technic/sounds/technic_spray_painter.ogg diff --git a/technic/textures/technic_paint.png b/technic/textures/technic_paint.png Binary files differnew file mode 100644 index 0000000..b052757 --- /dev/null +++ b/technic/textures/technic_paint.png diff --git a/technic/textures/technic_paint_palette.png b/technic/textures/technic_paint_palette.png Binary files differnew file mode 100644 index 0000000..b4bc32f --- /dev/null +++ b/technic/textures/technic_paint_palette.png diff --git a/technic/textures/technic_spray_painter.png b/technic/textures/technic_spray_painter.png Binary files differnew file mode 100644 index 0000000..99d1f07 --- /dev/null +++ b/technic/textures/technic_spray_painter.png 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") diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua new file mode 100644 index 0000000..cea42b4 --- /dev/null +++ b/technic/tools/spray_painter.lua @@ -0,0 +1,190 @@ +-- 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_cpa = 10 + +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"}, + 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}, + }, + drop = "", + groups = {attached_node = 1, dig_immediate = 2, not_in_creative_inventory = 1}, + paramtype = "light", + paramtype2 = "colorwallmounted", + palette = "technic_paint_palette.png", +}) + + +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 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 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.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) + + if not target or target.name ~= "air" then + return itemstack + end + + 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 + }) + + 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 + +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, +}) + + +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 = { + {'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 |