@@ -103,31 +103,55 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
103
103
end
104
104
105
105
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
125
149
126
- minetest .add_node (pointed_thing .under , {name = " air" })
150
+ minetest .add_node (pointed_thing .under , {name = " air" })
127
151
128
- return ItemStack (liquiddef . itemname )
129
- end
130
- end ,
152
+ return ItemStack (giving_back )
153
+ end
154
+ end ,
131
155
})
132
156
133
157
bucket .register_liquid (
2 commit comments
PilzAdam commentedon Mar 3, 2015
This code has wrong indentation.
ShadowNinja commentedon Mar 8, 2015
794a436