priv 'lumberjack' added, digging of trees from the top only added, tool wearing added
This commit is contained in:
parent
da275432db
commit
febfb36f53
@ -3,6 +3,8 @@
|
|||||||
A simple mod based on ideas from the mods TreeCapitator, Timber, and New Timber.
|
A simple mod based on ideas from the mods TreeCapitator, Timber, and New Timber.
|
||||||
This mod allows to hit the bottom of the tree and the whole tree (wood) is harvested
|
This mod allows to hit the bottom of the tree and the whole tree (wood) is harvested
|
||||||
and moved to the players inventory.
|
and moved to the players inventory.
|
||||||
|
But therefore 'lumberjack' privs are needed, otherwise you have to dig the hole tree from the top.
|
||||||
|
(prevents part of trees hanging in the air)
|
||||||
To distinguish between "grown" trees and playes tree nodes, the 'node.param1'
|
To distinguish between "grown" trees and playes tree nodes, the 'node.param1'
|
||||||
is used to identify placed nodes.
|
is used to identify placed nodes.
|
||||||
|
|
||||||
@ -16,4 +18,5 @@ Code: Licensed under the GNU LGPL version 2.1 or later. See LICENSE.txt and http
|
|||||||
Sound is taken from Hybrid Dog (TreeCapitator)
|
Sound is taken from Hybrid Dog (TreeCapitator)
|
||||||
|
|
||||||
# History
|
# History
|
||||||
V0.1 07/Apr/2018 mod initial created
|
V0.1 07/Apr/2018 Mod initial created
|
||||||
|
v0.2 08/Apr/2018 Priv 'lumberjack' added, digging of trees from the top only added, tool wearing added
|
||||||
|
114
init.lua
114
init.lua
@ -21,6 +21,43 @@ local MY_PARAM1_VAL = 7 -- to identify placed nodes
|
|||||||
|
|
||||||
local lTrees = {} -- List od registered tree items
|
local lTrees = {} -- List od registered tree items
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Check of diggers tool is some kind of axe
|
||||||
|
--
|
||||||
|
local function chopper_tool(digger)
|
||||||
|
local tool = digger:get_wielded_item()
|
||||||
|
if tool then
|
||||||
|
local caps = tool:get_tool_capabilities()
|
||||||
|
return caps.groupcaps and caps.groupcaps.choppy
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- tool wearing
|
||||||
|
--
|
||||||
|
local function add_wear(digger, node, num_nodes)
|
||||||
|
local tool = digger:get_wielded_item()
|
||||||
|
if tool then
|
||||||
|
local caps = tool:get_tool_capabilities()
|
||||||
|
if caps.groupcaps and caps.groupcaps.choppy then
|
||||||
|
local maxlevel = caps.groupcaps.choppy.maxlevel or 1
|
||||||
|
local uses = caps.groupcaps.choppy.uses or 10
|
||||||
|
local choppy = lTrees[node.name].choppy or 1
|
||||||
|
local leveldiff = maxlevel - choppy
|
||||||
|
if leveldiff == 1 then
|
||||||
|
uses = uses * 3
|
||||||
|
elseif leveldiff == 2 then
|
||||||
|
uses = uses * 9
|
||||||
|
end
|
||||||
|
print("maxlevel", maxlevel, "uses", uses, "choppy", choppy)
|
||||||
|
tool:add_wear(65535 * num_nodes / uses)
|
||||||
|
print("add_wear", 65535 * num_nodes / uses)
|
||||||
|
digger:set_wielded_item(tool)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Remove all treen nodes in the given range
|
-- Remove all treen nodes in the given range
|
||||||
--
|
--
|
||||||
@ -33,6 +70,18 @@ local function remove_level(pos1, pos2, name)
|
|||||||
return cnt
|
return cnt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Check for tree node on the next higher level
|
||||||
|
--
|
||||||
|
local function check_level(pos, name)
|
||||||
|
local pos1 = {x=pos.x-1, y=pos.y+1, z=pos.z-1}
|
||||||
|
local pos2 = {x=pos.x+1, y=pos.y+1, z=pos.z+1}
|
||||||
|
for _,pos in ipairs(minetest.find_nodes_in_area(pos1, pos2, name)) do
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Remove the complete tree and return the number of removed items
|
-- Remove the complete tree and return the number of removed items
|
||||||
--
|
--
|
||||||
@ -77,11 +126,14 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
|||||||
local radius = lTrees[oldnode.name].radius or 0
|
local radius = lTrees[oldnode.name].radius or 0
|
||||||
local num_nodes = remove_tree(pos, radius, oldnode.name)
|
local num_nodes = remove_tree(pos, radius, oldnode.name)
|
||||||
add_to_inventory(digger, oldnode.name, num_nodes)
|
add_to_inventory(digger, oldnode.name, num_nodes)
|
||||||
|
add_wear(digger, oldnode, num_nodes)
|
||||||
|
minetest.log("action", digger:get_player_name().." fells "..oldnode.name..
|
||||||
|
" ("..num_nodes.." items)".." at "..minetest.pos_to_string(pos))
|
||||||
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 16})
|
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 16})
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Mark node as "used placed"
|
-- Mark node as "player placed"
|
||||||
--
|
--
|
||||||
local function on_construct(pos)
|
local function on_construct(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
@ -90,6 +142,28 @@ local function on_construct(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function can_dig(pos, digger)
|
||||||
|
if not digger then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if minetest.is_protected(pos, digger:get_player_name()) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if minetest.check_player_privs(digger:get_player_name(), "lumberjack") and chopper_tool(digger) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if not check_level(pos, node.name) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_privilege("lumberjack",
|
||||||
|
{description = "Gives you the rights to fell a tree at once",
|
||||||
|
give_to_singleplayer = true})
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Register the tree node to the lumberjack mod.
|
-- Register the tree node to the lumberjack mod.
|
||||||
-- 'radius' the the range (+x/-x/+z/-z), where all available tree nodes will be removed-
|
-- 'radius' the the range (+x/-x/+z/-z), where all available tree nodes will be removed-
|
||||||
@ -100,18 +174,26 @@ function lumberjack.register_tree(name, radius, stem_height_min)
|
|||||||
if data == nil then
|
if data == nil then
|
||||||
error("[lumberjack] "..name.." is no valid item")
|
error("[lumberjack] "..name.." is no valid item")
|
||||||
end
|
end
|
||||||
if data.after_dig_node == nil then
|
if data.after_dig_node then
|
||||||
minetest.override_item(name, {
|
|
||||||
after_dig_node = after_dig_node,
|
|
||||||
on_construct = on_construct,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
error("[lumberjack] "..name.." has already an 'after_dig_node' function")
|
error("[lumberjack] "..name.." has already an 'after_dig_node' function")
|
||||||
end
|
end
|
||||||
lTrees[name] = {radius=radius, height_min=stem_height_min}
|
if data.on_construct then
|
||||||
|
error("[lumberjack] "..name.." has already an 'on_construct' function")
|
||||||
|
end
|
||||||
|
if data.can_dig then
|
||||||
|
error("[lumberjack] "..name.." has already a 'can_dig' function")
|
||||||
|
end
|
||||||
|
if not data.groups.choppy then
|
||||||
|
error("[lumberjack] "..name.." has no 'choppy' property")
|
||||||
|
end
|
||||||
|
minetest.override_item(name, {
|
||||||
|
after_dig_node = after_dig_node,
|
||||||
|
on_construct = on_construct,
|
||||||
|
can_dig = can_dig,
|
||||||
|
})
|
||||||
|
lTrees[name] = {radius=radius, height_min=stem_height_min, choppy=data.groups.choppy}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
lumberjack.register_tree("default:jungletree", 1, 5)
|
lumberjack.register_tree("default:jungletree", 1, 5)
|
||||||
lumberjack.register_tree("default:acacia_tree", 2, 3)
|
lumberjack.register_tree("default:acacia_tree", 2, 3)
|
||||||
lumberjack.register_tree("default:aspen_tree", 0, 5)
|
lumberjack.register_tree("default:aspen_tree", 0, 5)
|
||||||
@ -126,3 +208,17 @@ if minetest.get_modpath("ethereal") and ethereal ~= nil then
|
|||||||
lumberjack.register_tree("ethereal:willow_trunk", 4, 3)
|
lumberjack.register_tree("ethereal:willow_trunk", 4, 3)
|
||||||
lumberjack.register_tree("ethereal:frost_tree", 1, 3)
|
lumberjack.register_tree("ethereal:frost_tree", 1, 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--"moretrees:beech_trunk"
|
||||||
|
--"moretrees:apple_tree_trunk"
|
||||||
|
--"moretrees:oak_trunk"
|
||||||
|
--"moretrees:sequoia_trunk"
|
||||||
|
--"moretrees:birch_trunk"
|
||||||
|
--"moretrees:palm_trunk"
|
||||||
|
--"moretrees:spruce_trunk"
|
||||||
|
--"moretrees:pine_trunk"
|
||||||
|
--"moretrees:willow_trunk"
|
||||||
|
--"moretrees:rubber_tree_trunk"
|
||||||
|
--"moretrees:jungletree_trunk"
|
||||||
|
--"moretrees:fir_trunk"
|
Loading…
x
Reference in New Issue
Block a user