Use upvalues in registrations
| | |
| | | "label[1,5;Upgrade Slots]" |
| | | end |
| | | |
| | | data.formspec = formspec |
| | | |
| | | minetest.register_node("technic:"..ltier.."_alloy_furnace", { |
| | | description = S("%s Alloy Furnace"):format(tier), |
| | | tiles = {"technic_"..ltier.."_alloy_furnace_top.png", |
| | |
| | | paramtype2 = "facedir", |
| | | groups = groups, |
| | | tube = data.tube and tube or nil, |
| | | technic = data, |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_stone_defaults(), |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local name = minetest.get_node(pos).name |
| | | local data = minetest.registered_nodes[name].technic |
| | | |
| | | |
| | | meta:set_string("infotext", S("%s Alloy Furnace"):format(data.tier)) |
| | | meta:set_string("formspec", data.formspec) |
| | | meta:set_string("infotext", S("%s Alloy Furnace"):format(tier)) |
| | | meta:set_string("formspec", formspec) |
| | | meta:set_int("tube_time", 0) |
| | | local inv = meta:get_inventory() |
| | | inv:set_size("src", 2) |
| | |
| | | drop = "technic:"..ltier.."_alloy_furnace", |
| | | groups = active_groups, |
| | | tube = data.tube and tube or nil, |
| | | technic = data, |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_stone_defaults(), |
| | | can_dig = function(pos, player) |
| | |
| | | interval = 1, |
| | | chance = 1, |
| | | action = function(pos, node, active_object_count, active_object_count_wider) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | local meta = minetest.get_meta(pos) |
| | | local inv = meta:get_inventory() |
| | | local eu_input = meta:get_int(data.tier.."_EU_input") |
| | | local eu_input = meta:get_int(tier.."_EU_input") |
| | | |
| | | -- Machine information |
| | | local machine_name = S("%s Alloy Furnace"):format(data.tier) |
| | | local machine_node = "technic:"..string.lower(data.tier).."_alloy_furnace" |
| | | local machine_name = S("%s Alloy Furnace"):format(tier) |
| | | local machine_node = "technic:"..ltier.."_alloy_furnace" |
| | | local machine_demand = data.demand |
| | | |
| | | -- Setup meta data if it does not exist. |
| | | if not eu_input then |
| | | meta:set_int(data.tier.."_EU_demand", machine_demand[1]) |
| | | meta:set_int(data.tier.."_EU_input", 0) |
| | | meta:set_int(tier.."_EU_demand", machine_demand[1]) |
| | | meta:set_int(tier.."_EU_input", 0) |
| | | end |
| | | |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, data.tier) |
| | | technic.switching_station_timeout_count(pos, tier) |
| | | |
| | | local EU_upgrade, tube_upgrade = 0, 0 |
| | | if data.upgrade then |
| | |
| | | not inv:room_for_item("dst", result) then |
| | | hacky_swap_node(pos, machine_node) |
| | | meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
| | | meta:set_int(data.tier.."_EU_demand", 0) |
| | | meta:set_int(tier.."_EU_demand", 0) |
| | | return |
| | | end |
| | | |
| | |
| | | end |
| | | |
| | | end |
| | | meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | end, |
| | | }) |
| | | |
| | |
| | | local tier = data.tier |
| | | local ltier = string.lower(tier) |
| | | |
| | | data.formspec = |
| | | local formspec = |
| | | "invsize[8,9;]".. |
| | | "image[1,1;1,2;technic_power_meter_bg.png]".. |
| | | "list[current_name;src;3,1;1,1;]".. |
| | |
| | | groups = groups, |
| | | sounds = default.node_sound_wood_defaults(), |
| | | drop = "technic:"..ltier.."_battery_box0", |
| | | technic = data, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local inv = meta:get_inventory() |
| | | local node = minetest.get_node(pos) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | |
| | | meta:set_string("infotext", S("%s Battery Box"):format(data.tier)) |
| | | meta:set_string("formspec", data.formspec) |
| | | meta:set_int(data.tier.."_EU_demand", 0) |
| | | meta:set_int(data.tier.."_EU_supply", 0) |
| | | meta:set_int(data.tier.."_EU_input", 0) |
| | | meta:set_string("infotext", S("%s Battery Box"):format(tier)) |
| | | meta:set_string("formspec", formspec) |
| | | meta:set_int(tier.."_EU_demand", 0) |
| | | meta:set_int(tier.."_EU_supply", 0) |
| | | meta:set_int(tier.."_EU_input", 0) |
| | | meta:set_float("internal_EU_charge", 0) |
| | | inv:set_size("src", 1) |
| | | inv:set_size("dst", 1) |
| | |
| | | interval = 1, |
| | | chance = 1, |
| | | action = function(pos, node, active_object_count, active_object_count_wider) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | local meta = minetest.get_meta(pos) |
| | | local eu_input = meta:get_int(data.tier.."_EU_input") |
| | | local eu_input = meta:get_int(tier.."_EU_input") |
| | | local current_charge = meta:get_int("internal_EU_charge") |
| | | local max_charge = data.max_charge |
| | | local charge_rate = data.charge_rate |
| | | local discharge_rate = data.discharge_rate |
| | | |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, data.tier) |
| | | technic.switching_station_timeout_count(pos, tier) |
| | | |
| | | -- Charge/discharge the battery with the input EUs |
| | | if eu_input >= 0 then |
| | | current_charge = math.min(current_charge + eu_input, max_charge) |
| | | current_charge = math.min(current_charge + eu_input, data.max_charge) |
| | | else |
| | | current_charge = math.max(current_charge + eu_input, 0) |
| | | end |
| | |
| | | current_charge = technic.charge_tools(meta, |
| | | current_charge, data.charge_step) |
| | | current_charge = technic.discharge_tools(meta, |
| | | current_charge, data.discharge_step, max_charge) |
| | | current_charge, data.discharge_step, |
| | | data.max_charge) |
| | | |
| | | -- We allow batteries to charge on less than the demand |
| | | meta:set_int(data.tier.."_EU_demand", |
| | | math.min(charge_rate, max_charge - current_charge)) |
| | | meta:set_int(data.tier.."_EU_supply", |
| | | math.min(discharge_rate, current_charge)) |
| | | meta:set_int(tier.."_EU_demand", |
| | | math.min(data.charge_rate, data.max_charge - current_charge)) |
| | | meta:set_int(tier.."_EU_supply", |
| | | math.min(data.discharge_rate, current_charge)) |
| | | |
| | | meta:set_int("internal_EU_charge", current_charge) |
| | | |
| | | -- Select node textures |
| | | local charge_count = math.ceil((current_charge / max_charge) * 8) |
| | | local charge_count = math.ceil((current_charge / data.max_charge) * 8) |
| | | charge_count = math.min(charge_count, 8) |
| | | charge_count = math.max(charge_count, 0) |
| | | local last_count = meta:get_float("last_side_shown") |
| | | if charge_count ~= last_count then |
| | | hacky_swap_node(pos,"technic:"..string.lower(data.tier).."_battery_box"..charge_count) |
| | | hacky_swap_node(pos,"technic:"..ltier.."_battery_box"..charge_count) |
| | | meta:set_float("last_side_shown", charge_count) |
| | | end |
| | | |
| | | local charge_percent = math.floor(current_charge / max_charge * 100) |
| | | local charge_percent = math.floor(current_charge / data.max_charge * 100) |
| | | meta:set_string("formspec", |
| | | data.formspec.. |
| | | formspec.. |
| | | "image[1,1;1,2;technic_power_meter_bg.png" |
| | | .."^[lowpart:"..charge_percent |
| | | ..":technic_power_meter_fg.png]") |
| | | |
| | | local infotext = S("%s Battery Box: %d/%d"):format(data.tier, current_charge, max_charge) |
| | | local infotext = S("%s Battery Box: %d/%d"):format(tier, |
| | | current_charge, data.max_charge) |
| | | if eu_input == 0 then |
| | | infotext = S("%s Idle"):format(infotext) |
| | | end |
| | |
| | | "label[1,5;Upgrade Slots]" |
| | | end |
| | | |
| | | data.formspec = formspec |
| | | |
| | | minetest.register_node("technic:"..ltier.."_electric_furnace", { |
| | | description = S("%s Electric furnace"):format(tier), |
| | | tiles = {"technic_"..ltier.."_electric_furnace_top.png", |
| | |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_stone_defaults(), |
| | | tube = data.tube and tube or nil, |
| | | technic = data, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local name = minetest.get_node(pos).name |
| | | local data = minetest.registered_nodes[name].technic |
| | | meta:set_string("infotext", S("%s Electric furnace"):format(data.tier)) |
| | | meta:set_string("infotext", S("%s Electric furnace"):format(tier)) |
| | | meta:set_int("tube_time", 0) |
| | | meta:set_string("formspec", data.formspec) |
| | | meta:set_string("formspec", formspec) |
| | | local inv = meta:get_inventory() |
| | | inv:set_size("src", 1) |
| | | inv:set_size("dst", 4) |
| | |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_stone_defaults(), |
| | | tube = data.tube and tube or nil, |
| | | technic = data, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local name = minetest.get_node(pos).name |
| | | local data = minetest.registered_nodes[name].technic |
| | | meta:set_string("infotext", S("%s Electric furnace", data.tier)) |
| | | meta:set_string("infotext", S("%s Electric furnace"):format(tier)) |
| | | meta:set_int("tube_time", 0) |
| | | meta:set_string("formspec", data.formspec) |
| | | meta:set_string("formspec", formspec) |
| | | local inv = meta:get_inventory() |
| | | inv:set_size("src", 1) |
| | | inv:set_size("dst", 4) |
| | |
| | | interval = 1, |
| | | chance = 1, |
| | | action = function(pos, node, active_object_count, active_object_count_wider) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | local meta = minetest.get_meta(pos) |
| | | local inv = meta:get_inventory() |
| | | local eu_input = meta:get_int(data.tier.."_EU_input") |
| | | local eu_input = meta:get_int(tier.."_EU_input") |
| | | |
| | | -- Machine information |
| | | local machine_name = S("%s Electric Furnace"):format(data.tier) |
| | | local machine_node = "technic:"..string.lower(data.tier).."_electric_furnace" |
| | | local machine_name = S("%s Electric Furnace"):format(tier) |
| | | local machine_node = "technic:"..ltier.."_electric_furnace" |
| | | local machine_demand = data.demand |
| | | |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, data.tier) |
| | | technic.switching_station_timeout_count(pos, tier) |
| | | |
| | | -- Check upgrade slots |
| | | local EU_upgrade, tube_upgrade = 0, 0 |
| | |
| | | items = inv:get_list("src")}) |
| | | if not result or result.time == 0 or |
| | | not inv:room_for_item("dst", result.item) then |
| | | meta:set_int(data.tier.."_EU_demand", 0) |
| | | meta:set_int(tier.."_EU_demand", 0) |
| | | hacky_swap_node(pos, machine_node) |
| | | meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
| | | return |
| | |
| | | technic.smelt_item(meta, result, data.speed) |
| | | |
| | | end |
| | | meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | end, |
| | | }) |
| | | |
| | |
| | | "list[current_name;upgrade2;2,4;1,1;]".. |
| | | "label[1,5;Upgrade Slots]" |
| | | end |
| | | data.formspec = formspec |
| | | |
| | | minetest.register_node("technic:"..ltier.."_grinder", { |
| | | description = S("%s Grinder"):format(tier), |
| | |
| | | "technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_front.png"}, |
| | | paramtype2 = "facedir", |
| | | groups = groups, |
| | | technic = data, |
| | | tube = data.tube and tube or nil, |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_wood_defaults(), |
| | | on_construct = function(pos) |
| | | local node = minetest.get_node(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | meta:set_string("infotext", S("%s Grinder"):format(data.tier)) |
| | | meta:set_string("infotext", S("%s Grinder"):format(tier)) |
| | | meta:set_int("tube_time", 0) |
| | | meta:set_string("formspec", data.formspec) |
| | | meta:set_string("formspec", formspec) |
| | | local inv = meta:get_inventory() |
| | | inv:set_size("src", 1) |
| | | inv:set_size("dst", 4) |
| | |
| | | groups = active_groups, |
| | | legacy_facedir_simple = true, |
| | | sounds = default.node_sound_wood_defaults(), |
| | | technic = data, |
| | | tube = data.tube and tube or nil, |
| | | can_dig = function(pos,player) |
| | | can_dig = function(pos, player) |
| | | local meta = minetest.get_meta(pos) |
| | | local inv = meta:get_inventory() |
| | | if not inv:is_empty("src") or not inv:is_empty("dst") or |
| | |
| | | interval = 1, |
| | | chance = 1, |
| | | action = function(pos, node, active_object_count, active_object_count_wider) |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | local meta = minetest.get_meta(pos) |
| | | local inv = meta:get_inventory() |
| | | local eu_input = meta:get_int(data.tier.."_EU_input") |
| | | local eu_input = meta:get_int(tier.."_EU_input") |
| | | |
| | | local machine_name = S("%s Grinder"):format(data.tier) |
| | | local machine_node = "technic:"..string.lower(data.tier).."_grinder" |
| | | local machine_name = S("%s Grinder"):format(tier) |
| | | local machine_node = "technic:"..ltier.."_grinder" |
| | | local machine_demand = data.demand |
| | | |
| | | -- Setup meta data if it does not exist. |
| | | if not eu_input then |
| | | meta:set_int(data.tier.."_EU_demand", machine_demand[1]) |
| | | meta:set_int(data.tier.."_EU_input", 0) |
| | | meta:set_int(tier.."_EU_demand", machine_demand[1]) |
| | | meta:set_int(tier.."_EU_input", 0) |
| | | return |
| | | end |
| | | |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, data.tier) |
| | | technic.switching_station_timeout_count(pos, tier) |
| | | |
| | | local EU_upgrade, tube_upgrade = 0, 0 |
| | | if data.upgrade then |
| | |
| | | if not result then |
| | | hacky_swap_node(pos, machine_node) |
| | | meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
| | | meta:set_int(data.tier.."_EU_demand", 0) |
| | | meta:set_int(tier.."_EU_demand", 0) |
| | | return |
| | | end |
| | | |
| | |
| | | end |
| | | end |
| | | end |
| | | meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
| | | end |
| | | }) |
| | | |
| | |
| | | type = "fixed", |
| | | fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, |
| | | }, |
| | | technic = data, |
| | | on_construct = function(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local name = minetest.get_node(pos).name |
| | | local tier = minetest.registered_nodes[name].technic.tier |
| | | meta:set_int(tier.."_EU_supply", 0) |
| | | end, |
| | | }) |
| | |
| | | -- To take care of some of it solar panels do not work outside daylight hours or if |
| | | -- built below -10m |
| | | local pos1 = {} |
| | | local data = minetest.registered_nodes[node.name].technic |
| | | local machine_name = S("%s Solar Array"):format(data.tier) |
| | | local machine_name = S("%s Solar Array"):format(tier) |
| | | pos1.y = pos.y + 1 |
| | | pos1.x = pos.x |
| | | pos1.z = pos.z |
| | |
| | | charge_to_give = math.max(charge_to_give, 0) |
| | | charge_to_give = math.min(charge_to_give, data.power * 50) |
| | | meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..charge_to_give.."EU)") |
| | | meta:set_int(data.tier.."_EU_supply", charge_to_give) |
| | | meta:set_int(tier.."_EU_supply", charge_to_give) |
| | | else |
| | | meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
| | | meta:set_int(data.tier.."_EU_supply", 0) |
| | | meta:set_int(tier.."_EU_supply", 0) |
| | | end |
| | | end, |
| | | }) |