Make the quarry consume struts

This commit is contained in:
Valentin Anger 2019-10-02 02:36:49 +02:00 committed by Pascal Abresch
parent a07cf3a8f1
commit c0e0d2f696

View File

@ -36,6 +36,23 @@ local function try_drain_energy(target_pos, amount) ---
end end
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) local function on_construct(pos, player)
player:get_meta():set_string(NAME .. ":quarry_pos" , minetest.pos_to_string(pos)) player:get_meta():set_string(NAME .. ":quarry_pos" , minetest.pos_to_string(pos))
@ -133,13 +150,19 @@ end
local function place_strut(position, quarrypos) local function place_strut(position, quarrypos)
if minetest.get_node(position).name == "air" then if minetest.get_node(position).name == "air" then
if try_drain_energy(quarrypos, ENERGYCOST.static_strut) then minetest.debug("PLACE")
minetest.set_node(position, { name = NAME .. ":static_strut"}) 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 end
return true return true
else
return false
end end
return false
end end