This commit is contained in:
Evert Prants 2018-06-20 17:05:41 +03:00
parent 03ff573adb
commit 12867e4e5e
No known key found for this signature in database
GPG Key ID: 1688DA83D222D0B5
3 changed files with 33 additions and 28 deletions

@ -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. 1. Add the node to the `fluid_container` group.
2. Add the following to the node defintion: 2. Add the following to the node defintion:
``` ```
fluid_buffers = { fluid_buffers = {
buffer_name = { buffer_name = {
capacity = 2000, capacity = 2000,
accepts = {"default:water_source", "group:water_source"}, -- you can also set this to true to accept any fluid! accepts = {"default:water_source", "group:water_source"}, -- you can also set this to true to accept any fluid!
drainable = true, drainable = true,
}, },
} }
``` ```
3. Set the appropriate metadata. 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)` * `fluid_lib.get_buffer_data(pos, buffer)`
* Returns all the information about this buffer. * Returns all the information about this buffer.
``` ```
{ {
fluid = fluid source block, fluid = fluid source block,
amount = amount of fluid, amount = amount of fluid,
accepts = list of accepted fluids, accepts = list of accepted fluids,
capacity = capacity of the buffer, capacity = capacity of the buffer,
drainable = is this buffer drainable, drainable = is this buffer drainable,
} }
``` ```
* `fluid_lib.buffer_accepts_fluid(pos, buffer, fluid)` * `fluid_lib.buffer_accepts_fluid(pos, buffer, fluid)`

@ -111,12 +111,15 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
-- Fill any fluid buffers if present -- Fill any fluid buffers if present
local place = true local place = true
if ndef.fluid_buffers then if ndef.fluid_buffers then
local buffers = fluid_lib.get_node_buffers(lpos) local ppos = pointed_thing.under
for buffer in pairs(buffers) do local buffers = fluid_lib.get_node_buffers(ppos)
if fluid_lib.can_insert_into_buffer(lpos, buffer, source, 1000) == 1000 then if buffers then
fluid_lib.insert_into_buffer(lpos, buffer, source, 1000) for buffer in pairs(buffers) do
place = false if fluid_lib.can_insert_into_buffer(ppos, buffer, source, 1000) == 1000 then
break fluid_lib.insert_into_buffer(ppos, buffer, source, 1000)
place = false
break
end
end end
end end
end end
@ -222,7 +225,7 @@ minetest.register_craftitem("bucket:bucket_empty", {
if check_protection(lpos, user if check_protection(lpos, user
and user:get_player_name() and user:get_player_name()
or "", "take "..source) then or "", "take "..node.name) then
return return
end end
@ -231,13 +234,15 @@ minetest.register_craftitem("bucket:bucket_empty", {
-- Remove fluid from buffers if present -- Remove fluid from buffers if present
if ndef.fluid_buffers then if ndef.fluid_buffers then
local buffers = fluid_lib.get_node_buffers(lpos) local buffers = fluid_lib.get_node_buffers(lpos)
for buffer in pairs(buffers) do if buffers then
if fluid_lib.can_take_from_buffer(lpos, buffer, 1000) == 1000 then for buffer in pairs(buffers) do
local fluid = fluid_lib.take_from_buffer(lpos, buffer, 1000) if fluid_lib.can_take_from_buffer(lpos, buffer, 1000) == 1000 then
if bucket.liquids[fluid] then local fluid = fluid_lib.take_from_buffer(lpos, buffer, 1000)
itemstack = ItemStack(bucket.liquids[fluid].itemname) if bucket.liquids[fluid] then
itemstack = ItemStack(bucket.liquids[fluid].itemname)
end
break
end end
break
end end
end end
end end

@ -69,7 +69,7 @@ end
function fluid_lib.can_insert_into_buffer(pos, buffer, fluid, count) function fluid_lib.can_insert_into_buffer(pos, buffer, fluid, count)
local bfdata = fluid_lib.get_buffer_data(pos, buffer) local bfdata = fluid_lib.get_buffer_data(pos, buffer)
if not bfdata then return 0 end 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 local can_put = 0
if bfdata.amount + count > bfdata.capacity then if bfdata.amount + count > bfdata.capacity then