Replace last empty tank with a single full tank on recharge (#4)

This commit is contained in:
Kevin Sangeelee 2020-05-08 08:43:44 +01:00 committed by GitHub
parent 33db7c7924
commit b44be3b184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,9 +57,14 @@ local function recharge_airtank(itemstack, user, pointed_thing, full_item)
itemstack:set_wear(0)
else
local inv = user:get_inventory()
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:set_count(itemstack:get_count()-1)
itemstack:take_item(1)
end
end
end
minetest.sound_play("airtanks_compressor", {pos = pointed_thing.under, gain = 0.5})
@ -248,3 +253,4 @@ local function player_event_handler(player, eventname)
end
minetest.register_playerevent(player_event_handler)