techage/tools/trowel.lua

69 lines
1.7 KiB
Lua
Raw Normal View History

2019-03-02 14:24:48 +03:00
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
2020-10-19 20:09:17 +03:00
AGPL v3
2019-03-02 14:24:48 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2019-03-02 14:24:48 +03:00
Trowel tool to hide/open cable/pipe/tube nodes
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
2019-03-02 14:24:48 +03:00
local function replace_node(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.under
local name = placer:get_player_name()
if minetest.is_protected(pos, name) then
return
end
2021-06-05 21:18:04 +03:00
local node = minetest.get_node(pos)
local res = false
2019-03-02 14:24:48 +03:00
if minetest.get_item_group(node.name, "techage_trowel") == 1 then
2021-06-05 21:18:04 +03:00
res = networks.hide_node(pos, node, placer)
elseif networks.hidden_name(pos) or M(pos):get_string("techage_hidden_nodename") ~= "" then
2021-06-05 21:18:04 +03:00
res = networks.open_node(pos, node, placer)
else
minetest.chat_send_player(placer:get_player_name(), "Invalid/unsuported block!")
return
end
if res then
minetest.sound_play("default_dig_snappy", {
2022-01-03 23:40:31 +03:00
pos = pos,
2021-06-05 21:18:04 +03:00
gain = 1,
max_hear_distance = 5})
elseif placer and placer.get_player_name then
minetest.chat_send_player(placer:get_player_name(), "Invalid fill material in inventory slot 1!")
2019-03-02 14:24:48 +03:00
end
end
end
minetest.register_tool("techage:trowel", {
description = S("TechAge Trowel"),
2019-03-02 14:24:48 +03:00
inventory_image = "techage_trowel.png",
wield_image = "techage_trowel.png",
use_texture_alpha = techage.CLIP,
2019-03-02 14:24:48 +03:00
groups = {cracky=1},
on_use = replace_node,
on_place = replace_node,
node_placement_prediction = "",
stack_max = 1,
})
2019-05-11 02:21:03 +03:00
minetest.register_craft({
output = "techage:trowel",
recipe = {
{"basic_materials:steel_bar", "basic_materials:steel_bar", ""},
{"basic_materials:steel_bar", "default:stick", ""},
{"", "", "default:stick"},
},
})