mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
add inventory.get_uses, inventory.use, item.uses & update base:bazalt_breaker
This commit is contained in:
parent
231fc7e0d0
commit
bbfc0dbf17
5 changed files with 40 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"icon-type": "sprite",
|
||||
"icon": "items:bazalt_breaker"
|
||||
"icon": "items:bazalt_breaker",
|
||||
"uses": 100
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
function on_block_break_by(x, y, z, p)
|
||||
function on_block_break_by(x, y, z, pid)
|
||||
block.set(x, y, z, 0, 0)
|
||||
inventory.use(player.get_inventory(pid))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -497,3 +497,28 @@ end
|
|||
function file.prefix(path)
|
||||
return path:match("^([^:]+)")
|
||||
end
|
||||
|
||||
function inventory.get_uses(invid, slot)
|
||||
local uses = inventory.get_data(invid, slot, "uses")
|
||||
if uses == nil then
|
||||
return item.uses(inventory.get(invid, slot))
|
||||
end
|
||||
return uses
|
||||
end
|
||||
|
||||
|
||||
function inventory.use(invid, slot)
|
||||
local itemid, count = inventory.get(invid, slot)
|
||||
if itemid == nil then
|
||||
return
|
||||
end
|
||||
local item_uses = inventory.get_uses(invid, slot)
|
||||
if item_uses == nil then
|
||||
return
|
||||
end
|
||||
if item_uses == 1 then
|
||||
inventory.set(invid, slot, itemid, count - 1)
|
||||
elseif item_uses > 1 then
|
||||
inventory.set_data(invid, slot, "uses", item_uses - 1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue