2018-06-19 09:16:43 +02:00
|
|
|
|
|
|
|
local CAPACITY = 8000
|
|
|
|
|
|
|
|
minetest.register_node("elepower_machines:accumulator", {
|
|
|
|
description = "Water Accumulator",
|
|
|
|
groups = {fluid_container = 1, oddly_breakable_by_hand = 1, cracky = 1},
|
|
|
|
tiles = {
|
2020-04-28 19:52:57 +02:00
|
|
|
"elepower_machine_top.png^elepower_power_port.png", "elepower_machine_base.png", "elepower_machine_side.png^elepower_machine_accumulator.png",
|
|
|
|
"elepower_machine_side.png^elepower_machine_accumulator.png", "elepower_machine_side.png^elepower_machine_accumulator.png",
|
|
|
|
"elepower_machine_side.png^elepower_machine_accumulator.png",
|
2018-06-19 09:16:43 +02:00
|
|
|
},
|
|
|
|
fluid_buffers = {
|
|
|
|
water = {
|
2018-12-14 20:19:37 +01:00
|
|
|
capacity = CAPACITY,
|
|
|
|
drainable = true,
|
2018-06-19 09:16:43 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
on_construct = function ( pos )
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("water_fluid", "default:water_source")
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2018-12-14 20:19:37 +01:00
|
|
|
minetest.register_node("elepower_machines:accumulator_heavy", {
|
|
|
|
description = "Water Accumulator (Heavy Water)",
|
|
|
|
groups = {fluid_container = 1, oddly_breakable_by_hand = 1, cracky = 1, not_in_creative_inventory = 1},
|
|
|
|
tiles = {
|
2020-04-28 19:52:57 +02:00
|
|
|
"elepower_machine_top.png^elepower_power_port.png", "elepower_machine_base.png", "elepower_machine_side.png^elepower_machine_accumulator.png",
|
|
|
|
"elepower_machine_side.png^elepower_machine_accumulator.png", "elepower_machine_side.png^elepower_machine_accumulator.png",
|
|
|
|
"elepower_machine_side.png^elepower_machine_accumulator.png",
|
2018-12-14 20:19:37 +01:00
|
|
|
},
|
|
|
|
drop = {
|
|
|
|
max_items = 2,
|
|
|
|
items = { { items = {"elepower_machines:accumulator", "elepower_machines:heavy_filter"}, rarity = 1 } }
|
|
|
|
},
|
|
|
|
fluid_buffers = {
|
|
|
|
water = {
|
|
|
|
capacity = CAPACITY,
|
|
|
|
drainable = true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
on_construct = function ( pos )
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("water_fluid", "elepower_nuclear:heavy_water_source")
|
|
|
|
end,
|
|
|
|
_heavy = true
|
|
|
|
})
|
|
|
|
|
2018-06-19 09:16:43 +02:00
|
|
|
minetest.register_abm({
|
2018-12-14 20:19:37 +01:00
|
|
|
nodenames = {"elepower_machines:accumulator", "elepower_machines:accumulator_heavy"},
|
2018-06-21 12:14:12 +02:00
|
|
|
label = "elefluidAccumulator",
|
|
|
|
interval = 2,
|
|
|
|
chance = 1/5,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local buffer = fluid_lib.get_buffer_data(pos, "water")
|
|
|
|
if not buffer or buffer.amount == buffer.capacity then return end
|
2018-06-19 09:16:43 +02:00
|
|
|
|
|
|
|
local positions = {
|
|
|
|
{x=pos.x+1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x-1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x, y=pos.y,z=pos.z+1},
|
|
|
|
{x=pos.x, y=pos.y,z=pos.z-1},
|
|
|
|
}
|
|
|
|
|
2018-06-21 12:14:12 +02:00
|
|
|
local amount = 0
|
2018-06-19 09:16:43 +02:00
|
|
|
for _,fpos in pairs(positions) do
|
|
|
|
local node = minetest.get_node(fpos)
|
|
|
|
if node.name == "default:water_source" then
|
2018-06-21 12:14:12 +02:00
|
|
|
amount = amount + 1000
|
2018-06-19 09:16:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-21 12:14:12 +02:00
|
|
|
if amount == 0 then
|
2018-06-19 09:16:43 +02:00
|
|
|
meta:set_string("infotext", "Submerge me in water!")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-12-14 20:19:37 +01:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
local src = "default:water_source"
|
|
|
|
if ndef and ndef._heavy then
|
|
|
|
src = "elepower_nuclear:heavy_water_source"
|
|
|
|
if amount > 1000 then
|
|
|
|
amount = math.floor(amount / 8)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-19 09:16:43 +02:00
|
|
|
local give = 0
|
2018-06-21 12:14:12 +02:00
|
|
|
if buffer.amount + amount > buffer.capacity then
|
|
|
|
give = buffer.capacity - buffer.amount
|
2018-06-19 09:16:43 +02:00
|
|
|
else
|
2018-06-21 12:14:12 +02:00
|
|
|
give = amount
|
2018-06-19 09:16:43 +02:00
|
|
|
end
|
|
|
|
|
2018-06-21 12:14:12 +02:00
|
|
|
buffer.amount = buffer.amount + give
|
2018-06-19 09:16:43 +02:00
|
|
|
|
2018-06-21 12:14:12 +02:00
|
|
|
meta:set_int("water_fluid_storage", buffer.amount)
|
2018-12-14 20:19:37 +01:00
|
|
|
meta:set_string("water_fluid", src)
|
2018-06-21 12:14:12 +02:00
|
|
|
meta:set_string("infotext", fluid_lib.buffer_to_string(buffer))
|
2018-06-19 09:16:43 +02:00
|
|
|
end
|
|
|
|
})
|
2018-08-24 21:36:15 +02:00
|
|
|
|
|
|
|
fluid_lib.register_node("elepower_machines:accumulator")
|
2018-12-14 20:19:37 +01:00
|
|
|
fluid_lib.register_node("elepower_machines:accumulator_heavy")
|