1 -- Minetest 0.4 mod: bucket
2 -- See README.txt for licensing and other information.
4 local LIQUID_MAX = 8 --The number of water levels when liquid_finite is enabled
6 minetest.register_alias("bucket", "bucket:bucket_empty")
7 minetest.register_alias("bucket_water", "bucket:bucket_water")
8 minetest.register_alias("bucket_lava", "bucket:bucket_lava")
10 minetest.register_craft({
11 output = 'bucket:bucket_empty 1',
13 {'default:steel_ingot', '', 'default:steel_ingot'},
14 {'', 'default:steel_ingot', ''},
21 -- Register a new liquid
22 -- source = name of the source node
23 -- flowing = name of the flowing node
24 -- itemname = name of the new bucket item (or nil if liquid is not takeable)
25 -- inventory_image = texture of the new bucket item (ignored if itemname == nil)
26 -- This function can be called from any mod (that depends on bucket).
27 function bucket.register_liquid(source, flowing, itemname, inventory_image, name)
28 bucket.liquids[source] = {
33 bucket.liquids[flowing] = bucket.liquids[source]
35 if itemname ~= nil then
36 minetest.register_craftitem(itemname, {
38 inventory_image = inventory_image,
40 liquids_pointable = true,
41 groups = {not_in_creative_inventory=1},
42 on_place = function(itemstack, user, pointed_thing)
43 -- Must be pointing to node
44 if pointed_thing.type ~= "node" then
48 local place_liquid = function(pos, node, source, flowing, fullness)
49 if math.floor(fullness/128) == 1 or (not minetest.setting_getbool("liquid_finite")) then
50 minetest.env:add_node(pos, {name=source, param2=fullness})
52 elseif node.name == flowing then
53 fullness = fullness + node.param2
54 elseif node.name == source then
58 if fullness >= LIQUID_MAX then
59 minetest.env:add_node(pos, {name=source, param2=LIQUID_MAX})
61 minetest.env:add_node(pos, {name=flowing, param2=fullness})
65 -- Check if pointing to a buildable node
66 local node = minetest.env:get_node(pointed_thing.under)
67 local fullness = tonumber(itemstack:get_metadata())
68 if not fullness then fullness = LIQUID_MAX end
70 if minetest.registered_nodes[node.name].buildable_to then
71 -- buildable; replace the node
72 place_liquid(pointed_thing.under, node, source, flowing, fullness)
74 -- not buildable to; place the liquid above
75 -- check if the node above can be replaced
76 local node = minetest.env:get_node(pointed_thing.above)
77 if minetest.registered_nodes[node.name].buildable_to then
78 place_liquid(pointed_thing.above, node, source, flowing, fullness)
80 -- do not remove the bucket with the liquid
84 return {name="bucket:bucket_empty"}
90 minetest.register_craftitem("bucket:bucket_empty", {
91 description = "Empty Bucket",
92 inventory_image = "bucket.png",
94 liquids_pointable = true,
95 on_use = function(itemstack, user, pointed_thing)
96 -- Must be pointing to node
97 if pointed_thing.type ~= "node" then
100 -- Check if pointing to a liquid source
101 node = minetest.env:get_node(pointed_thing.under)
102 liquiddef = bucket.liquids[node.name]
103 if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or
104 (node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then
106 minetest.env:add_node(pointed_thing.under, {name="air"})
108 if node.name == liquiddef.source then node.param2 = LIQUID_MAX end
109 return ItemStack({name = liquiddef.itemname, metadata = tostring(node.param2)})
114 bucket.register_liquid(
115 "default:water_source",
116 "default:water_flowing",
117 "bucket:bucket_water",
122 bucket.register_liquid(
123 "default:lava_source",
124 "default:lava_flowing",
125 "bucket:bucket_lava",
130 minetest.register_craft({
132 recipe = "bucket:bucket_lava",
134 replacements = {{"bucket:bucket_lava", "bucket:bucket_empty"}},