Bucket now uses Node IO endpoints

This commit is contained in:
Evert Prants 2018-08-22 17:06:07 +03:00
parent a587717bd8
commit 4237ff7206
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -110,20 +110,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
local ppos = pointed_thing.under local ppos = pointed_thing.under
local buffers = fluid_lib.get_node_buffers(ppos) local node = minetest.get_node(ppos)
if buffers then if ndef.node_io_can_put_liquid and ndef.node_io_can_put_liquid(ppos, node, "") then
for buffer in pairs(buffers) do if ndef.node_io_room_for_liquid(ppos, node, "", source, 1000) >= 1000 then
if fluid_lib.can_insert_into_buffer(ppos, buffer, source, 1000) == 1000 then ndef.node_io_put_liquid(ppos, node, "", nil, source, 1000)
fluid_lib.insert_into_buffer(ppos, buffer, source, 1000)
if ndef.on_timer then if ndef.on_timer then
minetest.get_node_timer(ppos):start(ndef.node_timer_seconds or 1.0) minetest.get_node_timer(ppos):start(ndef.node_timer_seconds or 1.0)
end end
place = false place = false
break
end
end
end end
end end
@ -248,23 +243,30 @@ minetest.register_craftitem("bucket:bucket_empty", {
itemstack = ItemStack("bucket:bucket_empty") itemstack = ItemStack("bucket:bucket_empty")
-- Remove fluid from buffers if present -- Remove fluid from buffers if present
if ndef.fluid_buffers then if ndef.node_io_can_take_liquid and ndef.node_io_can_take_liquid(lpos, node, "") then
local buffers = fluid_lib.get_node_buffers(lpos) local bfc = ndef.node_io_get_liquid_size(lpos, node, "")
if buffers then local buffers = {}
for buffer in pairs(buffers) do for i = 1, bfc do
if fluid_lib.can_take_from_buffer(lpos, buffer, 1000) == 1000 then buffers[i] = ndef.node_io_get_liquid_name(lpos, node, "", i)
local fluid = fluid_lib.take_from_buffer(lpos, buffer, 1000) end
if #buffers > 0 then
for id,fluid in pairs(buffers) do
if fluid ~= "" then
local took = ndef.node_io_take_liquid(lpos, node, "", nil, fluid, 1000)
if took.millibuckets == 1000 and took.name == fluid then
if bucket.liquids[fluid] then if bucket.liquids[fluid] then
itemstack = ItemStack(bucket.liquids[fluid].itemname) itemstack = ItemStack(bucket.liquids[fluid].itemname)
if ndef.on_timer then if ndef.on_timer then
minetest.get_node_timer(lpos):start(ndef.node_timer_seconds or 1.0) minetest.get_node_timer(lpos):start(ndef.node_timer_seconds or 1.0)
end end
end
break break
end end
end end
end end
end end
end
end
return itemstack return itemstack
end end