This commit is contained in:
Joachim Stolberg 2020-02-01 22:00:58 +01:00
parent f049f7b18c
commit 4a9ca006d6
29 changed files with 543 additions and 307 deletions

View File

@ -29,6 +29,8 @@ local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).
local power = techage.power
local networks = techage.networks
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local function has_power(pos, nvm, state)
local crd = CRD(pos)
@ -115,19 +117,22 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
power_png = 'techage_appl_hole_electric.png'
tNetworks = {
ele1 = {
sides = tNode.power_sides or {F=1, B=1},
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
ntype = "con1",
nominal = tNode.power_consumption[stage],
on_power = on_power,
on_nopower = on_nopower,
},
}
if tNode.networks and tNode.networks.pipe2 then
tNetworks.pipe2 = tNode.networks.pipe2
end
else
power_network = techage.Axle
power_png = 'techage_axle_clutch.png'
tNetworks = {
axle = {
sides = tNode.power_sides or {F=1, B=1},
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
ntype = "con1",
nominal = tNode.power_consumption[stage],
on_power = on_power,
@ -196,7 +201,12 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
end
local tubelib2_on_update2 = function(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
print("tubelib2_on_update2", tlib2.tube_type)
if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2)
else
power.update_network(pos, outdir, tlib2)
end
end
tNode.groups.not_in_creative_inventory = 0

View File

@ -51,8 +51,8 @@ local function build(pos, param2, AssemblyPlan, idx)
minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4})
minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1)
else
local mem = techage.get_mem(pos)
mem.assemble_locked = false
local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
end
end
@ -65,8 +65,8 @@ local function remove(pos, param2, AssemblyPlan, idx)
minetest.remove_node(pos1)
minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1)
else
local mem = techage.get_mem(pos)
mem.assemble_locked = false
local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
end
end
@ -91,22 +91,22 @@ end
-- Two important flags:
-- 1) mem.assemble_locked is true while the object is being assembled/disassembled
-- 2) mem.assemble_build is true if the object is assembled
-- 1) nvm.assemble_locked is true while the object is being assembled/disassembled
-- 2) nvm.assemble_build is true if the object is assembled
function techage.assemble.build(pos, AssemblyPlan, player_name)
-- check protection
if minetest.is_protected(pos, player_name) then
return
end
local mem = techage.get_mem(pos)
if mem.assemble_locked then
local nvm = techage.get_nvm(pos)
if nvm.assemble_locked then
return
end
local node = minetest.get_node(pos)
if check_space(pos, node.param2, AssemblyPlan, player_name) then
mem.assemble_locked = true
nvm.assemble_locked = true
build(pos, node.param2, AssemblyPlan, 1)
mem.assemble_build = true
nvm.assemble_build = true
end
end
@ -115,12 +115,12 @@ function techage.assemble.remove(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then
return
end
local mem = techage.get_mem(pos)
if mem.assemble_locked then
local nvm = techage.get_nvm(pos)
if nvm.assemble_locked then
return
end
local node = minetest.get_node(pos)
mem.assemble_locked = true
nvm.assemble_locked = true
remove(pos, node.param2, AssemblyPlan, #AssemblyPlan)
mem.assemble_build = false
nvm.assemble_build = false
end

View File

@ -97,6 +97,20 @@ function techage.boiler.can_dig(pos, player)
return nvm.num_water == 0
end
local function space_in_inventory(wielded_item, item_count, puncher)
-- check if holding more than 1 empty container
if item_count > 1 then
local inv = puncher:get_inventory()
local item = ItemStack({name=wielded_item, count = item_count - 1})
if inv:room_for_item("main", item) then
inv:add_item("main", item)
return true
end
return false
end
return true
end
function techage.boiler.on_punch(pos, node, puncher, pointed_thing)
local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos)
@ -107,15 +121,27 @@ function techage.boiler.on_punch(pos, node, puncher, pointed_thing)
nvm.num_water = nvm.num_water or 0
local wielded_item = puncher:get_wielded_item():get_name()
local item_count = puncher:get_wielded_item():get_count()
if IsWater[wielded_item] and nvm.num_water < MAX_WATER then
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water + 1
puncher:set_wielded_item(ItemStack("bucket:bucket_empty"))
M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm))
elseif IsBucket[wielded_item] and nvm.num_water > 0 then
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water - 1
puncher:set_wielded_item(ItemStack("bucket:bucket_water"))
if item_count > 1 then
local inv = puncher:get_inventory()
local item = ItemStack("bucket:bucket_water")
if inv:room_for_item("main", item) then
inv:add_item("main", item)
puncher:set_wielded_item({name=wielded_item, count = item_count - 1})
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water - 1
end
else
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water - 1
puncher:set_wielded_item(ItemStack("bucket:bucket_water"))
end
M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm))
end
end

