removed unneeded code

This commit is contained in:
Joachim Stolberg 2020-02-27 22:33:42 +01:00
parent 2a6d1519c9
commit 2905a45774
22 changed files with 75 additions and 223 deletions

View File

@ -16,44 +16,10 @@
local M = minetest.get_meta
local S = techage.S
local PlayerActions = {}
local InventoryState = {}
local function store_action(pos, player, action, stack)
local meta = minetest.get_meta(pos)
local name = player and player:get_player_name() or ""
local number = meta:get_string("node_number")
local item = stack:get_name().." "..stack:get_count()
PlayerActions[number] = {name, action, item}
end
local function send_off_command(pos)
local meta = minetest.get_meta(pos)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(own_num, numbers, "off")
end
end
local function send_command(pos)
local meta = minetest.get_meta(pos)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(own_num, numbers, "on")
minetest.after(1, send_off_command, pos)
end
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
store_action(pos, player, "put", stack)
send_command(pos)
return stack:get_count()
end
@ -61,8 +27,6 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
store_action(pos, player, "take", stack)
send_command(pos)
return stack:get_count()
end
@ -109,11 +73,8 @@ minetest.register_node("techage:chest_ta2", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local number = techage.add_node(pos, "techage:chest_ta2")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec2())
meta:set_string("infotext", S("TA2 Protected Chest").." "..number)
end,
techage_set_numbers = function(pos, numbers, player_name)
@ -259,17 +220,12 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return techage.get_inv_state(inv, "main")
elseif topic == "player_action" then
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
return PlayerActions[number]
else
return "unsupported"
end
end,
})
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta2",
@ -279,6 +235,11 @@ minetest.register_craft({
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta3",
recipe = {"techage:chest_ta2", "techage:tubeS", "techage:vacuum_tube"}
recipe = {"techage:chest_ta2", "default:chest"}
})
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta4",
recipe = {"techage:chest_ta3", "default:chest"}
})

View File

@ -26,8 +26,7 @@ local COUNTDOWN_TICKS = 10
local STANDBY_TICKS = 10
local CYCLE_TIME = 4
local INFO = [[- Turn port on/off: command = "port", payload = "red/green/blue/yellow=on/off"
- Clear counter: command = "clear_counter"]]
local INFO = [[Turn port on/off: command = 'port', payload = red/green/blue/yellow=on/off]]
--local Side2Color = {B="red", L="green", F="blue", R="yellow"}
@ -441,12 +440,7 @@ local tubing = {
local slot, val = techage.ident_value(payload)
return change_filter_settings(pos, slot, val)
else
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
return CRD(pos).State:on_receive_message(pos, topic, payload)
end
end,

View File

@ -193,15 +193,7 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}

View File

@ -238,15 +238,7 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}
@ -290,7 +282,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
num_items = {0,1,1,1},
power_consumption = {0,3,3,3},
},
{false, true, true, false}) -- TA2/A3
{false, true, true, false}) -- TA2/TA3
minetest.register_craft({
output = node_name_ta2,

View File

@ -171,15 +171,7 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}

View File

@ -184,15 +184,7 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}

View File

@ -173,9 +173,6 @@ local tubing = {
on_recv_message = function(pos, src, topic, payload)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
end,
}
local node_name_ta2, node_name_ta3, _ =

View File

@ -115,15 +115,7 @@ local tubing = {
is_pusher = true, -- is a pulling/pushing node
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}

View File

@ -343,15 +343,9 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
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)

View File

@ -144,4 +144,11 @@ function techage.fuel.has_fuel(nvm)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
return nvm.liquid.amount > 0
end
function techage.fuel.get_fuel_amount(nvm)
if nvm.liquid and nvm.liquid.amount then
return nvm.liquid.amount
end
return 0
end

View File

@ -222,6 +222,13 @@ function techage.liquid.on_punch(pos, node, puncher, pointed_thing)
end
end
function techage.liquid.get_liquid_amount(nvm)
if nvm.liquid and nvm.liquid.amount then
return nvm.liquid.amount
end
return 0
end
techage.liquid.get_liquid_def = get_liquid_def
techage.liquid.get_container_def = get_container_def
techage.liquid.is_container_empty = is_container_empty

View File

@ -446,23 +446,15 @@ function NodeStates:on_receive_message(pos, topic, payload)
self:stop(pos, techage.get_nvm(pos))
return true
elseif topic == "state" then
local node = techage.get_node_lvm(pos)
local node = minetest.get_node(pos)
if node.name == "ignore" then -- unloaded node?
return "unloaded"
end
return techage.get_state_string(techage.get_nvm(pos))
elseif topic == "counter" then
return nvm.techage_item_meter or 1
elseif topic == "clear_counter" then
nvm.techage_item_meter = 0
return true
elseif topic == "fuel" then
local inv = M(pos):get_inventory()
if inv:get_size("fuel") == 1 then
local stack = inv:get_stack("fuel", 1)
return stack:get_count()
end
return
return techage.fuel.get_fuel_amount(nvm)
elseif topic == "load" then
return techage.liquid.get_liquid_amount(nvm)
else
return "unsupported"
end

View File

