mirror of
https://github.com/minetest-mods/technic.git
synced 2025-07-12 05:10:35 +02:00
Compare commits
4 Commits
9b7c44b453
...
49d4105a2b
Author | SHA1 | Date | |
---|---|---|---|
49d4105a2b | |||
fda8a3d042 | |||
dfcf64c1d0 | |||
0921c326a8 |
9
settingtypes.txt
Normal file
9
settingtypes.txt
Normal file
@ -0,0 +1,9 @@
|
||||
# Safety feature for the chainsaw tool aimed to prevent cutting structures
|
||||
# built by players.
|
||||
#
|
||||
# Trunk nodes generated by mapgen have a rotation of '0' whereas manually
|
||||
# placed trunks usually have another value. However, some mods might generate
|
||||
# trees with rotation != 0, which renders the chainsaw useless on them.
|
||||
#
|
||||
# Disabling this feature will sacrifice safety for convenience.
|
||||
technic_safe_chainsaw (Chainsaw safety feature) bool true
|
@ -110,6 +110,40 @@ local function quarry_handle_purge(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- Determines whether the quarry can dig the node at "pos"
|
||||
-- "startpos" is located a few nodes above the quarry in South West direction (X-, Z-)
|
||||
-- Returns the node to dig (to avoid double minetest.get_node lookup)
|
||||
local function quarry_can_dig_node(startpos, pos, quarry_owner)
|
||||
if minetest.is_protected(pos, quarry_owner) then
|
||||
return nil
|
||||
end
|
||||
|
||||
local node = technic.get_or_load_node(pos) or minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name] or {diggable=false}
|
||||
-- doors mod among other thing does NOT like a nil digger...
|
||||
local fakedigger = pipeworks.create_fake_player({
|
||||
name = quarry_owner
|
||||
})
|
||||
if not def.diggable or (def.can_dig and not def.can_dig(pos, fakedigger)) then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Find airlike nodes on top of the current node. The entire Y column must be free.
|
||||
for ay = pos.y+1, startpos.y do
|
||||
local checkpos = {x=pos.x, y=ay, z=pos.z}
|
||||
local checknode = technic.get_or_load_node(checkpos) or minetest.get_node(checkpos)
|
||||
|
||||
local cdef = minetest.registered_nodes[checknode.name] or {}
|
||||
local is_kind_of_gas = cdef.buildable_to and cdef.sunlight_propagates and not cdef.walkable
|
||||
and not cdef.diggable and (cdef.drawtype == "airlike" or cdef.drawtype == "glasslike")
|
||||
if not is_kind_of_gas then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return node
|
||||
end
|
||||
|
||||
local function quarry_run(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
@ -153,35 +187,11 @@ local function quarry_run(pos, node)
|
||||
vector.new(0, -ry, 0)),
|
||||
vector.multiply(pdir, rp)),
|
||||
vector.multiply(qdir, rq))
|
||||
local can_dig = true
|
||||
if can_dig and minetest.is_protected and minetest.is_protected(digpos, owner) then
|
||||
can_dig = false
|
||||
end
|
||||
local dignode
|
||||
if can_dig then
|
||||
dignode = technic.get_or_load_node(digpos) or minetest.get_node(digpos)
|
||||
local dignodedef = minetest.registered_nodes[dignode.name] or {diggable=false}
|
||||
-- doors mod among other thing does NOT like a nil digger...
|
||||
local fakedigger = pipeworks.create_fake_player({
|
||||
name = owner
|
||||
})
|
||||
if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, fakedigger)) then
|
||||
can_dig = false
|
||||
end
|
||||
end
|
||||
|
||||
if can_dig then
|
||||
for ay = startpos.y, digpos.y+1, -1 do
|
||||
local checkpos = {x=digpos.x, y=ay, z=digpos.z}
|
||||
local checknode = technic.get_or_load_node(checkpos) or minetest.get_node(checkpos)
|
||||
if checknode.name ~= "air" then
|
||||
can_dig = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
nd = nd + 1
|
||||
if can_dig then
|
||||
|
||||
local dignode = quarry_can_dig_node(startpos, digpos, owner)
|
||||
if dignode then
|
||||
minetest.remove_node(digpos)
|
||||
local drops = minetest.get_node_drops(dignode.name, "")
|
||||
for _, dropped_item in ipairs(drops) do
|
||||
|
@ -5,9 +5,9 @@ local chainsaw_max_charge = 30000 -- Maximum charge of the saw
|
||||
-- if this is disabled.
|
||||
local chainsaw_leaves = true
|
||||
|
||||
local chainsaw_efficiency = 0.95 -- Drops less items
|
||||
local chainsaw_efficiency = 0.92 -- Drops less items
|
||||
|
||||
-- Maximal dimensions of the tree to cut
|
||||
-- Maximal dimensions of the tree to cut (giant sequoia)
|
||||
local tree_max_radius = 10
|
||||
local tree_max_height = 70
|
||||
|
||||
@ -39,12 +39,16 @@ local tree_nodes = {
|
||||
["ethereal:bamboo"] = -1,
|
||||
}
|
||||
|
||||
local tree_nodes_by_cid = {
|
||||
-- content ID indexed table, data populated on mod load.
|
||||
-- Format: [node_name] = cost_number
|
||||
}
|
||||
|
||||
-- Function to decide whether or not to cut a certain node (and at which energy cost)
|
||||
local function populate_costs(name, def)
|
||||
repeat
|
||||
if tree_nodes[name] == -1 then
|
||||
tree_nodes[name] = nil
|
||||
break -- Manually added, but need updating
|
||||
if tree_nodes[name] then
|
||||
break -- Manually specified node to chop
|
||||
end
|
||||
if (def.groups.tree or 0) > 0 then
|
||||
break -- Tree node
|
||||
@ -61,17 +65,18 @@ local function populate_costs(name, def)
|
||||
until 1
|
||||
-- luacheck: pop
|
||||
|
||||
-- Function did not return! --> add content ID to the digging table
|
||||
-- Add the node cost to the content ID indexed table
|
||||
local content_id = minetest.get_content_id(name)
|
||||
|
||||
-- Get 12 in average
|
||||
local cost = 0
|
||||
-- Make it so that the giant sequoia can be cut with a full charge
|
||||
local cost = tree_nodes[name] or 0
|
||||
if def.groups.choppy then
|
||||
cost = def.groups.choppy * 5 -- trunks (usually 3 * 5)
|
||||
elseif def.groups.snappy then
|
||||
cost = def.groups.snappy * 2 -- leaves
|
||||
cost = math.max(cost, def.groups.choppy * 14) -- trunks (usually 3 * 14)
|
||||
end
|
||||
tree_nodes[content_id] = math.max(4, cost)
|
||||
if def.groups.snappy then
|
||||
cost = math.max(cost, def.groups.snappy * 2) -- leaves
|
||||
end
|
||||
tree_nodes_by_cid[content_id] = math.max(4, cost)
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
@ -111,6 +116,7 @@ local cutter = {
|
||||
-- See function cut_tree()
|
||||
}
|
||||
|
||||
local safe_cut = minetest.settings:get_bool("technic_safe_chainsaw") ~= false
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local function dig_recursive(x, y, z)
|
||||
local i = cutter.area:index(x, y, z)
|
||||
@ -119,13 +125,14 @@ local function dig_recursive(x, y, z)
|
||||
end
|
||||
cutter.seen[i] = 1 -- Mark as visited
|
||||
|
||||
if cutter.param2[i] ~= 0 then
|
||||
if safe_cut and cutter.param2[i] ~= 0 then
|
||||
-- Do not dig manually placed nodes
|
||||
-- Problem: moretrees' generated jungle trees use param2 = 2
|
||||
return
|
||||
end
|
||||
|
||||
local c_id = cutter.data[i]
|
||||
local cost = tree_nodes[c_id]
|
||||
local cost = tree_nodes_by_cid[c_id]
|
||||
if not cost or cost > cutter.charge then
|
||||
return -- Cannot dig this node
|
||||
end
|
||||
|
Reference in New Issue
Block a user