mirror of
https://github.com/minetest-mods/technic.git
synced 2024-12-26 02:40:29 +01:00
Use upvalues in registrations
This commit is contained in:
parent
08db41ee4d
commit
76a8acbe5b
@ -108,8 +108,6 @@ function technic.register_alloy_furnace(data)
|
||||
"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",
|
||||
@ -121,17 +119,14 @@ function technic.register_alloy_furnace(data)
|
||||
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)
|
||||
@ -166,7 +161,6 @@ function technic.register_alloy_furnace(data)
|
||||
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)
|
||||
@ -206,24 +200,23 @@ function technic.register_alloy_furnace(data)
|
||||
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
|
||||
@ -248,7 +241,7 @@ function technic.register_alloy_furnace(data)
|
||||
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
|
||||
|
||||
@ -277,7 +270,7 @@ function technic.register_alloy_furnace(data)
|
||||
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,
|
||||
})
|
||||
|
||||
|
@ -5,7 +5,7 @@ function technic.register_battery_box(data)
|
||||
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;]"..
|
||||
@ -33,18 +33,16 @@ function technic.register_battery_box(data)
|
||||
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)
|
||||
@ -73,20 +71,16 @@ function technic.register_battery_box(data)
|
||||
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
|
||||
@ -95,34 +89,36 @@ function technic.register_battery_box(data)
|
||||
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
|
||||
|
@ -44,8 +44,6 @@ function technic.register_electric_furnace(data)
|
||||
"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",
|
||||
@ -59,14 +57,12 @@ function technic.register_electric_furnace(data)
|
||||
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)
|
||||
@ -101,14 +97,13 @@ function technic.register_electric_furnace(data)
|
||||
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)
|
||||
@ -153,18 +148,17 @@ function technic.register_electric_furnace(data)
|
||||
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
|
||||
@ -181,7 +175,7 @@ function technic.register_electric_furnace(data)
|
||||
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
|
||||
@ -198,7 +192,7 @@ function technic.register_electric_furnace(data)
|
||||
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,
|
||||
})
|
||||
|
||||
|
@ -41,7 +41,6 @@ function technic.register_grinder(data)
|
||||
"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),
|
||||
@ -50,17 +49,15 @@ function technic.register_grinder(data)
|
||||
"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)
|
||||
@ -90,9 +87,8 @@ function technic.register_grinder(data)
|
||||
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
|
||||
@ -129,24 +125,23 @@ function technic.register_grinder(data)
|
||||
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
|
||||
@ -161,7 +156,7 @@ function technic.register_grinder(data)
|
||||
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
|
||||
|
||||
@ -186,7 +181,7 @@ function technic.register_grinder(data)
|
||||
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
|
||||
})
|
||||
|
||||
|
@ -19,11 +19,9 @@ function technic.register_solar_array(data)
|
||||
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,
|
||||
})
|
||||
@ -42,8 +40,7 @@ function technic.register_solar_array(data)
|
||||
-- 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
|
||||
@ -60,10 +57,10 @@ function technic.register_solar_array(data)
|
||||
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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user