mirror of
https://github.com/minetest-mods/technic.git
synced 2025-03-22 12:20:30 +01:00
Better check for node removal
This commit is contained in:
parent
02e24e3afd
commit
9db2602def
@ -32,12 +32,13 @@ local lawn_trimmer_charge_per_object = 25
|
|||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
local lawn_trimmer_mode_text = {
|
local lawn_trimmer_mode_text = {
|
||||||
S("immediately around the user"),
|
S("sweep a single block under the user"),
|
||||||
S("sweep 1 block wide"),
|
S("sweep 1 block around the user"),
|
||||||
S("sweep 2 blocks wide"),
|
S("sweep 2 blocks around the user"),
|
||||||
S("sweep 3 blocks wide")
|
S("sweep 3 blocks around the user")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local node_removed
|
||||||
|
|
||||||
-- Mode switcher for the tool
|
-- Mode switcher for the tool
|
||||||
local function lawn_trimmer_setmode(user, itemstack)
|
local function lawn_trimmer_setmode(user, itemstack)
|
||||||
@ -76,14 +77,14 @@ local function trim_the_lawn(itemstack, user)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if meta.charge > lawn_trimmer_charge_per_object then
|
if meta.charge < lawn_trimmer_charge_per_object then
|
||||||
|
return -- no charge for even a single node, aborting
|
||||||
|
end
|
||||||
|
|
||||||
minetest.sound_play("technic_lawn_trimmer", {
|
minetest.sound_play("technic_lawn_trimmer", {
|
||||||
to_player = user:get_player_name(),
|
to_player = user:get_player_name(),
|
||||||
gain = 0.4,
|
gain = 0.4,
|
||||||
})
|
})
|
||||||
else
|
|
||||||
return -- no charge for even a single node, aborting
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos = user:get_pos()
|
local pos = user:get_pos()
|
||||||
-- Defining the area for the search needs two positions
|
-- Defining the area for the search needs two positions
|
||||||
@ -103,14 +104,16 @@ local function trim_the_lawn(itemstack, user)
|
|||||||
-- find_node_near() and removing found nodes
|
-- find_node_near() and removing found nodes
|
||||||
local found_flora = minetest.find_nodes_in_area(start_pos, end_pos, {"group:flora"})
|
local found_flora = minetest.find_nodes_in_area(start_pos, end_pos, {"group:flora"})
|
||||||
for _, f in ipairs(found_flora) do
|
for _, f in ipairs(found_flora) do
|
||||||
-- Only dig the node if not protected, otherwise skip to the next one.
|
node_removed = false
|
||||||
if not minetest.is_protected(f, user:get_player_name()) then
|
-- Callback will set the flag to true if the node is dug successfully,
|
||||||
meta.charge = meta.charge - lawn_trimmer_charge_per_object
|
-- otherwise skip to the next one.
|
||||||
minetest.node_dig(f, minetest.get_node(f), user)
|
minetest.node_dig(f, minetest.get_node(f), user)
|
||||||
end
|
if node_removed then
|
||||||
|
meta.charge = meta.charge - lawn_trimmer_charge_per_object
|
||||||
-- Abort if no charge left for another node
|
-- Abort if no charge left for another node
|
||||||
if meta.charge < lawn_trimmer_charge_per_object then break end
|
if meta.charge < lawn_trimmer_charge_per_object then break end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- The charge won't expire in creative mode, but the tool still
|
-- The charge won't expire in creative mode, but the tool still
|
||||||
-- has to be charged prior to use
|
-- has to be charged prior to use
|
||||||
@ -121,6 +124,10 @@ local function trim_the_lawn(itemstack, user)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function check_removal(itemstack, user, node, digparams)
|
||||||
|
node_removed = true
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
-- Register the tool and its varieties in the game
|
-- Register the tool and its varieties in the game
|
||||||
technic.register_power_tool("technic:lawn_trimmer", lawn_trimmer_max_charge)
|
technic.register_power_tool("technic:lawn_trimmer", lawn_trimmer_max_charge)
|
||||||
@ -130,7 +137,9 @@ minetest.register_tool("technic:lawn_trimmer", {
|
|||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
on_refill = technic.refill_RE_charge,
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = trim_the_lawn
|
on_use = trim_the_lawn,
|
||||||
|
after_use = check_removal
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
@ -142,7 +151,8 @@ for i = 1, 4 do
|
|||||||
wear_represents = "technic_RE_charge",
|
wear_represents = "technic_RE_charge",
|
||||||
on_refill = technic.refill_RE_charge,
|
on_refill = technic.refill_RE_charge,
|
||||||
groups = {not_in_creative_inventory = 1},
|
groups = {not_in_creative_inventory = 1},
|
||||||
on_use = trim_the_lawn
|
on_use = trim_the_lawn,
|
||||||
|
after_use = check_removal
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user