diff --git a/README.md b/README.md index ad1579d..8e532c1 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ This API adds support for `fluid_buffers` inside nodes. This means that nodes ca 1. Add the node to the `fluid_container` group. 2. Add the following to the node defintion: ``` -fluid_buffers = { - buffer_name = { - capacity = 2000, - accepts = {"default:water_source", "group:water_source"}, -- you can also set this to true to accept any fluid! - drainable = true, - }, -} + fluid_buffers = { + buffer_name = { + capacity = 2000, + accepts = {"default:water_source", "group:water_source"}, -- you can also set this to true to accept any fluid! + drainable = true, + }, + } ``` 3. Set the appropriate metadata. @@ -27,13 +27,13 @@ All numbers are in **milli-buckets** (1 bucket = 1000 mB). * `fluid_lib.get_buffer_data(pos, buffer)` * Returns all the information about this buffer. ``` -{ - fluid = fluid source block, - amount = amount of fluid, - accepts = list of accepted fluids, - capacity = capacity of the buffer, - drainable = is this buffer drainable, -} + { + fluid = fluid source block, + amount = amount of fluid, + accepts = list of accepted fluids, + capacity = capacity of the buffer, + drainable = is this buffer drainable, + } ``` * `fluid_lib.buffer_accepts_fluid(pos, buffer, fluid)` diff --git a/bucket/init.lua b/bucket/init.lua index 6be8b8b..5e14a3e 100644 --- a/bucket/init.lua +++ b/bucket/init.lua @@ -111,12 +111,15 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name -- Fill any fluid buffers if present local place = true if ndef.fluid_buffers then - local buffers = fluid_lib.get_node_buffers(lpos) - for buffer in pairs(buffers) do - if fluid_lib.can_insert_into_buffer(lpos, buffer, source, 1000) == 1000 then - fluid_lib.insert_into_buffer(lpos, buffer, source, 1000) - place = false - break + local ppos = pointed_thing.under + local buffers = fluid_lib.get_node_buffers(ppos) + if buffers then + for buffer in pairs(buffers) do + if fluid_lib.can_insert_into_buffer(ppos, buffer, source, 1000) == 1000 then + fluid_lib.insert_into_buffer(ppos, buffer, source, 1000) + place = false + break + end end end end @@ -222,7 +225,7 @@ minetest.register_craftitem("bucket:bucket_empty", { if check_protection(lpos, user and user:get_player_name() - or "", "take "..source) then + or "", "take "..node.name) then return end @@ -231,13 +234,15 @@ minetest.register_craftitem("bucket:bucket_empty", { -- Remove fluid from buffers if present if ndef.fluid_buffers then local buffers = fluid_lib.get_node_buffers(lpos) - for buffer in pairs(buffers) do - if fluid_lib.can_take_from_buffer(lpos, buffer, 1000) == 1000 then - local fluid = fluid_lib.take_from_buffer(lpos, buffer, 1000) - if bucket.liquids[fluid] then - itemstack = ItemStack(bucket.liquids[fluid].itemname) + if buffers then + for buffer in pairs(buffers) do + if fluid_lib.can_take_from_buffer(lpos, buffer, 1000) == 1000 then + local fluid = fluid_lib.take_from_buffer(lpos, buffer, 1000) + if bucket.liquids[fluid] then + itemstack = ItemStack(bucket.liquids[fluid].itemname) + end + break end - break end end end diff --git a/fluid_lib/buffer.lua b/fluid_lib/buffer.lua index 92822f7..f89a1b6 100644 --- a/fluid_lib/buffer.lua +++ b/fluid_lib/buffer.lua @@ -69,7 +69,7 @@ end function fluid_lib.can_insert_into_buffer(pos, buffer, fluid, count) local bfdata = fluid_lib.get_buffer_data(pos, buffer) if not bfdata then return 0 end - if bfdata.fluid ~= fluid and bfdata.fluid ~= "" then return 0 end + if not fluid_lib.buffer_accepts_fluid(pos, buffer, fluid) then return 0 end local can_put = 0 if bfdata.amount + count > bfdata.capacity then