stripped_tree/init.lua

91 lines
2.5 KiB
Lua
Raw Normal View History

2020-11-07 22:11:22 +01:00
--check if creative for tree bark
local creative_mode = minetest.settings:get_bool("creative_mode")
2020-11-04 00:08:38 +01:00
--Register nodes
local trunk_names = {
"tree", "jungletree", "aspen_tree", "acacia_tree", "pine_tree",
2020-11-04 00:08:38 +01:00
}
2020-11-05 01:34:39 +01:00
-- Register all stripped trees
2020-11-04 00:08:38 +01:00
for _, name in ipairs(trunk_names) do
minetest.register_node(":default:stripped_" .. name, {
2020-11-04 00:08:38 +01:00
description = "Stripped "..name,
tiles = {
"stripped_"..name.."_top.png",
"stripped_"..name.."_top.png",
"stripped_"..name..".png"
},
2020-11-05 01:34:39 +01:00
groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1},
2020-11-04 00:08:38 +01:00
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_place = minetest.rotate_node,
})
end
2020-11-06 05:09:06 +01:00
--Register tree bark
minetest.register_craftitem(":default:tree_bark", {
description = "Tree bark",
inventory_image = "tree_bark.png",
groups = {not_in_creative_inventory = 1}
})
minetest.register_craft({
type = "fuel",
recipe = "default:tree_bark",
burntime = 15,
})
--list of axes to override
local axe_types = {
"wood", "stone", "bronze", "steel", "mese", "diamond",
}
for _, axe_name in ipairs(axe_types) do
minetest.override_item("default:axe_" .. axe_name, {
on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
return
2020-11-04 00:08:38 +01:00
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local node = minetest.get_node(pos).name
for _, n in ipairs(trunk_names) do
local tree = "default:"..n
if tree==node then
local old_node = minetest.get_node(pos)
minetest.swap_node(pos, {name = "default:stripped_"..n, param2 = old_node.param2})
itemstack:add_wear(65535 / 299) -- 300 uses
2020-11-06 17:01:11 +01:00
2020-11-07 22:11:22 +01:00
if not creative_mode then
2020-11-06 05:09:06 +01:00
local inv = user:get_inventory()
if inv:room_for_item("main", "default:tree_bark") then
inv:add_item("main", {name="default:tree_bark"})
else
2020-11-07 22:52:23 +01:00
minetest.add_item(pos, "default:tree_bark")
end
2020-11-07 22:11:22 +01:00
end
2020-11-06 16:59:57 +01:00
return itemstack
end
end
end,
})
end
--register alias to support old tool
minetest.register_alias("chisel_tree:chisel", "default:axe_steel")
2020-11-04 00:25:04 +01:00
2020-11-04 00:08:38 +01:00