technic/technic/tools/tree_tap.lua
Zefram 3b16a2858f Revise rules for regenerating latex
To ensure that only rubber tree trunk nodes that are part of trees
regenerate, rather than those that are used as building blocks, check
that they are sufficiently close to rubber tree leaves.  This replaces the
older rule that naturally-grown trunks regenerate (regardless of leaves)
and manually-placed trunks don't (even though manually building a tree
otherwise works).  The detection of manually-placed trunks was in any
case broken for users of moretrees, because that mod fails to set the
flag signalling manual placement.

Incidentally also fix a bug that caused rubber tree branches (horizontal
trunk nodes) to turn vertical when regenerating latex.  Rather than set
the complete node structure, only switch the type name, as does the tree
tap when emptying the node.
2014-08-13 23:13:52 +01:00

75 lines
1.9 KiB
Lua

local S = technic.getter
minetest.register_tool("technic:treetap", {
description = S("Tree Tap"),
inventory_image = "technic_tree_tap.png",
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
return
end
local inv = user:get_inventory()
if not inv:room_for_item("main", ItemStack("technic:raw_latex")) then
return
end
local pos = pointed_thing.under
if minetest.is_protected(pos, user:get_player_name()) then
minetest.record_protection_violation(pos, user:get_player_name())
return
end
local node = minetest.get_node(pos)
local node_name = node.name
if node_name ~= "moretrees:rubber_tree_trunk" then
return
end
node.name = "moretrees:rubber_tree_trunk_empty"
inv:add_item("main", ItemStack("technic:raw_latex"))
minetest.swap_node(pos, node)
local item_wear = tonumber(itemstack:get_wear())
item_wear = item_wear + 819
if item_wear > 65535 then
itemstack:clear()
return itemstack
end
itemstack:set_wear(item_wear)
return itemstack
end,
})
minetest.register_craft({
output = "technic:treetap",
recipe = {
{"pipeworks:tube_1", "group:wood", "default:stick"},
{"", "default:stick", "default:stick"}
},
})
minetest.register_craftitem("technic:raw_latex", {
description = S("Raw Latex"),
inventory_image = "technic_raw_latex.png",
})
minetest.register_craft({
type = "cooking",
output = "technic:rubber",
recipe = "technic:raw_latex",
})
minetest.register_craftitem("technic:rubber", {
description = S("Rubber Fiber"),
inventory_image = "technic_rubber.png",
})
minetest.register_abm({
nodenames = {"moretrees:rubber_tree_trunk_empty"},
interval = 60,
chance = 15,
action = function(pos, node)
if minetest.find_node_near(pos, (moretrees and moretrees.leafdecay_radius) or 5, {"moretrees:rubber_tree_leaves"}) then
node.name = "moretrees:rubber_tree_trunk"
minetest.swap_node(pos, node)
end
end
})