mirror of
https://github.com/minetest-mods/airtanks.git
synced 2024-12-26 06:07:28 +01:00
Replace last empty tank with a single full tank on recharge (#4)
This commit is contained in:
parent
33db7c7924
commit
b44be3b184
14
init.lua
14
init.lua
@ -57,9 +57,14 @@ local function recharge_airtank(itemstack, user, pointed_thing, full_item)
|
||||
itemstack:set_wear(0)
|
||||
else
|
||||
local inv = user:get_inventory()
|
||||
local leftover = inv:add_item("main", full_item)
|
||||
if leftover:get_count() == 0 then
|
||||
itemstack:set_count(itemstack:get_count()-1)
|
||||
|
||||
if itemstack:get_count() == 1 then
|
||||
itemstack = ItemStack(full_item) -- replace with new stack containing one full tank
|
||||
else
|
||||
local leftover = inv:add_item("main", full_item)
|
||||
if leftover:get_count() == 0 then
|
||||
itemstack:take_item(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.sound_play("airtanks_compressor", {pos = pointed_thing.under, gain = 0.5})
|
||||
@ -247,4 +252,5 @@ local function player_event_handler(player, eventname)
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_playerevent(player_event_handler)
|
||||
minetest.register_playerevent(player_event_handler)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user