Skip to content

Commit

Permalink
Replace last empty tank with a single full tank on recharge (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Sangeelee committed May 8, 2020
1 parent 33db7c7 commit b44be3b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)

0 comments on commit b44be3b

Please sign in to comment.