Common timer function, fusion reactor fix

This commit is contained in:
Evert Prants 2019-11-26 19:42:50 +02:00
parent 5013cfa0cb
commit 70674e2152
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
19 changed files with 142 additions and 99 deletions

View File

@ -117,6 +117,7 @@ function ele.register_fluid_generator(nodename, nodedef)
end
end
if burn_totaltime == 0 then burn_totaltime = 1 end
if flbuffer.fluid ~= "" and flbuffer.amount == 0 then flbuffer.fluid = "" end
break
end
@ -125,6 +126,7 @@ function ele.register_fluid_generator(nodename, nodedef)
meta:set_string("infotext", ("%s %s\n%s\n%s"):format(nodedef.description, status,
ele.capacity_text(capacity, pow_buffer.storage), fluid_lib.buffer_to_string(flbuffer)))
meta:set_string(buffer_name .. "_fluid", flbuffer.fluid)
meta:set_int(buffer_name .. "_fluid_storage", flbuffer.amount)
meta:set_int("storage", pow_buffer.storage)

View File

@ -134,7 +134,7 @@ local function get_fields(pos, formname, fields, sender)
meta:set_int("mode", fint)
end
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
end
ele.register_base_device("elepower_machines:bucketer", {

View File

@ -190,14 +190,6 @@ local function alloy_furnace_timer(pos, elapsed)
return result
end
local function metadata_inventory_changed(pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end
ele.register_base_device("elepower_machines:coal_alloy_furnace", {
description = "Coal-fired Alloy Furnace",
paramtype2 = "facedir",
@ -233,9 +225,9 @@ ele.register_base_device("elepower_machines:coal_alloy_furnace", {
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move,
on_metadata_inventory_move = metadata_inventory_changed,
on_metadata_inventory_take = metadata_inventory_changed,
on_metadata_inventory_put = metadata_inventory_changed,
on_metadata_inventory_move = ele.helpers.start_timer,
on_metadata_inventory_take = ele.helpers.start_timer,
on_metadata_inventory_put = ele.helpers.start_timer,
can_dig = can_dig,
on_timer = alloy_furnace_timer,
groups = {

View File

@ -165,7 +165,7 @@ ele.register_machine("elepower_machines:lava_cooler", {
if frecipe then
meta:set_string("recipe", frecipe)
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
end
end,
})

View File

@ -2,7 +2,7 @@
minetest.register_craft({
output = "elepower_mining:miner_controller",
recipe = {
{"elepower_dynamics:invar_gear", "elepower_dynamics:induction_coil_advanced", "elepower_dynamics:invar_gear"},
{"elepower_dynamics:servo_valve", "elepower_dynamics:soc", "fluid_transfer:fluid_duct"},
{"elepower_machines:resonant_capacitor", "elepower_machines:machine_block", "elepower_machines:resonant_capacitor"},
{"elepower_dynamics:viridisium_plate", "elepower_dynamics:lcd_panel", "elepower_dynamics:viridisium_plate"},
}
@ -12,7 +12,7 @@ minetest.register_craft({
output = "elepower_mining:miner_core",
recipe = {
{"default:steelblock", "elepower_dynamics:invar_gear", "default:steelblock"},
{"elepower_dynamics:invar_gear", "fluid_transfer:fluid_duct", "elepower_dynamics:invar_gear"},
{"elepower_dynamics:invar_gear", "elepower_dynamics:servo_valve", "elepower_dynamics:invar_gear"},
{"default:steelblock", "elepower_dynamics:invar_gear", "default:steelblock"},
}
})

View File

@ -573,7 +573,5 @@ minetest.register_lbm({
name = "elepower_nuclear:fission_core",
nodenames = {"elepower_nuclear:fission_core"},
run_at_every_load = true,
action = function (pos)
minetest.get_node_timer(pos):start(1.0)
end,
action = ele.helpers.start_timer,
})

View File

@ -23,7 +23,7 @@ local reactions = {
output = "elepower_nuclear:helium_plasma 2000", -- output fluid
power_ignite = 16000, -- ignition cost
power_upkeep = 1000, -- reaction sustain cost
time = 360, -- reaction time
time = 120, -- reaction time
}
}
@ -104,10 +104,7 @@ local function notify_controller_presence(posi, posj)
local meta = minetest.get_meta(pos)
meta:set_string("ctrl", posj)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(pos)
end
end
@ -119,7 +116,7 @@ local function controller_formspec(in1, in2, out, power, time, state)
(time)..":gui_furnace_arrow_fg.png^[transformR270]"
end
return "size[8,8.5]"..
return "size[8,3.25]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
@ -184,6 +181,7 @@ local function controller_timer(pos)
local time = meta:get_int("src_time")
local time_res = meta:get_int("src_time_max")
local state = meta:get_int("state")
-- Deuterium + Tritium -> Helium Plasma
while true do
@ -228,8 +226,8 @@ local function controller_timer(pos)
out_buffer.fluid = recipe.out:get_name()
out_buffer.amount = out_buffer.amount + recipe.out:get_count()
in1_buffer.amount = in1_buffer.amount - result.i1:get_count()
in2_buffer.amount = in2_buffer.amount - result.i2:get_count()
in1_buffer.amount = in1_buffer.amount - recipe.i1:get_count()
in2_buffer.amount = in2_buffer.amount - recipe.i2:get_count()
if in1_buffer.amount == 0 then
in1_buffer.fluid = ""
@ -263,7 +261,7 @@ local function controller_timer(pos)
pcrt = math.floor(100 * time / time_res)
end
meta:set_string("formspec", controller_formspec(in1_buffer, in2_buffer, out_buffer, pow_buffer, 0, pcrt))
meta:set_string("formspec", controller_formspec(in1_buffer, in2_buffer, out_buffer, pow_buffer, pcrt, state))
return refresh
end
@ -546,12 +544,7 @@ minetest.register_lbm({
name = "elepower_nuclear:fusion_reactors",
nodenames = {"elepower_nuclear:reactor_controller"},
run_at_every_load = true,
action = function (pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end,
action = ele.helpers.start_timer,
})
-- Define reactor structure with Content IDs

View File

@ -18,11 +18,11 @@ end
local heat_recipes = {
["elepower_nuclear:hot_coolant_source"] = {
out = "elepower_nuclear:coolant_source",
factor = 4,
factor = 8,
},
["elepower_nuclear:helium_plasma"] = {
out = "elepower_nuclear:helium",
factor = 8,
factor = 32,
},
}
@ -72,10 +72,21 @@ local function heat_exchanger_timer(pos)
end
end
if heat.fluid ~= "" and heat.amount == 0 then
heat.fluid = ""
change = true
end
if cold.fluid ~= "" and cold.amount == 0 then
cold.fluid = ""
change = true
end
break
end
if change then
meta:set_string("heat_fluid", heat.fluid)
meta:set_string("cold_fluid", cold.fluid)
meta:set_string("steam_fluid", "elepower_dynamics:steam")
@ -100,22 +111,22 @@ ele.register_machine("elepower_nuclear:heat_exchanger", {
groups = {cracky = 3, fluid_container = 1},
fluid_buffers = {
heat = {
capacity = 8000,
capacity = 16000,
accepts = {"elepower_nuclear:hot_coolant_source", "elepower_nuclear:helium_plasma"},
drainable = false,
},
cold = {
capacity = 8000,
capacity = 16000,
accepts = {"elepower_nuclear:coolant_source", "elepower_nuclear:helium"},
drainable = true,
},
water = {
capacity = 16000,
capacity = 64000,
accepts = {"default:water_source"},
drainable = false,
},
steam = {
capacity = 16000,
capacity = 64000,
drainable = true,
},
},

View File

@ -156,7 +156,7 @@ ele.register_base_device("elepower_nuclear:solar_neutron_activator", {
},
on_timer = on_timer,
on_punch = function (pos, node, puncher, pointed_thing)
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
minetest.node_punch(pos, node, puncher, pointed_thing)
end,
on_construct = function (pos)

View File

@ -39,6 +39,14 @@ function ele.helpers.get_item_group(name, grp)
return minetest.get_item_group(name, grp) > 0
end
function ele.helpers.start_timer(pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end
function ele.helpers.flatten(map)
local list = {}
for key, value in pairs(map) do

View File

@ -77,13 +77,7 @@ function ele.default.allow_metadata_inventory_take(pos, listname, index, stack,
return stack:get_count()
end
function ele.default.metadata_inventory_changed(pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end
ele.default.metadata_inventory_changed = ele.helpers.start_timer
-- State machine descriptions
ele.default.states = {
@ -141,10 +135,7 @@ local function retrieve_metadata(pos, placer, itemstack, pointed_thing)
elepm.handle_machine_upgrades(pos)
end
else
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(pos)
end
end
@ -161,7 +152,7 @@ local tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
return inv:add_item("src", stack)
end,
can_insert = function(pos, node, stack, direction)
@ -180,17 +171,17 @@ local tube = {
local tubelib_tube = {
on_pull_item = function(pos, side, player_name)
local meta = minetest.get_meta(pos)
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
return tubelib.get_item(meta, "dst")
end,
on_push_item = function(pos, side, item, player_name)
local meta = minetest.get_meta(pos)
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
return tubelib.put_item(meta, "src", item)
end,
on_unpull_item = function(pos, side, item, player_name)
local meta = minetest.get_meta(pos)
minetest.get_node_timer(pos):start(1.0)
ele.helpers.start_timer(pos)
return tubelib.put_item(meta, "dst", item)
end,
}
@ -205,12 +196,7 @@ local mesecons_def = {
local meta = minetest.get_meta(pos)
meta:set_int("signal_interrupt", 0)
end,
action_change = function (pos, node)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end,
action_change = ele.helpers.start_timer,
}
}
@ -235,10 +221,7 @@ local function switch_state(pos, state_def)
state = states[state + 1]
meta:set_int("state", state)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(pos)
end
-- Patch a table
@ -357,10 +340,7 @@ function ele.register_base_device(nodename, nodedef)
nodedef.node_io_put_item = function(pos, node, side, putter, itemstack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(pos)
return inv:add_item("src", itemstack)
end
nodedef.node_io_can_take_item = function(pos, node, side) return true end
@ -384,10 +364,7 @@ function ele.register_base_device(nodename, nodedef)
local inv = meta:get_inventory()
local stack = ItemStack(want_item)
stack:set_count(want_count)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(pos)
return inv:take_item("dst", stack)
end
end

View File

@ -238,10 +238,7 @@ minetest.register_abm({
user_meta:set_int("storage", user_storage + user_gets)
-- Set timer on this node
local t = minetest.get_node_timer(ndv)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(ndv)
end
end
@ -260,10 +257,7 @@ minetest.register_abm({
smeta:set_int("storage", 0)
end
local t = minetest.get_node_timer(spos)
if not t:is_started() then
t:start(1.0)
end
ele.helpers.start_timer(spos)
end
end
end,

View File

@ -130,6 +130,7 @@ function elesolar.register_solar_generator(nodename, nodedef)
local storage = ele.helpers.get_node_property(meta, pos, "storage")
meta:set_string("formspec", get_formspec({capacity = capacity, storage = storage, usage = 0}, 0))
ele.helpers.start_timer(pos)
end
}
@ -147,10 +148,5 @@ minetest.register_lbm({
name = "elepower_solar:solar_generators",
nodenames = {"group:ele_solar_generator"},
run_at_every_load = true,
action = function (pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end,
action = ele.helpers.start_timer,
})

View File

@ -100,13 +100,6 @@ local function validate_structure(pos, player)
return height, inputs, outputs, thermal, all
end
local function start_timer(pos)
local t = minetest.get_node_timer(pos)
if not t:is_started() then
t:start(1.0)
end
end
local function get_port_controller(pos)
for ctrl,t in pairs(elethermal.cache) do
local ctrlpos = minetest.string_to_pos(ctrl)
@ -161,7 +154,7 @@ local function break_structure(pos)
local ctrl = get_port_controller(pos)
if not ctrl then return end
elethermal.cache[minetest.pos_to_string(ctrl)] = nil
start_timer(ctrl)
ele.helpers.start_timer(ctrl)
end
local function controller_timer (pos, elapsed)
@ -276,7 +269,7 @@ minetest.register_node("elepower_thermal:evaporator_controller", {
on_timer = controller_timer,
on_punch = function (pos, node, puncher, pointed_thing)
if validate_structure(pos, puncher:get_player_name()) then
start_timer(pos)
ele.helpers.start_timer(pos)
end
minetest.node_punch(pos, node, puncher, pointed_thing)
end,
@ -321,7 +314,7 @@ minetest.register_node("elepower_thermal:evaporator_output", {
name, took = fluid_lib.take_from_buffer(ctrl, buffer, want_millibuckets)
end
start_timer(ctrl)
ele.helpers.start_timer(ctrl)
return {name = name, millibuckets = took}
end,
@ -385,7 +378,7 @@ minetest.register_node("elepower_thermal:evaporator_input", {
if millibuckets == 0 then return 0 end
local didnt_fit = fluid_lib.insert_into_buffer(ctrl, "input", liquid, millibuckets)
start_timer(ctrl)
ele.helpers.start_timer(ctrl)
return didnt_fit
end,
node_io_room_for_liquid = function(pos, node, side, liquid, millibuckets)
@ -405,5 +398,5 @@ minetest.register_lbm({
name = "elepower_thermal:evaporator_controllers",
nodenames = {"elepower_thermal:evaporator_controller"},
run_at_every_load = true,
action = start_timer,
action = ele.helpers.start_timer,
})

View File

@ -44,3 +44,25 @@ minetest.register_craft({
{"elepower_dynamics:wound_silver_coil", "elepower_dynamics:battery", "elepower_dynamics:wound_silver_coil"},
}
})
--[[
-- Tesseract Frame
minetest.register_craft({
output = "elepower_wireless:tesseract_frame",
recipe = {
{"elepower_dynamics:lead_block", "elepower_dynamics:conduit", "elepower_dynamics:lead_block"},
{"fluid_transfer:fluid_duct", "", "fluid_transfer:fluid_duct"},
{"elepower_dynamics:lead_block", "elepower_dynamics:conduit", "elepower_dynamics:lead_block"},
}
})
-- Tesseract
minetest.register_craft({
output = "elepower_wireless:tesseract",
recipe = {
{"elepower_dynamics:induction_coil_advanced", "elepower_dynamics:soc", "elepower_dynamics:induction_coil_advanced"},
{"elepower_dynamics:xycrone_lump", "elepower_wireless:tesseract_frame", "elepower_dynamics:xycrone_lump"},
{"elepower_dynamics:viridisium_block", "elepower_dynamics:servo_valve", "elepower_dynamics:viridisium_block"},
}
})
]]

View File

@ -11,3 +11,4 @@ elewi.slab_nodebox = {
dofile(mp .. "matter_receiver.lua")
dofile(mp .. "matter_transmitter.lua")
dofile(mp .. "dialler.lua")
dofile(mp .. "tesseract.lua")

View File

@ -0,0 +1,56 @@
minetest.register_node("elepower_wireless:tesseract_frame", {
description = "Tesseract Frame",
tiles = {
"elewireless_tesseract.png",
},
groups = {cracky = 3,},
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, -0.3125, -0.3125, 0.5}, -- NodeBox1
{0.3125, -0.5, -0.5, 0.5, -0.3125, 0.5}, -- NodeBox2
{-0.5, 0.3125, -0.5, -0.3125, 0.5, 0.5}, -- NodeBox3
{0.3125, 0.3125, -0.5, 0.5, 0.5, 0.5}, -- NodeBox4
{-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, -- NodeBox5
{-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, -- NodeBox6
{-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, -- NodeBox7
{-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, -- NodeBox8
{-0.5, -0.3125, -0.5, -0.3125, 0.3125, -0.3125}, -- NodeBox9
{-0.5, -0.3125, 0.3125, -0.3125, 0.3125, 0.5}, -- NodeBox10
{0.3125, -0.5, 0.3125, 0.5, 0.5, 0.5}, -- NodeBox11
{0.3125, -0.3125, -0.5, 0.5, 0.3125, -0.3125}, -- NodeBox12
}
}
})
minetest.register_node("elepower_wireless:tesseract", {
description = "Tesseract",
tiles = {
"elewireless_tesseract.png",
},
groups = {cracky = 3,},
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, -0.3125, -0.3125, 0.5}, -- NodeBox1
{0.3125, -0.5, -0.5, 0.5, -0.3125, 0.5}, -- NodeBox2
{-0.5, 0.3125, -0.5, -0.3125, 0.5, 0.5}, -- NodeBox3
{0.3125, 0.3125, -0.5, 0.5, 0.5, 0.5}, -- NodeBox4
{-0.3125, -0.5, -0.5, 0.3125, -0.3125, -0.3125}, -- NodeBox5
{-0.3125, -0.5, 0.3125, 0.3125, -0.3125, 0.5}, -- NodeBox6
{-0.3125, 0.3125, 0.3125, 0.3125, 0.5, 0.5}, -- NodeBox7
{-0.3125, 0.3125, -0.5, 0.3125, 0.5, -0.3125}, -- NodeBox8
{-0.5, -0.3125, -0.5, -0.3125, 0.3125, -0.3125}, -- NodeBox9
{-0.5, -0.3125, 0.3125, -0.3125, 0.3125, 0.5}, -- NodeBox10
{0.3125, -0.5, 0.3125, 0.5, 0.5, 0.5}, -- NodeBox11
{0.3125, -0.3125, -0.5, 0.5, 0.3125, -0.3125}, -- NodeBox12
{-0.3125, -0.3125, -0.3125, 0.3125, 0.3125, 0.3125}, -- NodeBox13
}
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

View File