Skip to content

Commit df35360

Browse files
tenplus1BlockMen
authored andcommittedFeb 28, 2015
Make empty buckets stackable
1 parent 3e912f7 commit df35360

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed
 

‎mods/bucket/init.lua

+47-23
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,55 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
103103
end
104104

105105
minetest.register_craftitem("bucket:bucket_empty", {
106-
description = "Empty Bucket",
107-
inventory_image = "bucket.png",
108-
stack_max = 1,
109-
liquids_pointable = true,
110-
on_use = function(itemstack, user, pointed_thing)
111-
-- Must be pointing to node
112-
if pointed_thing.type ~= "node" then
113-
return
114-
end
115-
-- Check if pointing to a liquid source
116-
local node = minetest.get_node(pointed_thing.under)
117-
local liquiddef = bucket.liquids[node.name]
118-
if liquiddef ~= nil and liquiddef.itemname ~= nil and
119-
node.name == liquiddef.source then
120-
if check_protection(pointed_thing.under,
121-
user:get_player_name(),
122-
"take ".. node.name) then
123-
return
124-
end
106+
description = "Empty Bucket",
107+
inventory_image = "bucket.png",
108+
stack_max = 99,
109+
liquids_pointable = true,
110+
on_use = function(itemstack, user, pointed_thing)
111+
-- Must be pointing to node
112+
if pointed_thing.type ~= "node" then
113+
return
114+
end
115+
-- Check if pointing to a liquid source
116+
local node = minetest.get_node(pointed_thing.under)
117+
local liquiddef = bucket.liquids[node.name]
118+
local item_count = user:get_wielded_item():get_count()
119+
120+
if liquiddef ~= nil
121+
and liquiddef.itemname ~= nil
122+
and node.name == liquiddef.source then
123+
if check_protection(pointed_thing.under,
124+
user:get_player_name(),
125+
"take ".. node.name) then
126+
return
127+
end
128+
129+
-- default set to return filled bucket
130+
local giving_back = liquiddef.itemname
131+
132+
-- check if holding more than 1 empty bucket
133+
if item_count > 1 then
134+
135+
-- if space in inventory add filled bucked, otherwise drop as item
136+
local inv = user:get_inventory()
137+
if inv:room_for_item("main", {name=liquiddef.itemname}) then
138+
inv:add_item("main", liquiddef.itemname)
139+
else
140+
local pos = user:getpos()
141+
pos.y = math.floor(pos.y + 0.5)
142+
core.add_item(pos, liquiddef.itemname)
143+
end
144+
145+
-- set to return empty buckets minus 1
146+
giving_back = "bucket:bucket_empty "..tostring(item_count-1)
147+
148+
end
125149

126-
minetest.add_node(pointed_thing.under, {name="air"})
150+
minetest.add_node(pointed_thing.under, {name="air"})
127151

128-
return ItemStack(liquiddef.itemname)
129-
end
130-
end,
152+
return ItemStack(giving_back)
153+
end
154+
end,
131155
})
132156

133157
bucket.register_liquid(

2 commit comments

Comments
 (2)

PilzAdam commented on Mar 3, 2015

@PilzAdam
Contributor

This code has wrong indentation.

ShadowNinja commented on Mar 8, 2015

@ShadowNinja
Contributor
Please sign in to comment.