View File

@ -335,8 +335,10 @@ function techage.networks.get_network(tube_type, netID)
end
function techage.networks.delete_network(tube_type, netID)
print("delete_network", tube_type, string.format("%012X", netID))
if Networks[tube_type] and Networks[tube_type][netID] then
Networks[tube_type][netID] = nil
print("deleted")
end
end

View File

@ -273,7 +273,7 @@ function NodeStates:start(pos, nvm)
return false
end
function NodeStates:standby(pos, nvm)
function NodeStates:standby(pos, nvm, err_string)
local state = nvm.techage_state or STOPPED
if state == RUNNING then
nvm.techage_state = STANDBY
@ -282,10 +282,10 @@ function NodeStates:standby(pos, nvm)
end
if self.infotext_name then
local number = M(pos):get_string("node_number")
M(pos):set_string("infotext", self.infotext_name.." "..number..": standby")
M(pos):set_string("infotext", self.infotext_name.." "..number..": "..(err_string or "standby"))
end
if self.formspec_func then
nvm.ta_state_tooltip = "standby"
nvm.ta_state_tooltip = err_string or "standby"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
@ -331,7 +331,7 @@ function NodeStates:nopower(pos, nvm, err_string)
end
if self.infotext_name then
local number = M(pos):get_string("node_number")
M(pos):set_string("infotext", self.infotext_name.." "..number..": no power")
M(pos):set_string("infotext", self.infotext_name.." "..number..": "..(err_string or "no power"))
end
if self.formspec_func then
nvm.ta_state_tooltip = err_string or "no power"
@ -514,15 +514,6 @@ function NodeStates:on_node_load(pos, not_start_timer)
elseif state == BLOCKED then
minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks)
end
if self.formspec_func then
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
-- power available?
if nvm.techage_state == RUNNING and not self.has_power(pos, nvm, state) then
self:nopower(pos, nvm)
end
end
minetest.register_node("techage:defect_dummy", {

View File

@ -39,13 +39,15 @@ end
local function play_sound(pos)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end

View File

@ -69,20 +69,24 @@ local function inlet_cmnd(pos, cmnd, payload)
end
local function play_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.running then
nvm.handle = minetest.sound_play("techage_booster", {
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.running and nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end

View File

@ -30,20 +30,24 @@ local function swap_node(pos, name)
end
local function play_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.running then
nvm.handle = minetest.sound_play("techage_turbine", {
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.running and nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end

View File

@ -39,13 +39,15 @@ end
local function play_sound(pos)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
@ -179,7 +181,8 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
if M(pos):get_int("indir") == in_dir then
local nvm = techage.get_nvm(pos)
if topic == "power" then
return techage.get_node_lvm(pos).name == "techage:ta3_booster_on"
return techage.get_node_lvm(pos).name == "techage:ta3_booster_on" or
power.power_available(pos, Cable)
elseif topic == "start" and not nvm.running then
if power.power_available(pos, Cable) then
nvm.running = true
@ -197,7 +200,12 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
stop_sound(pos)
end
end
end
end,
on_node_load = function(pos, node)
if node.name == "techage:ta3_booster_on" then
play_sound(pos)
end
end,
})
minetest.register_craft({

View File

@ -26,7 +26,6 @@ local EFFICIENCY = 2 -- burn cycles
local CATEGORY = 3
local function has_fuel(pos, nvm)
print("has_fuel", nvm.burn_cycles, topic, payload)
return nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
end
@ -55,8 +54,11 @@ local function node_timer(pos, elapsed)
return false
end
end
return true
end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return true
end
local function start_firebox(pos, nvm)
@ -85,11 +87,23 @@ local _liquid = {
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_OIL) then
return liquid.srv_put(pos, indir, name, amount)
local res = liquid.srv_put(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return res
end
return amount
end,
take = liquid.srv_take,
take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return amount, name
end
}
local _networks = {
@ -121,6 +135,7 @@ minetest.register_node("techage:furnace_firebox", {
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
on_metadata_inventory_put = fuel.on_metadata_inventory_put,
on_punch = fuel.on_punch,
on_receive_fields = fuel.on_receive_fields,
on_rightclick = fuel.on_rightclick,
liquid = _liquid,
@ -174,6 +189,7 @@ minetest.register_node("techage:furnace_firebox_on", {
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_receive_fields = fuel.on_receive_fields,
on_punch = fuel.on_punch,
on_rightclick = fuel.on_rightclick,
liquid = _liquid,
networks = _networks,
@ -215,7 +231,6 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
on_transfer = function(pos, in_dir, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "fuel" then
print(dump(nvm))
return has_fuel(pos, nvm) and booster_cmnd(pos, "power")
elseif topic == "running" then
return nvm.running and booster_cmnd(pos, "power")

View File

@ -100,7 +100,7 @@ local function cooking(pos, crd, nvm, elapsed)
crd.State:idle(pos, nvm)
end
else
crd.State:idle(pos, nvm)
crd.State:standby(pos, nvm, S("no fuel or no power"))
end
end
end
@ -113,7 +113,6 @@ local function keep_running(pos, elapsed)
if nvm.toggle then -- progress bar/arrow
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
return crd.State:is_active(nvm)
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -186,6 +185,7 @@ local function can_start(pos, nvm, state)
end
local function on_node_state_change(pos, old_state, new_state)
print("on_node_state_change")
local pwr1 = techage.needs_power2(old_state)
local pwr2 = techage.needs_power2(new_state)
if pwr1 ~= pwr2 then

View File

@ -85,6 +85,12 @@ else
dofile(MP.."/steam_engine/cylinder.lua")
dofile(MP.."/steam_engine/flywheel.lua")
-- Liquids I
dofile(MP.."/liquids/liquid_pipe.lua")
dofile(MP.."/liquids/liquid.lua")
dofile(MP.."/liquids/liquid_lib.lua")
dofile(MP.."/liquids/fuel_lib.lua")
-- Basic Machines
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
dofile(MP.."/basic_machines/source.lua")
@ -100,14 +106,10 @@ else
dofile(MP.."/basic_machines/funnel.lua")
dofile(MP.."/basic_machines/liquidsampler.lua")
-- -- Liquids
dofile(MP.."/liquids/liquid_pipe.lua")
dofile(MP.."/liquids/liquid.lua")
dofile(MP.."/liquids/liquid_lib.lua")
-- Liquids II
dofile(MP.."/liquids/tank.lua")
dofile(MP.."/liquids/silo.lua")
dofile(MP.."/liquids/pump.lua")
dofile(MP.."/liquids/fuel_lib.lua")
-- Coal power station
dofile(MP.."/coal_power_station/firebox.lua")
@ -141,17 +143,17 @@ else
dofile(MP.."/lamps/industriallamp3.lua")
-- -- Oil
-- dofile(MP.."/oil/explore.lua")
-- dofile(MP.."/oil/tower.lua")
-- dofile(MP.."/oil/drillbox.lua")
-- dofile(MP.."/oil/pumpjack.lua")
-- dofile(MP.."/oil/distiller.lua")
-- dofile(MP.."/oil/reboiler.lua")
dofile(MP.."/oil/explore.lua")
dofile(MP.."/oil/tower.lua")
dofile(MP.."/oil/drillbox.lua")
dofile(MP.."/oil/pumpjack.lua")
dofile(MP.."/oil/distiller.lua")
dofile(MP.."/oil/reboiler.lua")
-- dofile(MP.."/oil/gasflare.lua")
-- TA3 power based
--dofile(MP.."/ta3_power/tiny_generator.lua")
--dofile(MP.."/ta3_power/akkubox.lua")
dofile(MP.."/ta3_power/tiny_generator.lua")
dofile(MP.."/ta3_power/akkubox.lua")
-- Logic
dofile(MP.."/logic/lib.lua")

43
items/hydrogen.lua Normal file
View File

@ -0,0 +1,43 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA4 Hydrogen
]]--
local S = techage.S
minetest.register_craftitem("techage:hydrogen", {
description = S("TA4 Hydrogen"),
inventory_image = "techage_hydrogen_inv.png",
})
minetest.register_craftitem("techage:cylinder_small_hydrogen", {
description = S("Hydrogen Cylinder Small"),
inventory_image = "techage_gas_cylinder_small.png^[colorize:#00528A:120",
stack_max = 1,
})
minetest.register_craftitem("techage:cylinder_large_hydrogen", {
description = S("Hydrogen Cylinder Large"),
inventory_image = "techage_gas_cylinder_large.png^[colorize:#00528A:120",
stack_max = 1,
})
techage.register_liquid("techage:hydrogen", "", 1, "techage:hydrogen")
techage.register_liquid("techage:cylinder_small_hydrogen", "techage:ta3_cylinder_small", 1, "techage:hydrogen")
techage.register_liquid("techage:cylinder_large_hydrogen", "techage:ta3_cylinder_large", 6, "techage:hydrogen")
techage.recipes.add("ta4_doser", {
output = "techage:hydrogen 1",
input = {
"techage:gas 1",
}
})

View File

@ -25,6 +25,7 @@ local Burntime = techage.firebox.Burntime
techage.fuel = {}
local CAPACITY = 50
local BLOCKING_TIME = 0.3 -- 300ms
techage.fuel.CAPACITY = CAPACITY
@ -35,7 +36,7 @@ techage.fuel.BT_FUELOIL = 2
techage.fuel.BT_NAPHTHA = 1
local function formspec_fuel(x, y, nvm)
function techage.fuel.fuel_container(x, y, nvm)
local itemname = ""
if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then
itemname = nvm.liquid.name.." "..nvm.liquid.amount
@ -44,27 +45,25 @@ local function formspec_fuel(x, y, nvm)
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
local tooltip = S("To add fuel punch\nthis block\nwith a fuel container")
return "container["..x..","..y.."]"..
"background[0,0;3,1.05;techage_form_grey.png]"..
"list[context;fuel;0,0;1,1;]"..
techage.item_image(1, 0, itemname)..
"image[2,0;1,1;default_furnace_fire_bg.png^[lowpart:"..
"box[0,0;1.05,2.1;#000000]"..
"tooltip[0,0;1.1,1.1;"..tooltip..";#0C3D32;#FFFFFF]"..
"image[0.1,0.1;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
techage.item_image(0.1, 1.1, itemname)..
"container_end[]"
end
techage.fuel.formspec_fuel = formspec_fuel
function techage.fuel.formspec(nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
formspec_fuel(1, 0, nvm)..
"button[5,0;2,1;update;"..update.."]"..
"list[current_player;main;0,1.3;8,4;]"
local title = S("Fuel Menu")
return "size[4,3]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize("#000000", title).."]"..
techage.fuel.fuel_container(1.5, 1, nvm)
end
local function fill_container(pos, inv, nvm)
@ -163,9 +162,9 @@ function techage.fuel.can_dig(pos, player)
return inv:is_empty("fuel") and nvm.liquid.amount == 0
end
function techage.fuel.on_rightclick(pos)
function techage.fuel.on_rightclick(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end
@ -196,3 +195,69 @@ end
function techage.fuel.valid_fuel(name, category)
return ValidOilFuels[name] and ValidOilFuels[name] <= category
end
-- check if the given empty container can be replaced by a full
-- container and added to the players inventory
local function fill(nvm, empty_container, item_count, puncher)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local full_container = liquid.get_full_container(empty_container, nvm.liquid.name)
if empty_container and full_container then
local item = ItemStack(full_container) -- to be added
local ldef = liquid.get_liquid_def(full_container)
if ldef and nvm.liquid.amount - ldef.size >= 0 then
if item_count > 1 then -- can't be simply replaced?
-- check for extra free space
local inv = puncher:get_inventory()
if inv:room_for_item("main", item) then
-- add full container and return
-- the empty once - 1
inv:add_item("main", item)
item = {name = empty_container, count = item_count - 1}
else
return -- no free space
end
end
nvm.liquid.amount = nvm.liquid.amount - ldef.size
if nvm.liquid.amount == 0 then
nvm.liquid.name = nil
end
return item -- to be added to the players inv.
end
end
end
local function empty(nvm, full_container)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local ldef = liquid.get_liquid_def(full_container)
if ldef and ValidOilFuels[ldef.inv_item] then
if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then
if nvm.liquid.amount + ldef.size <= CAPACITY then
nvm.liquid.amount = nvm.liquid.amount + ldef.size
nvm.liquid.name = ldef.inv_item
return ItemStack(ldef.container)
end
end
end
end
function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos)
mem.blocking_time = mem.blocking_time or 0
if mem.blocking_time > techage.SystemTime then
return
end
local wielded_item = puncher:get_wielded_item():get_name()
local item_count = puncher:get_wielded_item():get_count()
local new_item = fill(nvm, wielded_item, item_count, puncher)
or empty(nvm, wielded_item)
if new_item then
puncher:set_wielded_item(ItemStack(new_item))
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
return
end
end

View File

@ -74,7 +74,7 @@ local function delete_netID(pos, outdir)
end
end
end)
networks.delete_network(netID, Pipe)
networks.delete_network("pipe2", netID)
end
local function get_netID(pos, outdir)
@ -88,16 +88,19 @@ end
local function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir)
print(1)
if netID then
print(2)
local netw = networks.get_network("pipe2", netID)
if not netw then
print(3)
netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network("pipe2", netID, netw)
end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID))
--print("netw", string.format("%012X", netID), s, dump(netw))
print("netw", string.format("%012X", netID), dump(netw))
return netw[ntype] or {}
end
print(4)
return {}
end

View File

@ -77,7 +77,7 @@ Oil Drill Box=Ölbohrkiste
Oil Pumpjack=Ölpumpe
Oil Source=Erdöl
Oil Tank=Öltank
Oil amount:=Ölmenge:
Oil amount=Ölmenge
Other consumers=Weitere Verbraucher
Outp=Ergeb.
Plan=Plan

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -19,7 +19,7 @@ local S = techage.S
-- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local STANDBY_TICKS = 4
local STANDBY_TICKS = 1
local COUNTDOWN_TICKS = 6
local CYCLE_TIME = 16
@ -31,21 +31,24 @@ local formspec0 = "size[5,4]"..
"button_exit[1,3.2;3,1;build;"..S("Build derrick").."]"
local function play_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.techage_state == techage.RUNNING then
nvm.handle = minetest.sound_play("techage_oildrill", {
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_oildrill", {
pos = pos,
gain = 1,
max_hear_distance = 15})
minetest.after(4, play_sound, pos)
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local nvm = techage.get_nvm(pos)
if nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
@ -104,8 +107,9 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count()
end
local function on_rightclick(pos)
local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end
@ -118,6 +122,7 @@ local function on_node_state_change(pos, old_state, new_state)
end
local function drilling(pos, crd, nvm, inv)
print("drilling")
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
local owner = M(pos):get_string("owner")
@ -127,12 +132,12 @@ local function drilling(pos, crd, nvm, inv)
local ndef = minetest.registered_nodes[node.name]
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
crd.State:idle(pos, nvm)
crd.State:idle(pos, nvm, S("Drill bits missing"))
elseif curr_depth >= depth then
M(pos):set_string("oil_found", "true")
crd.State:stop(pos, nvm)
elseif minetest.is_protected(nvm.drill_pos, owner) then
crd.State:fault(pos, nvm)
crd.State:fault(pos, nvm, S("Drill area is protected"))
elseif node.name == "techage:oil_drillbit2" then
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
@ -156,7 +161,7 @@ local function drilling(pos, crd, nvm, inv)
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else
crd.State:fault(pos, nvm)
crd.State:fault(pos, nvm, S("block can't be dug"))
end
end
@ -167,7 +172,9 @@ local function keep_running(pos, elapsed)
if inv then
drilling(pos, crd, nvm, inv)
end
return crd.State:is_active(nvm)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
end
local function can_dig(pos, player)
@ -196,6 +203,7 @@ local function on_receive_fields(pos, formname, fields, player)
else
local nvm = techage.get_nvm(pos)
if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
end
@ -245,8 +253,12 @@ local tubing = {
return "unsupported"
end
end,
on_node_load = function(pos)
on_node_load = function(pos, node)
CRD(pos).State:on_node_load(pos)
local nvm = techage.get_nvm(pos)
if nvm.techage_state == techage.RUNNING then
play_sound(pos)
end
end,
}
@ -295,17 +307,3 @@ minetest.register_craft({
{"default:steel_ingot", "techage:vacuum_tube", "default:steel_ingot"},
},
})
minetest.register_lbm({
label = "[techage] Oil Tower sound",
name = "techage:oil_tower",
nodenames = {"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
if nvm.techage_state == techage.RUNNING then
play_sound(pos)
end
end
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -24,7 +24,7 @@ local liquid = techage.liquid
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
local STANDBY_TICKS = 10
local STANDBY_TICKS = 1
local COUNTDOWN_TICKS = 10
local CYCLE_TIME = 8
@ -52,53 +52,85 @@ local function formspec(self, pos, nvm)
amount = techage.explore.get_oil_amount(P(storage_pos))
end
return "size[5,3]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[0.5,0;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
"image[2,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"label[0,1.3;"..S("Oil amount:")..": "..amount.."]"..
"button[3,1.1;2,1;update;"..S("Update").."]"..
"image_button[2,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1.5,-0.1;"..minetest.colorize( "#000000", S("Pumpjack")).."]"..
"image[0.5,1.4;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
"image[4,0.8;1,1;"..techage.get_power_image(pos, nvm).."]"..
"tooltip[4,0.8;1,1;"..S("needs power").."]"..
"label[0,2.5;"..S("Oil amount")..": "..amount.."]"..
"image_button[2.5,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"
end
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function on_node_state_change(pos, old_state, new_state)
if new_state == techage.RUNNING then
play_sound(pos)
else
stop_sound(pos)
end
end
local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end
local function pumping(pos, crd, meta, nvm)
if has_oil(pos, meta) then
local leftover = liquid.put(pos, 6, "techage:oil_source", 1)
print("pumping", dump(leftover))
if leftover and leftover > 0 then
crd.State:blocked(pos, nvm)
stop_sound(pos)
return
end
dec_oil_item(pos, meta)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
crd.State:fault(pos, nvm)
crd.State:fault(pos, nvm, S("no oil"))
end
local function keep_running(pos, elapsed)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
pumping(pos, crd, M(pos), nvm)
return crd.State:is_active(nvm)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
if fields.update then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
else
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local tiles = {}
@ -149,8 +181,11 @@ local tubing = {
return "unsupported"
end
end,
on_node_load = function(pos)
on_node_load = function(pos, node)
CRD(pos).State:on_node_load(pos)
if node.name == "techage:ta3_pumpjack_act" then
play_sound(pos)
end
end,
}
@ -160,6 +195,7 @@ local _, node_name_ta3, _ =
standby_ticks = STANDBY_TICKS,
formspec = formspec,
tubing = tubing,
on_state_change = on_node_state_change,
after_place_node = function(pos, placer)
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:oil_drillbit2" then
@ -176,9 +212,7 @@ local _, node_name_ta3, _ =
ntype = "pump",
},
},
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
end,
power_sides = {F=1, B=1, L=1, R=1, D=1},
on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields,
node_timer = keep_running,

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -27,6 +27,28 @@ local CYCLE_TIME = 6
local CAPA = 12
local PWR_NEEDED = 14
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function swap_node(pos, on)
local nvm = techage.get_nvm(pos)
if on then
@ -34,10 +56,7 @@ local function swap_node(pos, on)
node.name = "techage:ta3_reboiler_on"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(CYCLE_TIME)
minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 10})
play_sound(pos)
elseif not on and nvm.running then
local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler"
@ -45,16 +64,15 @@ local function swap_node(pos, on)
minetest.get_node_timer(pos):stop()
nvm.running = false
power.consumer_stop(pos, Cable)
stop_sound(pos)
end
end
local function on_power(pos, nvm)
if nvm.running then
swap_node(pos, true)
end
local function on_power(pos)
swap_node(pos, true)
end
local function on_nopower(pos, nvm)
local function on_nopower(pos)
swap_node(pos, false)
end
@ -99,34 +117,32 @@ local function node_timer(pos, elapsed)
swap_node(pos, false)
return false
end
minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true
end
swap_node(pos, false)
return false
end
-- liquid
local function tubelib2_on_update2(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
local function after_place_node(pos)
Pipe:after_place_node(pos)
Cable:after_place_node(pos)
end
-- power
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
power.after_dig_node(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local _liquid = {
local function tubelib2_on_update2(pos, outdir, tlib2, node)
if tlib2 == Pipe then
liquid.update_network(pos, outdir)
else
power.update_network(pos, outdir, tlib2)
end
end
local liquid_def = {
capa = CAPA,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
@ -148,11 +164,18 @@ local _liquid = {
take = liquid.srv_take,
}
local _networks = {
local net_def = {
pipe2 = {
sides = {L = true, R = true}, -- Pipe connection sides
ntype = "tank",
},
ele1 = {
sides = techage.networks.AllSides, -- Cable connection sides
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:ta3_reboiler", {
@ -177,12 +200,13 @@ minetest.register_node("techage:ta3_reboiler", {
power.after_place_node(pos)
end,
tubelib2_on_update2 = tubelib2_on_update2, -- liquid
after_tube_update = after_tube_update, -- power
tubelib2_on_update2 = tubelib2_on_update2,
on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
liquid = _liquid,
networks = _networks,
after_dig_node = after_dig_node,
liquid = liquid_def,
networks = net_def,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
@ -199,34 +223,32 @@ minetest.register_node("techage:ta3_reboiler_on", {
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png",
{
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png^[transformFX",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
{
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png^[transformFX",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
{
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
{
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
},
tubelib2_on_update2 = tubelib2_on_update2, -- liquid
after_tube_update = after_tube_update, -- power
tubelib2_on_update2 = tubelib2_on_update2,
on_timer = node_timer,
after_dig_node = after_dig_node,
liquid = _liquid,
networks = _networks,
liquid = liquid_def,
networks = net_def,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
@ -236,19 +258,8 @@ minetest.register_node("techage:ta3_reboiler_on", {
sounds = default.node_sound_metal_defaults(),
})
--
-- Liquids
--
Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
--
-- Power
--
techage.power.enrich_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
power_network = Cable,
on_power = on_power,
on_nopower = on_nopower,
})
Cable:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
minetest.register_craft({
output = "techage:ta3_reboiler",

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information

View File

@ -72,7 +72,7 @@ local function delete_netID(pos, outdir, Cable)
end
end
end)
networks.delete_network(netID, Cable)
networks.delete_network(Cable.tube_type, netID)
end
-- Keep the network up and running

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,13 +34,15 @@ end
local function play_sound(pos)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_steamengine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_steamengine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end

View File

@ -29,45 +29,61 @@ local PWR_CAPA = 12
local EFFICIENCY = 2.5
local function formspec(self, pos, nvm)
local fuel_percent = 0
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
return "size[8,6]"..
--"box[0,-0.1;3.8,0.5;#c6e8ff]"..
--"label[1,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
--power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
return "size[5,4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
fuel.formspec_fuel(1, 0, nvm)..
"button[1.6,1;1.8,1;update;"..S("Update").."]"..
"image_button[5.5,0.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]"..
"list[current_player;main;0,2.3;8,4;]"..
default.get_hotbar_bg(0, 3)
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1.5,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
fuel.fuel_container(0, 0.9, nvm)..
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
power.formspec_label_bar(2.5, 0.8, S("power"), PWR_CAPA, nvm.provided)
end
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function can_start(pos, nvm, state)
if nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then
return true
end
return false
return S("no fuel")
end
local function start_node(pos, nvm, state)
nvm.running = true
power.generator_start(pos, nvm, PWR_CAPA)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
nvm.running = true -- needed by fuel_lib
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
play_sound(pos)
end
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.provided = 0
power.generator_stop(pos, nvm)
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
stop_sound(pos)
end
local State = techage.NodeStates:new({
@ -96,7 +112,8 @@ local function burning(pos, nvm)
return true
else
nvm.liquid.name = nil
State:fault(pos, nvm)
State:fault(pos, nvm, S("no fuel"))
stop_sound(pos)
return false
end
else
@ -106,17 +123,16 @@ end
local function node_timer(pos, elapsed)
local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
if nvm.running and burning(pos, nvm) then
nvm.provided = power.generator_alive(pos, nvm)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
else
nvm.provided = 0
end
return false
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return true
end
local function on_receive_fields(pos, formname, fields, player)
@ -125,42 +141,50 @@ local function on_receive_fields(pos, formname, fields, player)
end
local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function formspec_clbk(pos, nvm)
return formspec(State, pos, nvm)
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
minetest.after(0.5, fuel.move_item, pos, stack, formspec_clbk)
end
local function on_rightclick(pos)
local function on_rightclick(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local _liquid = {
local liquid_def = {
fuel_cat = fuel.BT_NAPHTHA,
capa = fuel.CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_NAPHTHA) then
return liquid.srv_put(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_OIL) then
local res = liquid.srv_put(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return res
end
return amount
end,
take = liquid.srv_take,
take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return amount, name
end
}
local _networks = {
pipe = {
local net_def = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
ele1 = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
minetest.register_node("techage:tiny_generator", {
@ -179,28 +203,23 @@ minetest.register_node("techage:tiny_generator", {
on_rotate = screwdriver.disallow,
is_ground_content = false,
on_construct = function(pos)
after_place_node = function(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:tiny_generator")
nvm.running = false
nvm.burn_cycles = 0
State:node_init(pos, nvm, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
M(pos):set_string("formspec", formspec(State, pos, nvm))
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
end,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_punch = fuel.on_punch,
on_timer = node_timer,
can_dig = fuel.can_dig,
liquid = _liquid,
networks = _networks,
liquid = liquid_def,
networks = net_def,
})
minetest.register_node("techage:tiny_generator_on", {
@ -241,23 +260,17 @@ minetest.register_node("techage:tiny_generator_on", {
on_rotate = screwdriver.disallow,
is_ground_content = false,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_punch = fuel.on_punch,
on_timer = node_timer,
can_dig = fuel.can_dig,
liquid = _liquid,
networks = _networks,
liquid = liquid_def,
networks = net_def,
})
Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
conn_sides = {"R"},
power_network = Power,
})
Cable:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, src, topic, payload)
@ -268,8 +281,11 @@ techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos)
on_node_load = function(pos, node)
State:on_node_load(pos)
if node.name == "techage:tiny_generator_on" then
play_sound(pos)
end
end,
})