2018-04-07 23:28:59 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
lumberjack
|
|
|
|
==========
|
|
|
|
|
2022-01-29 11:56:11 +01:00
|
|
|
Copyright (C) 2018-2022 Joachim Stolberg
|
2018-04-07 23:28:59 +02:00
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
2018-04-09 22:55:12 +02:00
|
|
|
Mod to completely cut trees by destroying only one block.
|
2022-01-29 11:56:11 +01:00
|
|
|
This mod allows to destroy the root block of the tree and the whole tree is felled and
|
|
|
|
alternatively moved to the player's inventory or dropped.
|
2018-04-09 22:55:12 +02:00
|
|
|
|
|
|
|
To distinguish between "grown" trees and placed tree nodes, the attribute
|
|
|
|
'node.param1' is used to identify placed nodes.
|
|
|
|
|
|
|
|
The number of necessary lumberjack points has to be configured via 'settingtypes.txt'
|
2018-04-07 23:28:59 +02:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
lumberjack = {}
|
|
|
|
|
2021-03-19 20:30:47 +01:00
|
|
|
-- Test MT 5.4 new string mode
|
2023-03-15 13:56:30 +01:00
|
|
|
local CLIP = minetest.features.use_texture_alpha_string_modes and "blend" or true
|
2022-01-29 11:56:11 +01:00
|
|
|
local S = minetest.get_translator("lumberjack")
|
2021-03-19 20:30:47 +01:00
|
|
|
|
2018-04-07 23:28:59 +02:00
|
|
|
local MY_PARAM1_VAL = 7 -- to identify placed nodes
|
|
|
|
|
2018-04-09 22:55:12 +02:00
|
|
|
-- Necessary number of points for dug trees and placed sapling to get lumberjack privs
|
2020-09-20 16:08:36 +02:00
|
|
|
local LUMBERJACK_TREE_POINTS = tonumber(minetest.settings:get("lumberjack_points")) or 400
|
2021-03-19 20:30:47 +01:00
|
|
|
local LUMBERJACK_SAPL_POINTS = math.floor(LUMBERJACK_TREE_POINTS / 6)
|
2022-01-29 11:56:11 +01:00
|
|
|
local DROP_ITEMS = minetest.settings:get_bool("lumberjack_drop_tree_items") == true
|
2018-04-09 22:55:12 +02:00
|
|
|
|
|
|
|
local lTrees = {} -- List of registered tree items
|
2018-04-07 23:28:59 +02:00
|
|
|
|
2018-04-08 22:27:05 +02:00
|
|
|
--
|
2018-04-17 20:14:26 +02:00
|
|
|
-- Check if used tool is some kind of axe and is used by a player
|
2018-04-08 22:27:05 +02:00
|
|
|
--
|
|
|
|
local function chopper_tool(digger)
|
2018-04-17 20:14:26 +02:00
|
|
|
if digger and digger:is_player() then
|
|
|
|
local tool = digger:get_wielded_item()
|
|
|
|
if tool then
|
|
|
|
local caps = tool:get_tool_capabilities()
|
2021-03-19 20:30:47 +01:00
|
|
|
if caps.groupcaps and caps.groupcaps.choppy and caps.groupcaps.choppy.maxlevel then
|
2021-03-28 13:50:03 +02:00
|
|
|
-- diamond axe returns 3
|
|
|
|
return caps.groupcaps.choppy.maxlevel <= 3
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
2018-04-17 20:14:26 +02:00
|
|
|
end
|
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2018-04-16 22:19:31 +02:00
|
|
|
--
|
|
|
|
-- Remove/add tree steps
|
|
|
|
--
|
|
|
|
local function remove_steps(pos)
|
|
|
|
local pos1 = {x=pos.x-1, y=pos.y, z=pos.z-1}
|
|
|
|
local pos2 = {x=pos.x+1, y=pos.y, z=pos.z+1}
|
|
|
|
for _,pos in ipairs(minetest.find_nodes_in_area(pos1, pos2, "lumberjack:step")) do
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function add_steps(pos, digger)
|
|
|
|
local facedir = minetest.dir_to_facedir(digger:get_look_dir(), false)
|
|
|
|
local dir = minetest.facedir_to_dir((facedir + 2) % 4)
|
|
|
|
local newpos = vector.add(pos, dir)
|
2018-04-17 20:14:26 +02:00
|
|
|
if minetest.get_node(newpos).name == "air" then
|
|
|
|
minetest.add_node(newpos, {name="lumberjack:step", param2=facedir})
|
|
|
|
end
|
2018-04-16 22:19:31 +02:00
|
|
|
end
|
|
|
|
|
2018-05-30 22:48:13 +02:00
|
|
|
local function on_punch(pos, node, puncher, pointed_thing)
|
2018-04-17 20:14:26 +02:00
|
|
|
if chopper_tool(puncher) and node.param1 == 0 then -- grown tree?
|
|
|
|
if not minetest.is_protected(pos, puncher:get_player_name()) then
|
|
|
|
add_steps(pos, puncher)
|
|
|
|
end
|
2018-04-16 22:19:31 +02:00
|
|
|
end
|
2018-04-20 20:17:10 +02:00
|
|
|
minetest.node_punch(pos, node, puncher, pointed_thing)
|
2018-04-16 22:19:31 +02:00
|
|
|
end
|
|
|
|
|
2018-04-08 22:27:05 +02:00
|
|
|
--
|
|
|
|
-- 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 uses = caps.groupcaps.choppy.uses or 10
|
2018-04-09 22:55:12 +02:00
|
|
|
uses = uses * 9
|
2022-02-01 18:55:19 +01:00
|
|
|
if minetest.global_exists("toolranks") then
|
2022-02-02 10:55:14 +01:00
|
|
|
local itemmeta = tool:get_meta()
|
|
|
|
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
|
|
|
itemmeta:set_string("dug", dugnodes + num_nodes - 1)
|
2022-02-01 18:55:19 +01:00
|
|
|
toolranks.new_afteruse(tool, digger, node, {wear = uses})
|
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
tool:add_wear(65535 * num_nodes / uses)
|
|
|
|
digger:set_wielded_item(tool)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
2021-03-19 20:30:47 +01:00
|
|
|
-- Remove all tree nodes including steps in the given area
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
2018-04-16 22:10:08 +02:00
|
|
|
local function remove_items(pos1, pos2, name)
|
2018-04-07 23:28:59 +02:00
|
|
|
local cnt = 0
|
|
|
|
for _,pos in ipairs(minetest.find_nodes_in_area(pos1, pos2, name)) do
|
|
|
|
minetest.remove_node(pos)
|
2018-04-16 22:19:31 +02:00
|
|
|
remove_steps(pos)
|
2022-01-29 11:56:11 +01:00
|
|
|
if DROP_ITEMS then
|
|
|
|
minetest.add_item(pos, ItemStack(name))
|
|
|
|
end
|
2018-04-07 23:28:59 +02:00
|
|
|
cnt = cnt + 1
|
|
|
|
end
|
|
|
|
return cnt
|
|
|
|
end
|
|
|
|
|
2018-04-08 22:27:05 +02:00
|
|
|
--
|
2018-04-10 13:06:08 +02:00
|
|
|
-- Check for tree nodes on the next higher level
|
2018-04-17 20:14:26 +02:00
|
|
|
-- We have to check more than one level, because Ethereal allows stem gaps
|
2018-04-08 22:27:05 +02:00
|
|
|
--
|
2018-04-09 22:55:12 +02:00
|
|
|
local function is_top_tree_node(pos, name)
|
2018-04-08 22:27:05 +02:00
|
|
|
local pos1 = {x=pos.x-1, y=pos.y+1, z=pos.z-1}
|
2018-04-17 20:14:26 +02:00
|
|
|
local pos2 = {x=pos.x+1, y=pos.y+3, z=pos.z+1}
|
2018-04-08 22:27:05 +02:00
|
|
|
for _,pos in ipairs(minetest.find_nodes_in_area(pos1, pos2, name)) do
|
2018-04-09 22:55:12 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-04-10 13:06:08 +02:00
|
|
|
--
|
|
|
|
-- Check for the necessary number of points and grant lumberjack privs if level is reached
|
|
|
|
--
|
2021-03-19 20:30:47 +01:00
|
|
|
|
|
|
|
local function get_points(player)
|
|
|
|
if player and player.is_player and player:is_player() then
|
2024-07-27 19:10:47 +02:00
|
|
|
-- Passthrough for pipeworks nodebreakers ( assume enough lumberjack points )
|
|
|
|
if not player.get_meta or -- pipeworks standard behavior
|
|
|
|
getmetatable(player) == "fakelib:player" then -- mt-mods new behavior
|
2021-03-28 13:50:03 +02:00
|
|
|
return -1,-1
|
|
|
|
end
|
2021-03-19 20:30:47 +01:00
|
|
|
local meta = player:get_meta()
|
|
|
|
|
|
|
|
if not meta:contains("lumberjack_tree_points") then
|
|
|
|
meta:set_int("lumberjack_tree_points", LUMBERJACK_TREE_POINTS)
|
|
|
|
end
|
|
|
|
if not meta:contains("lumberjack_sapl_points") then
|
|
|
|
meta:set_int("lumberjack_sapl_points", LUMBERJACK_SAPL_POINTS)
|
|
|
|
end
|
|
|
|
|
|
|
|
local tree_points = meta:get_int("lumberjack_tree_points")
|
|
|
|
local sapl_points = meta:get_int("lumberjack_sapl_points")
|
|
|
|
|
|
|
|
return tree_points, sapl_points
|
2021-02-20 10:18:07 +01:00
|
|
|
end
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function is_lumberjack(player, tree_points, sapl_points)
|
|
|
|
if not tree_points or not sapl_points then
|
|
|
|
return false
|
|
|
|
elseif tree_points > 0 or sapl_points > 0 then
|
2018-04-09 22:55:12 +02:00
|
|
|
return false
|
2021-03-19 20:30:47 +01:00
|
|
|
elseif tree_points == 0 or sapl_points == 0 then
|
|
|
|
local meta = player:get_meta()
|
|
|
|
if not meta:contains("is_lumberjack") then
|
|
|
|
meta:set_int("is_lumberjack", 1)
|
|
|
|
local player_name = player:get_player_name()
|
2022-01-29 11:56:11 +01:00
|
|
|
minetest.chat_send_player(player_name, S("You're a real lumberjack now!"))
|
|
|
|
minetest.log("action", player_name .. " got lumberjack privs")
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
2018-04-09 22:55:12 +02:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
2021-03-19 20:30:47 +01:00
|
|
|
-- Maintain lumberjack points
|
2018-04-09 22:55:12 +02:00
|
|
|
--
|
2021-03-19 20:30:47 +01:00
|
|
|
local function after_dig_tree(digger)
|
|
|
|
local tree_points, sapl_points = get_points(digger)
|
2021-03-28 13:50:03 +02:00
|
|
|
if tree_points and digger.get_meta then
|
2021-03-19 20:30:47 +01:00
|
|
|
tree_points = tree_points - 1
|
|
|
|
local meta = digger:get_meta()
|
|
|
|
meta:set_int("lumberjack_tree_points", tree_points)
|
|
|
|
is_lumberjack(digger, tree_points, sapl_points)
|
2018-04-08 22:27:05 +02:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2018-04-10 13:06:08 +02:00
|
|
|
--
|
|
|
|
-- Decrement sapling points
|
|
|
|
--
|
2018-04-09 22:55:12 +02:00
|
|
|
local function after_place_sapling(pos, placer)
|
2021-03-19 20:30:47 +01:00
|
|
|
local tree_points, sapl_points = get_points(placer)
|
2021-03-28 13:50:03 +02:00
|
|
|
if sapl_points and placer.get_meta then
|
2021-03-19 20:30:47 +01:00
|
|
|
sapl_points = sapl_points - 1
|
|
|
|
local meta = placer:get_meta()
|
|
|
|
meta:set_int("lumberjack_sapl_points", sapl_points)
|
|
|
|
is_lumberjack(placer, tree_points, sapl_points)
|
2018-04-09 22:55:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
|
|
|
-- Remove the complete tree and return the number of removed items
|
|
|
|
--
|
|
|
|
local function remove_tree(pos, radius, name)
|
|
|
|
local level = 1
|
|
|
|
local num_nodes = 0
|
|
|
|
while true do
|
2018-04-17 20:14:26 +02:00
|
|
|
-- We have to check more than one level, because Ethereal allows stem gaps
|
2018-04-16 22:10:08 +02:00
|
|
|
local pos1 = {x=pos.x-radius, y=pos.y+level, z=pos.z-radius}
|
|
|
|
local pos2 = {x=pos.x+radius, y=pos.y+level+2, z=pos.z+radius}
|
|
|
|
local cnt = remove_items(pos1, pos2, name)
|
2018-04-07 23:28:59 +02:00
|
|
|
if cnt == 0 then break end
|
|
|
|
num_nodes = num_nodes + cnt
|
2018-04-17 20:14:26 +02:00
|
|
|
level = level + 3
|
2018-04-07 23:28:59 +02:00
|
|
|
end
|
|
|
|
return num_nodes
|
|
|
|
end
|
|
|
|
|
2018-04-09 22:55:12 +02:00
|
|
|
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
|
|
|
-- Add tree items to the players inventory
|
|
|
|
--
|
2018-04-12 21:54:30 +02:00
|
|
|
local function add_to_inventory(digger, name, len, pos)
|
2022-01-29 11:56:11 +01:00
|
|
|
if not DROP_ITEMS then
|
|
|
|
local inv = digger:get_inventory()
|
|
|
|
local items = ItemStack(name .. " " .. len)
|
|
|
|
if inv and items and inv:room_for_item("main", items) then
|
|
|
|
inv:add_item("main", items)
|
|
|
|
else
|
|
|
|
minetest.item_drop(items, digger, pos)
|
|
|
|
end
|
2018-04-07 23:28:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
2018-04-10 13:06:08 +02:00
|
|
|
-- Remove the complete tree if the destroyed node belongs to a tree
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
|
|
|
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
2018-04-09 22:55:12 +02:00
|
|
|
-- Player placed node?
|
|
|
|
if oldnode.param1 ~= 0 then return end
|
2021-03-19 20:30:47 +01:00
|
|
|
|
|
|
|
after_dig_tree(digger)
|
2018-04-17 20:14:26 +02:00
|
|
|
remove_steps(pos)
|
2019-01-28 08:14:12 +01:00
|
|
|
-- don't remove whole tree?
|
2018-04-17 20:14:26 +02:00
|
|
|
if not digger or digger:get_player_control().sneak then return end
|
2019-01-28 08:14:12 +01:00
|
|
|
-- Get tree parameters
|
|
|
|
local height_min = 3
|
|
|
|
local radius = 0
|
|
|
|
local registered_tree = lTrees[oldnode.name]
|
|
|
|
if registered_tree then
|
|
|
|
height_min = registered_tree.height_min or height_min
|
|
|
|
radius = registered_tree.radius or radius
|
|
|
|
end
|
2018-04-09 22:55:12 +02:00
|
|
|
-- Or root nodes?
|
2018-04-07 23:28:59 +02:00
|
|
|
local test_pos = {x=pos.x, y=pos.y+height_min-1, z=pos.z}
|
|
|
|
if minetest.get_node(test_pos).name ~= oldnode.name then return end
|
2018-04-09 22:55:12 +02:00
|
|
|
-- Fell the tree
|
2018-04-07 23:28:59 +02:00
|
|
|
local num_nodes = remove_tree(pos, radius, oldnode.name)
|
2018-04-12 21:54:30 +02:00
|
|
|
add_to_inventory(digger, oldnode.name, num_nodes, pos)
|
2018-04-08 22:27:05 +02:00
|
|
|
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))
|
2018-04-07 23:28:59 +02:00
|
|
|
minetest.sound_play("tree_falling", {pos = pos, max_hear_distance = 16})
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
2018-04-10 13:06:08 +02:00
|
|
|
-- Mark node as "placed by player"
|
2018-04-07 23:28:59 +02:00
|
|
|
--
|
|
|
|
local function on_construct(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node then
|
|
|
|
minetest.swap_node(pos, {name=node.name, param1=MY_PARAM1_VAL, param2=node.param2})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-08 22:27:05 +02:00
|
|
|
local function can_dig(pos, digger)
|
|
|
|
if not digger then
|
|
|
|
return true
|
|
|
|
end
|
2021-03-19 20:30:47 +01:00
|
|
|
local name = digger:get_player_name()
|
|
|
|
if minetest.is_protected(pos, name) then
|
2018-04-08 22:27:05 +02:00
|
|
|
return false
|
|
|
|
end
|
2022-02-01 18:55:19 +01:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.param1 ~= 0 then
|
|
|
|
return true
|
|
|
|
end
|
2022-09-09 04:24:39 +02:00
|
|
|
-- compatibility with digtron mod
|
|
|
|
local dbg_info = debug.getinfo(2)
|
|
|
|
if dbg_info.source:sub(-17) == "/digtron/util.lua"
|
|
|
|
and dbg_info.name == "execute_dig" then
|
|
|
|
return true
|
|
|
|
end
|
2021-03-19 20:30:47 +01:00
|
|
|
local tree_points, sapl_points = get_points(digger)
|
|
|
|
if is_lumberjack(digger, tree_points, sapl_points) then
|
2018-04-10 20:43:15 +02:00
|
|
|
if chopper_tool(digger) then
|
|
|
|
return true
|
2022-01-29 11:56:11 +01:00
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, S("[Lumberjack Mod] You are using the wrong tool"))
|
|
|
|
return false
|
2018-04-10 20:43:15 +02:00
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
end
|
2021-03-19 20:30:47 +01:00
|
|
|
if is_top_tree_node(pos, node.name) then
|
2018-04-08 22:27:05 +02:00
|
|
|
return true
|
|
|
|
end
|
2022-01-29 11:56:11 +01:00
|
|
|
minetest.chat_send_player(name, S("[Lumberjack Mod] From the top, please"))
|
2018-04-08 22:27:05 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2018-04-16 22:10:08 +02:00
|
|
|
minetest.register_node("lumberjack:step", {
|
|
|
|
description = "Lumberjack Step",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
tiles = {"lumberjack_steps.png"},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -0.5, -0.5, 0.49, 0.5, 0.5, 0.5},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
climbable = true,
|
|
|
|
paramtype = "light",
|
2021-03-19 20:30:47 +01:00
|
|
|
use_texture_alpha = CLIP,
|
2018-04-16 22:10:08 +02:00
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
pointable = false,
|
|
|
|
drop = "",
|
|
|
|
groups = {choppy = 2},
|
|
|
|
})
|
|
|
|
|
2018-04-08 22:27:05 +02:00
|
|
|
|
2018-04-07 23:41:34 +02:00
|
|
|
--
|
|
|
|
-- Register the tree node to the lumberjack mod.
|
2018-04-10 13:06:08 +02:00
|
|
|
-- 'tree_name' is the tree item name,, e.g. "default:tree"
|
|
|
|
-- 'sapling_name' is the tree sapling name, e.g. "default:sapling"
|
2022-01-29 11:56:11 +01:00
|
|
|
-- 'radius' is the range in nodes (+x/-x/+z/-z), where all available tree nodes will be removed.
|
|
|
|
-- 'stem_height_min' is the minimum number of tree nodes, to be a valid stem (and not a root item).
|
2018-04-07 23:41:34 +02:00
|
|
|
--
|
2018-04-09 22:55:12 +02:00
|
|
|
function lumberjack.register_tree(tree_name, sapling_name, radius, stem_height_min)
|
|
|
|
|
|
|
|
-- check tree attributes
|
|
|
|
local data = minetest.registered_nodes[tree_name]
|
2018-04-07 23:41:34 +02:00
|
|
|
if data == nil then
|
2018-04-09 22:55:12 +02:00
|
|
|
error("[lumberjack] "..tree_name.." is no valid item")
|
2018-04-07 23:41:34 +02:00
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
if data.after_dig_node then
|
2018-04-09 22:55:12 +02:00
|
|
|
error("[lumberjack] "..tree_name.." has already an 'after_dig_node' function")
|
2018-04-07 23:41:34 +02:00
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
if data.on_construct then
|
2018-04-09 22:55:12 +02:00
|
|
|
error("[lumberjack] "..tree_name.." has already an 'on_construct' function")
|
2018-04-08 22:27:05 +02:00
|
|
|
end
|
|
|
|
if data.can_dig then
|
2018-04-09 22:55:12 +02:00
|
|
|
error("[lumberjack] "..tree_name.." has already a 'can_dig' function")
|
2018-04-08 22:27:05 +02:00
|
|
|
end
|
|
|
|
if not data.groups.choppy then
|
2018-04-09 22:55:12 +02:00
|
|
|
error("[lumberjack] "..tree_name.." has no 'choppy' property")
|
|
|
|
end
|
|
|
|
|
2018-04-10 13:06:08 +02:00
|
|
|
-- check sapling attributes
|
2018-04-09 22:55:12 +02:00
|
|
|
if minetest.registered_nodes[sapling_name].after_place_node then
|
|
|
|
error("[lumberjack] "..sapling_name.." has already an 'after_place_node' function")
|
2018-04-08 22:27:05 +02:00
|
|
|
end
|
2018-04-09 22:55:12 +02:00
|
|
|
|
|
|
|
minetest.override_item(tree_name, {
|
2018-04-08 22:27:05 +02:00
|
|
|
after_dig_node = after_dig_node,
|
|
|
|
on_construct = on_construct,
|
|
|
|
can_dig = can_dig,
|
2018-04-16 22:10:08 +02:00
|
|
|
on_punch = on_punch,
|
2018-04-08 22:27:05 +02:00
|
|
|
})
|
2018-04-09 22:55:12 +02:00
|
|
|
minetest.override_item(sapling_name, {
|
|
|
|
after_place_node = after_place_sapling
|
|
|
|
})
|
|
|
|
|
|
|
|
lTrees[tree_name] = {radius=radius, height_min=stem_height_min, choppy=data.groups.choppy}
|
2018-04-07 23:41:34 +02:00
|
|
|
end
|
|
|
|
|
2021-03-19 20:30:47 +01:00
|
|
|
minetest.register_chatcommand("lumberjack", {
|
2022-01-29 11:56:11 +01:00
|
|
|
description = S("Output your lumberjack points"),
|
2021-03-19 20:30:47 +01:00
|
|
|
func = function(name, param)
|
|
|
|
local tree_points, sapl_points = get_points(minetest.get_player_by_name(name))
|
|
|
|
if tree_points > 0 and sapl_points > 0 then
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("You need further @1 tree and @2 sapling points.", tree_points, sapl_points)
|
2021-03-19 20:30:47 +01:00
|
|
|
elseif tree_points > 0 then
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("You need further @1 tree points.", tree_points)
|
2021-03-19 20:30:47 +01:00
|
|
|
elseif sapl_points > 0 then
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("You need further @1 sapling points.", sapl_points)
|
2021-03-19 20:30:47 +01:00
|
|
|
else
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("You are already a lumberjack.")
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("set_lumberjack_points", {
|
|
|
|
params = "<name> <tree-points>",
|
2022-01-29 11:56:11 +01:00
|
|
|
description = S("Give a player lumberjack points"),
|
2021-03-19 20:30:47 +01:00
|
|
|
privs = {server = true},
|
|
|
|
func = function(name, param)
|
|
|
|
local param_name, points = param:match("^(%S+)%s+(%d+)$")
|
|
|
|
if param_name and points then
|
|
|
|
local tree_points = tonumber(points) or 0
|
|
|
|
local sapl_points = math.floor(tree_points / 6)
|
|
|
|
local player = minetest.get_player_by_name(param_name)
|
|
|
|
if player then
|
|
|
|
local meta = player:get_meta()
|
|
|
|
meta:set_int("lumberjack_tree_points", tree_points)
|
|
|
|
meta:set_int("lumberjack_sapl_points", sapl_points)
|
|
|
|
meta:set_string("is_lumberjack", "")
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("Player @1 now has @2 tree and @3 sapling points.", param_name, tree_points, sapl_points)
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
2022-01-29 11:56:11 +01:00
|
|
|
return true, S("Player @1 is unknown!", param_name)
|
2021-03-19 20:30:47 +01:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2022-01-29 12:37:18 +01:00
|
|
|
if minetest.global_exists("default") then
|
|
|
|
lumberjack.register_tree("default:tree", "default:sapling", 1, 2)
|
|
|
|
lumberjack.register_tree("default:jungletree", "default:junglesapling", 1, 5)
|
2023-05-01 12:09:37 +02:00
|
|
|
lumberjack.register_tree("default:acacia_tree", "default:acacia_sapling", 2, 2)
|
2022-01-29 12:37:18 +01:00
|
|
|
lumberjack.register_tree("default:aspen_tree", "default:aspen_sapling", 0, 5)
|
|
|
|
lumberjack.register_tree("default:pine_tree", "default:pine_sapling", 0, 3)
|
|
|
|
end
|
2018-04-07 23:28:59 +02:00
|
|
|
|
2018-04-16 22:10:08 +02:00
|
|
|
if minetest.get_modpath("ethereal") and minetest.global_exists("ethereal") then
|
2018-04-09 22:55:12 +02:00
|
|
|
lumberjack.register_tree("ethereal:palm_trunk", "ethereal:palm_sapling", 1, 3)
|
|
|
|
lumberjack.register_tree("ethereal:mushroom_trunk", "ethereal:mushroom_sapling", 1, 3)
|
|
|
|
lumberjack.register_tree("ethereal:birch_trunk", "ethereal:birch_sapling", 0, 3)
|
|
|
|
lumberjack.register_tree("ethereal:banana_trunk", "ethereal:banana_tree_sapling", 1, 3)
|
|
|
|
lumberjack.register_tree("ethereal:willow_trunk", "ethereal:willow_sapling", 4, 3)
|
|
|
|
lumberjack.register_tree("ethereal:frost_tree", "ethereal:frost_tree_sapling", 1, 3)
|
2020-11-10 17:08:25 +01:00
|
|
|
lumberjack.register_tree("ethereal:sakura_trunk", "ethereal:sakura_sapling", 4, 3)
|
|
|
|
lumberjack.register_tree("ethereal:yellow_trunk", "ethereal:yellow_tree_sapling", 3, 3)
|
2018-04-07 23:28:59 +02:00
|
|
|
end
|
2018-04-08 22:27:05 +02:00
|
|
|
|
2019-01-29 06:09:26 +01:00
|
|
|
if minetest.get_modpath("moretrees") and minetest.global_exists("moretrees") then
|
|
|
|
lumberjack.register_tree("moretrees:beech_trunk", "moretrees:beech_sapling", 1, 3)
|
|
|
|
lumberjack.register_tree("moretrees:apple_tree_trunk", "moretrees:apple_tree_sapling", 8, 3)
|
|
|
|
lumberjack.register_tree("moretrees:oak_trunk", "moretrees:oak_sapling", 13,5 )
|
|
|
|
lumberjack.register_tree("moretrees:sequoia_trunk", "moretrees:sequoia_sapling", 9, 3)
|
|
|
|
lumberjack.register_tree("moretrees:birch_trunk", "moretrees:birch_sapling", 12,5)
|
|
|
|
lumberjack.register_tree("moretrees:palm_trunk", "moretrees:palm_sapling", 5, 3)
|
|
|
|
-- lumberjack.register_tree("moretrees:palm_fruit_trunk", "moretrees:palm_sapling", 5, 3)
|
|
|
|
lumberjack.register_tree("moretrees:spruce_trunk", "moretrees:spruce_sapling", 1, 3)
|
|
|
|
lumberjack.register_tree("moretrees:pine_trunk", "moretrees:pine_sapling", 0, 3)
|
|
|
|
lumberjack.register_tree("moretrees:willow_trunk", "moretrees:willow_sapling",1,3)
|
|
|
|
lumberjack.register_tree("moretrees:rubber_tree_trunk", "moretrees:rubber_tree_sapling", 7, 3)
|
|
|
|
-- lumberjack.register_tree("moretrees:jungletree_trunk", "moretrees:jungletree_sapling", 1, 5) -- crashes
|
|
|
|
lumberjack.register_tree("moretrees:fir_trunk", "moretrees:fir_sapling", 5, 3) -- below leaves by 5
|
|
|
|
end
|