Pumps can now be upgraded to pump Heavy Water

This commit is contained in:
Evert Prants 2018-12-18 21:04:09 +02:00
parent 2ce8339f6f
commit 3e9a13f10c
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 37 additions and 5 deletions

View File

@ -42,7 +42,7 @@ minetest.register_craftitem("elepower_machines:super_capacitor", {
minetest.register_craftitem("elepower_machines:heavy_filter", { minetest.register_craftitem("elepower_machines:heavy_filter", {
description = "Liquid Weight Filter\nMakes water pumps pump only Heavy Water\nRight-Click to apply to Water Accumulator", description = "Liquid Weight Filter\nMakes water pumps pump only Heavy Water\nRight-Click to apply to Water Accumulator",
groups = {accumulator_filter = 1}, groups = {accumulator_filter = 1, pump_filter = 2, ele_upgrade_component = 1},
inventory_image = "elepower_accumulator_filter.png", inventory_image = "elepower_accumulator_filter.png",
on_place = function (itemstack, placer, pointed_thing) on_place = function (itemstack, placer, pointed_thing)
if not placer or not placer:is_player() then return itemstack end if not placer or not placer:is_player() then return itemstack end

View File

@ -59,6 +59,7 @@ local function timer(pos, elapsed)
local usage = ele.helpers.get_node_property(meta, pos, "usage") local usage = ele.helpers.get_node_property(meta, pos, "usage")
local storage = ele.helpers.get_node_property(meta, pos, "storage") local storage = ele.helpers.get_node_property(meta, pos, "storage")
local state = meta:get_int("state") local state = meta:get_int("state")
local comps = meta:get_string("components")
local status = "Idle" local status = "Idle"
local is_enabled = ele.helpers.state_enabled(meta, pos, state) local is_enabled = ele.helpers.state_enabled(meta, pos, state)
@ -73,6 +74,8 @@ local function timer(pos, elapsed)
local ppos = vector.add(pos, {x=0,y=plevel,z=0}) local ppos = vector.add(pos, {x=0,y=plevel,z=0})
local heavy = comps:match("elepower_machines:heavy_filter") ~= nil
while true do while true do
if not is_enabled then if not is_enabled then
status = "Off" status = "Off"
@ -84,7 +87,14 @@ local function timer(pos, elapsed)
break break
end end
if fl_buffer.amount + 1000 > fl_buffer.capacity then local dig_node = fl_buffer.fluid
local amount = 1000
if fl_buffer.fluid == "elepower_nuclear:heavy_water_source" and heavy then
dig_node = "default:water_source"
amount = 200
end
if fl_buffer.amount + amount > fl_buffer.capacity then
status = "Tank Full!" status = "Tank Full!"
break break
end end
@ -103,6 +113,10 @@ local function timer(pos, elapsed)
-- Valid liquid, proceed pumping -- Valid liquid, proceed pumping
if bucket.liquids[node.name] and bucket.liquids[node.name].source == node.name then if bucket.liquids[node.name] and bucket.liquids[node.name].source == node.name then
if node.name == "default:water_source" and heavy then
node.name = "elepower_nuclear:heavy_water_source"
end
fl_buffer.fluid = node.name fl_buffer.fluid = node.name
refresh = true refresh = true
else else
@ -112,12 +126,24 @@ local function timer(pos, elapsed)
end end
if fl_buffer.fluid ~= "" then if fl_buffer.fluid ~= "" then
-- Filter was installed
if fl_buffer.fluid == "default:water_source" and heavy and fl_buffer.amount > 0 then
fl_buffer.fluid = "elepower_nuclear:heavy_water_source"
fl_buffer.amount = 0
refresh = true
break
end
-- We are looking for `fl_buffer.fluid` on Y level `plevel` -- We are looking for `fl_buffer.fluid` on Y level `plevel`
-- If we find a fluid node, we dig it, and add it to the buffer's storage -- If we find a fluid node, we dig it, and add it to the buffer's storage
-- If we don't find a fluid node, we go a level down -- If we don't find a fluid node, we go a level down
local dug = dig_node_leveled_radius(ppos, 16, fl_buffer.fluid) local dug = dig_node_leveled_radius(ppos, 16, dig_node)
if not dug then if not dug then
local node = minetest.get_node_or_nil(ppos) local node = minetest.get_node_or_nil(ppos)
if node.name == "default:water_source" and heavy then
node.name = "elepower_nuclear:heavy_water_source"
end
if not node or (node.name ~= fl_buffer.fluid and node.name ~= "air") then if not node or (node.name ~= fl_buffer.fluid and node.name ~= "air") then
status = "No More Fluid!" status = "No More Fluid!"
refresh = false refresh = false
@ -131,7 +157,7 @@ local function timer(pos, elapsed)
end end
break break
else else
fl_buffer.amount = fl_buffer.amount + 1000 fl_buffer.amount = fl_buffer.amount + amount
pow_buffer.usage = usage pow_buffer.usage = usage
pow_buffer.storage = pow_buffer.storage - usage pow_buffer.storage = pow_buffer.storage - usage
status = "Pumping" status = "Pumping"
@ -200,7 +226,12 @@ ele.register_machine("elepower_machines:pump", {
on_construct = function (pos) on_construct = function (pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", nil, nil, 0, -1) meta:set_string("formspec", nil, nil, 0, -1)
end end,
-- Upgradable
ele_upgrades = {
pump_filter = {},
capacitor = {"capacity"},
},
}) })
minetest.register_entity("elepower_machines:pump_tube", { minetest.register_entity("elepower_machines:pump_tube", {

View File

@ -3,6 +3,7 @@
local dict = { local dict = {
machine_chip = "Machine Chip", machine_chip = "Machine Chip",
capacitor = "Capacitor", capacitor = "Capacitor",
pump_filter = "Pump Filter",
} }
local function upgrade_formspec (upgrades, desc) local function upgrade_formspec (upgrades, desc)