mirror of
https://github.com/minefaco/stripped_tree.git
synced 2024-11-19 22:13:50 +01:00
remove mods tool, add ability for default axes to strip trees
This commit is contained in:
parent
060c943076
commit
9fdcb7439a
78
init.lua
78
init.lua
@ -1,11 +1,11 @@
|
|||||||
--Register nodes
|
--Register nodes
|
||||||
local trunk_names = {
|
local trunk_names = {
|
||||||
"tree", "jungletree", "aspen_tree", "acacia_tree","pine_tree",
|
"tree", "jungletree", "aspen_tree", "acacia_tree", "pine_tree",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Register all stripped trees
|
-- Register all stripped trees
|
||||||
for _, name in ipairs(trunk_names) do
|
for _, name in ipairs(trunk_names) do
|
||||||
minetest.register_node(":default:stripped_"..name, {
|
minetest.register_node(":default:stripped_" .. name, {
|
||||||
description = "Stripped "..name,
|
description = "Stripped "..name,
|
||||||
tiles = {
|
tiles = {
|
||||||
"stripped_"..name.."_top.png",
|
"stripped_"..name.."_top.png",
|
||||||
@ -19,51 +19,47 @@ for _, name in ipairs(trunk_names) do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--Register tool
|
--list of axes to override
|
||||||
minetest.register_tool("chisel_tree:chisel", {
|
local axe_types = {
|
||||||
description = "A chisel for wood",
|
"wood", "stone", "bronze", "steel", "mese", "diamond",
|
||||||
inventory_image = "chisel.png",
|
}
|
||||||
wield_image = "chisel.png",
|
|
||||||
sound = {breaks = "default_tool_breaks"},
|
|
||||||
stack_max = 1,
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "node" then
|
for _, axe_name in ipairs(axe_types) do
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos = pointed_thing.under
|
minetest.override_item("default:axe_" .. axe_name, {
|
||||||
local pname = user:get_player_name()
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
if minetest.is_protected(pos, pname) then
|
if pointed_thing.type ~= "node" then
|
||||||
minetest.record_protection_violation(pos, pname)
|
return
|
||||||
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
|
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end,
|
local pos = pointed_thing.under
|
||||||
})
|
local pname = user:get_player_name()
|
||||||
|
|
||||||
--Register craft
|
if minetest.is_protected(pos, pname) then
|
||||||
minetest.register_craft({
|
minetest.record_protection_violation(pos, pname)
|
||||||
output = "chisel_tree:chisel",
|
return
|
||||||
recipe = {
|
end
|
||||||
{"", "default:steel_ingot", ""},
|
|
||||||
{"", "group:fence", ""},
|
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
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--register alias to support old tool
|
||||||
|
minetest.register_alias("chisel_tree:chisel", "default:axe_steel")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user