Skip to content

Commit 7b30c26

Browse files
committed
Bucket: Add optional 'force-renew' bool to registration
River water needs to be 'liquid_renewable = false' to avoid a mess caused by spreading of sources, however picking it up with a bucket then creates a hole in the river. Allow a 'force-renew' of the source node if it has a source neighbour.
1 parent 78311a2 commit 7b30c26

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

game_api.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ The bucket API allows registering new types of buckets for non-default liquids.
2626
"bucket:bucket_lava", -- name of the new bucket item (or nil if liquid is not takeable)
2727
"bucket_lava.png", -- texture of the new bucket item (ignored if itemname == nil)
2828
"Lava Bucket", -- text description of the bucket item
29-
{lava_bucket = 1} -- groups of the bucket item, OPTIONAL
29+
{lava_bucket = 1}, -- groups of the bucket item, OPTIONAL
30+
false -- force-renew, OPTIONAL. Force the liquid source to renew if it has
31+
-- a source neighbour, even if defined as 'liquid_renewable = false'.
32+
-- Needed to avoid creating holes in sloping rivers.
3033
)
3134

3235
Beds API

mods/bucket/init.lua

+17-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ end
3636
-- inventory_image = texture of the new bucket item (ignored if itemname == nil)
3737
-- name = text description of the bucket item
3838
-- groups = (optional) groups of the bucket item, for example {water_bucket = 1}
39+
-- force_renew = (optional) bool. Force the liquid source to renew if it has a
40+
-- source neighbour, even if defined as 'liquid_renewable = false'.
41+
-- Needed to avoid creating holes in sloping rivers.
3942
-- This function can be called from any mod (that depends on bucket).
40-
function bucket.register_liquid(source, flowing, itemname, inventory_image, name, groups)
43+
function bucket.register_liquid(source, flowing, itemname, inventory_image, name,
44+
groups, force_renew)
4145
bucket.liquids[source] = {
4246
source = source,
4347
flowing = flowing,
4448
itemname = itemname,
49+
force_renew = force_renew,
4550
}
4651
bucket.liquids[flowing] = bucket.liquids[source]
4752

@@ -149,7 +154,15 @@ minetest.register_craftitem("bucket:bucket_empty", {
149154

150155
end
151156

152-
minetest.add_node(pointed_thing.under, {name="air"})
157+
-- force_renew requires a source neighbour
158+
local source_neighbor = false
159+
if liquiddef.force_renew then
160+
source_neighbor =
161+
minetest.find_node_near(pointed_thing.under, 1, liquiddef.source)
162+
end
163+
if not (source_neighbor and liquiddef.force_renew) then
164+
minetest.add_node(pointed_thing.under, {name = "air"})
165+
end
153166

154167
return ItemStack(giving_back)
155168
end
@@ -171,7 +184,8 @@ bucket.register_liquid(
171184
"bucket:bucket_river_water",
172185
"bucket_river_water.png",
173186
"River Water Bucket",
174-
{water_bucket = 1}
187+
{water_bucket = 1},
188+
true
175189
)
176190

177191
bucket.register_liquid(

0 commit comments

Comments
 (0)