@ -304,15 +304,7 @@ minetest.register_node("techage:ta4_doser_on", {
techage.register_node({"techage:ta4_doser", "techage:ta4_doser_on"}, {
on_recv_message = function(pos, src, topic, payload)
local resp = State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
State:on_node_load(pos)
return State:on_receive_message(pos, topic, payload)
end,
})

View File

@ -207,15 +207,9 @@ techage.register_node({"techage:coalfirebox"}, {
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "state" then
if nvm.running then
return "running"
else
return "stopped"
end
return nvm.running and "running" or "stopped"
elseif topic == "fuel" then
local inv = M(pos):get_inventory()
local stack = inv:get_stack("fuel", 1)
return stack:get_count()
return techage.fuel.get_fuel_amount(nvm)
else
return "unsupported"
end
@ -230,17 +224,3 @@ minetest.register_craft({
{'default:stone', 'default:stone', 'default:stone'},
},
})
minetest.register_lbm({
label = "[techage] Power Station firebox",
name = "techage:coalfirebox",
nodenames = {"techage:coalfirebox"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})

View File

@ -25,6 +25,8 @@ local Cable = techage.ElectricCable
local power = techage.power
local networks = techage.networks
local INFO = [[Command 'load' returns the current provided power in ku]]
local function formspec(self, pos, nvm)
return "size[4,4]"..
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
@ -222,16 +224,14 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end,
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return techage.power.percent(PWR_CAPA, nvm.provided)
if topic == "info" then
return INFO
elseif topic == "load" then
return math.floor((nvm.provided or 0) + 0.5)
else
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
State:on_node_load(pos)
end,
})
minetest.register_craft({

View File

@ -170,13 +170,9 @@ techage.register_node({"techage:oilfirebox"}, {
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "state" then
if nvm.running then
return "running"
else
return "stopped"
end
return nvm.running and "running" or "stopped"
elseif topic == "fuel" then
return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
return techage.fuel.get_fuel_amount(nvm)
else
return "unsupported"
end
@ -192,16 +188,4 @@ minetest.register_craft({
},
})
minetest.register_lbm({
label = "[techage] Power Station firebox",
name = "techage:steam_engine",
nodenames = {"techage:oilfirebox"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})

View File

@ -166,7 +166,6 @@ techage.register_node({"techage:turbine", "techage:turbine_on"}, {
end
end,
on_node_load = function(pos, node)
--print("on_node_load", node.name)
if node.name == "techage:turbine_on" then
play_sound(pos)
end

View File

@ -25,6 +25,8 @@ local Cable = techage.ElectricCable
local power = techage.power
local networks = techage.networks
local INFO = [[Command 'load' returns the current provided power in ku]]
local function formspec(self, pos, nvm)
return "size[4,4]"..
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
@ -223,16 +225,14 @@ techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
end,
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return techage.power.percent(PWR_CAPA, nvm.provided)
if topic == "info" then
return INFO
elseif topic == "load" then
return math.floor((nvm.provided or 0) + 0.5)
else
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
State:on_node_load(pos)
end,
})
minetest.register_craft({

View File

@ -32,6 +32,8 @@ local Pipe = techage.LiquidPipe
local power = techage.power
local in_range = techage.in_range
local INFO = [[- Command 'load' returns the storage load in percent]]
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
@ -115,6 +117,9 @@ local function after_place_node(pos, placer, itemstack)
local nvm = techage.get_nvm(pos)
nvm.capa = 0
M(pos):set_string("owner", placer:get_player_name())
local number = techage.add_node(pos, "techage:heatexchanger1")
M(pos):set_string("node_number", number)
M(pos):set_string("infotext", S("TA4 Heat Exchanger 1").." "..number)
Cable:after_place_node(pos)
Pipe:after_place_node(pos)
end
@ -250,10 +255,24 @@ techage.register_node({"techage:heatexchanger1"}, {
end,
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "load" then
if topic == "state" then
if nvm.charging then
return "running"
elseif nvm.running then
return "standby"
else
return "stopped"
end
elseif topic == "load" then
return techage.power.percent(nvm.capa_max, nvm.capa)
elseif topic == "size" then
return (nvm.capa_max or 0) / GRVL_CAPA
elseif topic == "on" then
start_node(pos, techage.get_nvm(pos))
return true
elseif topic == "off" then
stop_node(pos, techage.get_nvm(pos))
return true
elseif topic == "info" then
return INFO
else
return "unsupported"
end

View File

@ -215,13 +215,9 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "state" then
if nvm.running then
return "running"
else
return "stopped"
end
return nvm.running and "running" or "stopped"
elseif topic == "fuel" then
return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
return techage.fuel.get_fuel_amount(nvm)
else
return "unsupported"
end
@ -244,15 +240,3 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
})
Pipe:add_secondary_node_names({"techage:furnace_firebox", "techage:furnace_firebox_on"})
minetest.register_lbm({
label = "[techage] Furnace firebox",
name = "techage:furnace",
nodenames = {"techage:furnace_firebox_on"},
run_at_every_load = true,
action = function(pos, node)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})

View File

@ -234,15 +234,7 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
}

View File

@ -234,21 +234,11 @@ local function read_state(itemstack, user, pointed_thing)
fuel = dump(fuel)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
end
local counter = techage.send_single("0", number, "counter", nil)
if counter and counter ~= "" and counter ~= "unsupported" then
counter = dump(counter)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": counter = "..counter.." ")
end
local load = techage.send_single("0", number, "load", nil)
if load and load ~= "" and load ~= "unsupported" then
load = dump(load)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ")
end
local size = techage.send_single("0", number, "size", nil)
if size and size ~= "" and size ~= "unsupported" then
size = dump(size)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": size = "..size.." units ")
end
local owner = M(pos):get_string("owner") or ""
if owner ~= "" then
minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ")