2014-07-02 22:24:38 +02:00
|
|
|
|
|
|
|
local S = technic.getter
|
|
|
|
|
2017-04-11 06:26:11 -04:00
|
|
|
local fs_helpers = pipeworks.fs_helpers
|
2017-04-11 07:54:00 -04:00
|
|
|
local tube_entry = "^pipeworks_tube_connection_metallic.png"
|
2017-04-11 06:26:11 -04:00
|
|
|
|
2014-07-02 22:24:38 +02:00
|
|
|
local tube = {
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:add_item("src", stack)
|
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2017-04-11 06:26:11 -04:00
|
|
|
if meta:get_int("splitstacks") == 1 then
|
|
|
|
stack = stack:peek_item(1)
|
|
|
|
end
|
|
|
|
return inv:room_for_item("src", stack)
|
2014-07-02 22:24:38 +02:00
|
|
|
end,
|
|
|
|
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1},
|
|
|
|
}
|
|
|
|
|
2016-03-19 21:34:56 -04:00
|
|
|
local connect_default = {"bottom", "back", "left", "right"}
|
|
|
|
|
2014-08-17 23:57:01 +01:00
|
|
|
local function round(v)
|
|
|
|
return math.floor(v + 0.5)
|
|
|
|
end
|
|
|
|
|
2014-07-02 22:24:38 +02:00
|
|
|
function technic.register_base_machine(data)
|
|
|
|
local typename = data.typename
|
2014-07-15 18:29:36 +01:00
|
|
|
local input_size = technic.recipes[typename].input_size
|
2014-07-02 22:24:38 +02:00
|
|
|
local machine_name = data.machine_name
|
|
|
|
local machine_desc = data.machine_desc
|
|
|
|
local tier = data.tier
|
|
|
|
local ltier = string.lower(tier)
|
|
|
|
|
2016-03-19 21:34:56 -04:00
|
|
|
local groups = {cracky = 2, technic_machine = 1, ["technic_"..ltier] = 1}
|
2014-07-02 22:24:38 +02:00
|
|
|
if data.tube then
|
|
|
|
groups.tubedevice = 1
|
|
|
|
groups.tubedevice_receiver = 1
|
|
|
|
end
|
2016-03-19 21:34:56 -04:00
|
|
|
local active_groups = {not_in_creative_inventory = 1}
|
|
|
|
for k, v in pairs(groups) do active_groups[k] = v end
|
2014-07-02 22:24:38 +02:00
|
|
|
|
2017-04-25 18:25:16 +07:00
|
|
|
local formspec = function(data, progress_percentage)
|
|
|
|
local formspec_string = "invsize[8,9;]"..
|
|
|
|
"list[current_name;src;"..(3.75-input_size)..",1.5;"..input_size..",1;]"..
|
|
|
|
"list[current_name;dst;5,1;2,2;]"..
|
|
|
|
"list[current_player;main;0,5;8,4;]"..
|
|
|
|
"label[0,0;"..machine_desc:format(tier).."]"..
|
|
|
|
"listring[current_name;dst]"..
|
2015-06-18 04:09:27 +02:00
|
|
|
"listring[current_player;main]"..
|
2017-04-25 18:25:16 +07:00
|
|
|
"listring[current_name;src]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
|
|
|
|
(progress_percentage)..":gui_furnace_arrow_fg.png^[transformR270]"
|
|
|
|
if data.upgrade then
|
|
|
|
formspec_string = formspec_string..
|
|
|
|
"list[current_name;upgrade1;1,3;1,1;]"..
|
|
|
|
"list[current_name;upgrade2;2,3;1,1;]"..
|
|
|
|
"label[1,4;"..S("Upgrade Slots").."]"..
|
|
|
|
"listring[current_name;upgrade1]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[current_name;upgrade2]"..
|
|
|
|
"listring[current_player;main]"
|
|
|
|
end
|
|
|
|
return formspec_string
|
2014-07-02 22:24:38 +02:00
|
|
|
end
|
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local run = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local eu_input = meta:get_int(tier.."_EU_input")
|
|
|
|
|
|
|
|
local machine_desc_tier = machine_desc:format(tier)
|
|
|
|
local machine_node = "technic:"..ltier.."_"..machine_name
|
|
|
|
local machine_demand = data.demand
|
|
|
|
|
2017-04-25 18:25:16 +07:00
|
|
|
local update_formspec = function(result)
|
|
|
|
if result ~= nil then
|
|
|
|
meta:set_string("formspec", formspec(data, 100.0 * meta:get_int("src_time") / round(result.time * 10)))
|
|
|
|
else
|
|
|
|
meta:set_string("formspec", formspec(data, 0))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
-- Setup meta data if it does not exist.
|
|
|
|
if not eu_input then
|
|
|
|
meta:set_int(tier.."_EU_demand", machine_demand[1])
|
|
|
|
meta:set_int(tier.."_EU_input", 0)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local EU_upgrade, tube_upgrade = 0, 0
|
|
|
|
if data.upgrade then
|
|
|
|
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
|
|
|
|
end
|
|
|
|
if data.tube then
|
|
|
|
technic.handle_machine_pipeworks(pos, tube_upgrade)
|
|
|
|
end
|
|
|
|
|
2014-08-17 23:57:01 +01:00
|
|
|
local powered = eu_input >= machine_demand[EU_upgrade+1]
|
|
|
|
if powered then
|
|
|
|
meta:set_int("src_time", meta:get_int("src_time") + round(data.speed*10))
|
2014-07-11 11:00:46 +02:00
|
|
|
end
|
2014-08-17 23:57:01 +01:00
|
|
|
while true do
|
|
|
|
local result = technic.get_recipe(typename, inv:get_list("src"))
|
|
|
|
if not result then
|
|
|
|
technic.swap_node(pos, machine_node)
|
|
|
|
meta:set_string("infotext", S("%s Idle"):format(machine_desc_tier))
|
|
|
|
meta:set_int(tier.."_EU_demand", 0)
|
|
|
|
meta:set_int("src_time", 0)
|
2017-04-25 18:25:16 +07:00
|
|
|
update_formspec(result)
|
2014-08-17 23:57:01 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1])
|
2014-07-11 11:00:46 +02:00
|
|
|
technic.swap_node(pos, machine_node.."_active")
|
|
|
|
meta:set_string("infotext", S("%s Active"):format(machine_desc_tier))
|
2017-04-25 18:25:16 +07:00
|
|
|
update_formspec(result)
|
2014-08-17 23:57:01 +01:00
|
|
|
if meta:get_int("src_time") < round(result.time*10) then
|
|
|
|
if not powered then
|
|
|
|
technic.swap_node(pos, machine_node)
|
|
|
|
meta:set_string("infotext", S("%s Unpowered"):format(machine_desc_tier))
|
2014-07-15 18:29:36 +01:00
|
|
|
end
|
2014-08-17 23:57:01 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local output = result.output
|
|
|
|
if type(output) ~= "table" then output = { output } end
|
|
|
|
local output_stacks = {}
|
|
|
|
for _, o in ipairs(output) do
|
|
|
|
table.insert(output_stacks, ItemStack(o))
|
|
|
|
end
|
|
|
|
local room_for_output = true
|
|
|
|
inv:set_size("dst_tmp", inv:get_size("dst"))
|
|
|
|
inv:set_list("dst_tmp", inv:get_list("dst"))
|
|
|
|
for _, o in ipairs(output_stacks) do
|
|
|
|
if not inv:room_for_item("dst_tmp", o) then
|
|
|
|
room_for_output = false
|
|
|
|
break
|
2014-07-11 11:00:46 +02:00
|
|
|
end
|
2014-08-17 23:57:01 +01:00
|
|
|
inv:add_item("dst_tmp", o)
|
|
|
|
end
|
|
|
|
if not room_for_output then
|
2015-07-12 20:43:01 +02:00
|
|
|
technic.swap_node(pos, machine_node)
|
|
|
|
meta:set_string("infotext", S("%s Idle"):format(machine_desc_tier))
|
|
|
|
meta:set_int(tier.."_EU_demand", 0)
|
2014-08-17 23:57:01 +01:00
|
|
|
meta:set_int("src_time", round(result.time*10))
|
2017-04-25 18:25:16 +07:00
|
|
|
update_formspec(result)
|
2014-08-17 23:57:01 +01:00
|
|
|
return
|
2014-07-11 11:00:46 +02:00
|
|
|
end
|
2014-08-17 23:57:01 +01:00
|
|
|
meta:set_int("src_time", meta:get_int("src_time") - round(result.time*10))
|
2017-04-25 18:25:16 +07:00
|
|
|
update_formspec(result)
|
2014-08-17 23:57:01 +01:00
|
|
|
inv:set_list("src", result.new_input)
|
|
|
|
inv:set_list("dst", inv:get_list("dst_tmp"))
|
2014-07-11 11:00:46 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-11 06:26:11 -04:00
|
|
|
|
2017-04-11 07:54:00 -04:00
|
|
|
local tentry = tube_entry
|
|
|
|
if ltier == "lv" then
|
|
|
|
tentry = ""
|
|
|
|
end
|
2014-07-02 22:24:38 +02:00
|
|
|
minetest.register_node("technic:"..ltier.."_"..machine_name, {
|
|
|
|
description = machine_desc:format(tier),
|
2017-04-11 07:54:00 -04:00
|
|
|
tiles = {
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_top.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_bottom.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
2017-04-11 06:26:11 -04:00
|
|
|
"technic_"..ltier.."_"..machine_name.."_front.png"
|
|
|
|
},
|
2014-07-02 22:24:38 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = groups,
|
|
|
|
tube = data.tube and tube or nil,
|
2016-03-19 21:34:56 -04:00
|
|
|
connect_sides = data.connect_sides or connect_default,
|
2014-07-02 22:24:38 +02:00
|
|
|
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)
|
2017-04-11 06:26:11 -04:00
|
|
|
|
|
|
|
local form_buttons = ""
|
|
|
|
if not string.find(node.name, ":lv_") then
|
|
|
|
form_buttons = fs_helpers.cycling_button(
|
|
|
|
meta,
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_base,
|
2017-04-11 06:26:11 -04:00
|
|
|
"splitstacks",
|
|
|
|
{
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_off,
|
|
|
|
pipeworks.button_on
|
2017-04-11 06:26:11 -04:00
|
|
|
}
|
2017-04-11 19:16:50 -04:00
|
|
|
)..pipeworks.button_label
|
2017-04-11 06:26:11 -04:00
|
|
|
end
|
|
|
|
|
2014-07-02 22:24:38 +02:00
|
|
|
meta:set_string("infotext", machine_desc:format(tier))
|
|
|
|
meta:set_int("tube_time", 0)
|
2017-04-25 18:25:16 +07:00
|
|
|
meta:set_string("formspec", formspec(data, 0)..form_buttons)
|
2014-07-02 22:24:38 +02:00
|
|
|
local inv = meta:get_inventory()
|
2014-07-15 18:29:36 +01:00
|
|
|
inv:set_size("src", input_size)
|
2014-07-02 22:24:38 +02:00
|
|
|
inv:set_size("dst", 4)
|
|
|
|
inv:set_size("upgrade1", 1)
|
|
|
|
inv:set_size("upgrade2", 1)
|
|
|
|
end,
|
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
2015-03-07 19:45:57 -06:00
|
|
|
after_place_node = data.tube and pipeworks.after_place,
|
2017-04-11 06:26:11 -04:00
|
|
|
after_dig_node = technic.machine_after_dig_node,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if not pipeworks.may_configure(pos, sender) then return end
|
|
|
|
fs_helpers.on_receive_fields(pos, fields)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local form_buttons = ""
|
|
|
|
if not string.find(node.name, ":lv_") then
|
|
|
|
form_buttons = fs_helpers.cycling_button(
|
|
|
|
meta,
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_base,
|
2017-04-11 06:26:11 -04:00
|
|
|
"splitstacks",
|
|
|
|
{
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_off,
|
|
|
|
pipeworks.button_on
|
2017-04-11 06:26:11 -04:00
|
|
|
}
|
2017-04-11 19:16:50 -04:00
|
|
|
)..pipeworks.button_label
|
2017-04-11 06:26:11 -04:00
|
|
|
end
|
2017-04-25 18:25:16 +07:00
|
|
|
meta:set_string("formspec", formspec(data, 0)..form_buttons)
|
2017-04-11 06:26:11 -04:00
|
|
|
end,
|
2014-07-02 22:24:38 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("technic:"..ltier.."_"..machine_name.."_active",{
|
|
|
|
description = machine_desc:format(tier),
|
2017-04-11 07:54:00 -04:00
|
|
|
tiles = {
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_top.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_bottom.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
|
|
|
"technic_"..ltier.."_"..machine_name.."_side.png"..tentry,
|
2017-04-11 06:26:11 -04:00
|
|
|
"technic_"..ltier.."_"..machine_name.."_front_active.png"
|
|
|
|
},
|
2014-07-02 22:24:38 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
drop = "technic:"..ltier.."_"..machine_name,
|
|
|
|
groups = active_groups,
|
2016-03-19 21:34:56 -04:00
|
|
|
connect_sides = data.connect_sides or connect_default,
|
2014-07-02 22:24:38 +02:00
|
|
|
legacy_facedir_simple = true,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
tube = data.tube and tube or nil,
|
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
|
|
|
technic_disabled_machine_name = "technic:"..ltier.."_"..machine_name,
|
2017-04-11 06:26:11 -04:00
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if not pipeworks.may_configure(pos, sender) then return end
|
|
|
|
fs_helpers.on_receive_fields(pos, fields)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local form_buttons = ""
|
|
|
|
if not string.find(node.name, ":lv_") then
|
|
|
|
form_buttons = fs_helpers.cycling_button(
|
|
|
|
meta,
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_base,
|
2017-04-11 06:26:11 -04:00
|
|
|
"splitstacks",
|
|
|
|
{
|
2017-04-11 19:16:50 -04:00
|
|
|
pipeworks.button_off,
|
|
|
|
pipeworks.button_on
|
2017-04-11 06:26:11 -04:00
|
|
|
}
|
2017-04-11 19:16:50 -04:00
|
|
|
)..pipeworks.button_label
|
2017-04-11 06:26:11 -04:00
|
|
|
end
|
2017-04-25 18:25:16 +07:00
|
|
|
meta:set_string("formspec", formspec(data, 0)..form_buttons)
|
2017-04-11 06:26:11 -04:00
|
|
|
end,
|
2014-07-02 22:24:38 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name, technic.receiver)
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name.."_active", technic.receiver)
|
|
|
|
|
|
|
|
end -- End registration
|
|
|
|
|