Bucket: Add optional 'force-renew' bool to registration
authorparamat <mat.gregory@virginmedia.com>
Sun, 9 Oct 2016 22:33:07 +0000 (23:33 +0100)
committerparamat <mat.gregory@virginmedia.com>
Wed, 12 Oct 2016 03:11:36 +0000 (04:11 +0100)
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.

game_api.txt
mods/bucket/init.lua

index a20ecd4f8baed49b3069edcbac7f7c5e9cc1c1da..f758499ff6e0eee04a5008128d22d94738270445 100644 (file)
@@ -26,7 +26,10 @@ The bucket API allows registering new types of buckets for non-default liquids.
                "bucket:bucket_lava",    -- name of the new bucket item (or nil if liquid is not takeable)
                "bucket_lava.png",       -- texture of the new bucket item (ignored if itemname == nil)
                "Lava Bucket",           -- text description of the bucket item
-               {lava_bucket = 1}        -- groups of the bucket item, OPTIONAL
+               {lava_bucket = 1},       -- groups of the bucket item, OPTIONAL
+               false                    -- force-renew, OPTIONAL. Force the liquid source to renew if it has
+                                        -- a source neighbour, even if defined as 'liquid_renewable = false'.
+                                        -- Needed to avoid creating holes in sloping rivers.
        )
 
 Beds API
index a7cb0f2715c02b877ff174d0ed402c1a96d155c0..638ce1f42c1d8b4ca5745865356e8cafcddb2a7c 100644 (file)
@@ -36,12 +36,17 @@ end
 --    inventory_image = texture of the new bucket item (ignored if itemname == nil)
 --    name = text description of the bucket item
 --    groups = (optional) groups of the bucket item, for example {water_bucket = 1}
+--    force_renew = (optional) bool. Force the liquid source to renew if it has a
+--                  source neighbour, even if defined as 'liquid_renewable = false'.
+--                  Needed to avoid creating holes in sloping rivers.
 -- This function can be called from any mod (that depends on bucket).
-function bucket.register_liquid(source, flowing, itemname, inventory_image, name, groups)
+function bucket.register_liquid(source, flowing, itemname, inventory_image, name,
+               groups, force_renew)
        bucket.liquids[source] = {
                source = source,
                flowing = flowing,
                itemname = itemname,
+               force_renew = force_renew,
        }
        bucket.liquids[flowing] = bucket.liquids[source]
 
@@ -149,7 +154,15 @@ minetest.register_craftitem("bucket:bucket_empty", {
 
                        end
 
-                       minetest.add_node(pointed_thing.under, {name="air"})
+                       -- force_renew requires a source neighbour
+                       local source_neighbor = false
+                       if liquiddef.force_renew then
+                               source_neighbor =
+                                       minetest.find_node_near(pointed_thing.under, 1, liquiddef.source)
+                       end
+                       if not (source_neighbor and liquiddef.force_renew) then
+                               minetest.add_node(pointed_thing.under, {name = "air"})
+                       end
 
                        return ItemStack(giving_back)
                end
@@ -171,7 +184,8 @@ bucket.register_liquid(
        "bucket:bucket_river_water",
        "bucket_river_water.png",
        "River Water Bucket",
-       {water_bucket = 1}
+       {water_bucket = 1},
+       true
 )
 
 bucket.register_liquid(