stripped_tree/functions.lua

78 lines
3.0 KiB
Lua
Raw Normal View History

2020-11-17 03:55:16 +01:00
stripped_tree = {}
2020-12-20 20:07:09 +01:00
--Select between chisel tool or axes.
stripped_tree.ENABLE_CHISEL = true
2020-11-09 15:41:55 +01:00
local creative_mode = minetest.settings:get_bool("creative_mode")
2020-11-09 04:32:54 +01:00
--function to register nodes
2020-11-17 03:55:16 +01:00
function stripped_tree.register_trunk(mod_name,trunk_names)
2020-11-09 04:32:54 +01:00
for _, name in ipairs(trunk_names) do
minetest.register_node(":"..mod_name..":stripped_" .. name, {
description = "Stripped "..name,
tiles = {
"stripped_"..mod_name.."_"..name.."_top.png",
"stripped_"..mod_name.."_"..name.."_top.png",
"stripped_"..mod_name.."_"..name..".png"
},
groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_place = minetest.rotate_node,
})
2020-12-20 19:23:54 +01:00
minetest.register_craft({
output = mod_name..":"..name,
recipe = {{"","default:tree_bark",""},
{"default:tree_bark",mod_name..":stripped_" .. name,"default:tree_bark"},
{"","default:tree_bark",""}}
})
2020-11-09 04:32:54 +01:00
end
end
--function to override axes
2020-12-20 19:37:33 +01:00
if stripped_tree.ENABLE_CHISEL ~= true then
2020-12-20 19:23:54 +01:00
function stripped_tree.register_axes(mod_n,axe_types)
for _, axe_name in ipairs(axe_types) do
minetest.override_item(mod_n..":" .. axe_name, {
on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
2020-11-09 04:32:54 +01:00
2020-12-20 19:23:54 +01:00
local pos = pointed_thing.under
local pname = user:get_player_name()
2020-11-09 04:32:54 +01:00
2020-12-20 19:23:54 +01:00
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
2020-11-09 04:32:54 +01:00
2020-12-20 19:23:54 +01:00
local node = minetest.get_node(pos).name
local mod_name, node_name = unpack(node:split(":"))
local has_stripped = minetest.registered_nodes[mod_name..":".."stripped_"..node_name]
2020-11-09 15:10:05 +01:00
2020-12-20 19:23:54 +01:00
if has_stripped then
local old_node = minetest.get_node(pos)
local stripped =mod_name..":".."stripped_"..node_name
minetest.swap_node(pos,{name=stripped,param2=old_node.param2})
--itemstack:add_wear(65535 / 299) this is not useful at moment.
2020-11-09 15:10:05 +01:00
2020-12-20 19:23:54 +01:00
if not creative_mode then
local inv = user:get_inventory()
--check for room in inv, if not, drop item
if inv:room_for_item("main", "default:tree_bark") then
inv:add_item("main", {name="default:tree_bark"})
else
minetest.add_item(pos, "default:tree_bark")
end
end
2020-11-09 15:10:05 +01:00
2020-12-20 19:23:54 +01:00
return itemstack
end
2020-11-09 04:32:54 +01:00
2020-12-20 19:23:54 +01:00
end,
})
end
2020-11-09 04:32:54 +01:00
end
end