Make the quarry consume struts
This commit is contained in:
parent
a07cf3a8f1
commit
c0e0d2f696
@ -36,6 +36,23 @@ local function try_drain_energy(target_pos, amount) ---
|
||||
end
|
||||
end
|
||||
|
||||
local function try_remove_item(target_pos, listname, itemname, amount)
|
||||
local inv = minetest.get_inventory({type="node", pos=target_pos})
|
||||
local stack = ItemStack(itemname)
|
||||
local amount = amount or 1
|
||||
stack:set_count(amount)
|
||||
|
||||
local result = inv:remove_item(listname, stack)
|
||||
|
||||
if result:get_count() ~= amount then
|
||||
inv:add_item(listname, result)
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function on_construct(pos, player)
|
||||
player:get_meta():set_string(NAME .. ":quarry_pos" , minetest.pos_to_string(pos))
|
||||
|
||||
@ -133,13 +150,19 @@ end
|
||||
|
||||
local function place_strut(position, quarrypos)
|
||||
if minetest.get_node(position).name == "air" then
|
||||
minetest.debug("PLACE")
|
||||
if try_remove_item(quarrypos, "quarry", NAME .. ":static_strut") then
|
||||
minetest.debug("ENERGY")
|
||||
if try_drain_energy(quarrypos, ENERGYCOST.static_strut) then
|
||||
minetest.debug("CONFIRM")
|
||||
minetest.set_node(position, { name = NAME .. ":static_strut"})
|
||||
else
|
||||
-- Restore items
|
||||
end
|
||||
end
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user