1 -- Minetest 0.4 mod: bucket
2 -- See README.txt for licensing and other information.
4 minetest.register_alias("bucket", "bucket:bucket_empty")
5 minetest.register_alias("bucket_water", "bucket:bucket_water")
6 minetest.register_alias("bucket_lava", "bucket:bucket_lava")
8 minetest.register_craft({
9 output = 'bucket:bucket_empty 1',
11 {'default:steel_ingot', '', 'default:steel_ingot'},
12 {'', 'default:steel_ingot', ''},
19 local function check_protection(pos, name, text)
20 if minetest.is_protected(pos, name) then
21 minetest.log("action", (name ~= "" and name or "A mod")
22 .. " tried to " .. text
23 .. " at protected position "
24 .. minetest.pos_to_string(pos)
26 minetest.record_protection_violation(pos, name)
32 -- Register a new liquid
33 -- source = name of the source node
34 -- flowing = name of the flowing node
35 -- itemname = name of the new bucket item (or nil if liquid is not takeable)
36 -- inventory_image = texture of the new bucket item (ignored if itemname == nil)
37 -- name = text description of the bucket item
38 -- groups = (optional) groups of the bucket item, for example {water_bucket = 1}
39 -- This function can be called from any mod (that depends on bucket).
40 function bucket.register_liquid(source, flowing, itemname, inventory_image, name, groups)
41 bucket.liquids[source] = {
46 bucket.liquids[flowing] = bucket.liquids[source]
48 if itemname ~= nil then
49 minetest.register_craftitem(itemname, {
51 inventory_image = inventory_image,
53 liquids_pointable = true,
56 on_place = function(itemstack, user, pointed_thing)
57 -- Must be pointing to node
58 if pointed_thing.type ~= "node" then
62 local node = minetest.get_node_or_nil(pointed_thing.under)
63 local ndef = node and minetest.registered_nodes[node.name]
65 -- Call on_rightclick if the pointed node defines it
66 if ndef and ndef.on_rightclick and
67 user and not user:get_player_control().sneak then
68 return ndef.on_rightclick(
76 -- Check if pointing to a buildable node
77 if ndef and ndef.buildable_to then
78 -- buildable; replace the node
79 lpos = pointed_thing.under
81 -- not buildable to; place the liquid above
82 -- check if the node above can be replaced
83 lpos = pointed_thing.above
84 local node = minetest.get_node_or_nil(lpos)
85 local above_ndef = node and minetest.registered_nodes[node.name]
87 if not above_ndef or not above_ndef.buildable_to then
88 -- do not remove the bucket with the liquid
93 if check_protection(lpos, user
94 and user:get_player_name()
95 or "", "place "..source) then
99 minetest.set_node(lpos, {name = source})
100 return ItemStack("bucket:bucket_empty")
106 minetest.register_craftitem("bucket:bucket_empty", {
107 description = "Empty Bucket",
108 inventory_image = "bucket.png",
110 liquids_pointable = true,
111 on_use = function(itemstack, user, pointed_thing)
112 -- Must be pointing to node
113 if pointed_thing.type ~= "node" then
116 -- Check if pointing to a liquid source
117 local node = minetest.get_node(pointed_thing.under)
118 local liquiddef = bucket.liquids[node.name]
119 local item_count = user:get_wielded_item():get_count()
122 and liquiddef.itemname ~= nil
123 and node.name == liquiddef.source then
124 if check_protection(pointed_thing.under,
125 user:get_player_name(),
126 "take ".. node.name) then
130 -- default set to return filled bucket
131 local giving_back = liquiddef.itemname
133 -- check if holding more than 1 empty bucket
134 if item_count > 1 then
136 -- if space in inventory add filled bucked, otherwise drop as item
137 local inv = user:get_inventory()
138 if inv:room_for_item("main", {name=liquiddef.itemname}) then
139 inv:add_item("main", liquiddef.itemname)
141 local pos = user:getpos()
142 pos.y = math.floor(pos.y + 0.5)
143 core.add_item(pos, liquiddef.itemname)
146 -- set to return empty buckets minus 1
147 giving_back = "bucket:bucket_empty "..tostring(item_count-1)
151 minetest.add_node(pointed_thing.under, {name="air"})
153 return ItemStack(giving_back)
158 bucket.register_liquid(
159 "default:water_source",
160 "default:water_flowing",
161 "bucket:bucket_water",
167 bucket.register_liquid(
168 "default:river_water_source",
169 "default:river_water_flowing",
170 "bucket:bucket_river_water",
171 "bucket_river_water.png",
172 "River Water Bucket",
176 bucket.register_liquid(
177 "default:lava_source",
178 "default:lava_flowing",
179 "bucket:bucket_lava",
184 minetest.register_craft({
186 recipe = "bucket:bucket_lava",
188 replacements = {{"bucket:bucket_lava", "bucket:bucket_empty"}},