diff options
Diffstat (limited to 'technic/machines/register')
-rw-r--r-- | technic/machines/register/battery_box.lua | 93 | ||||
-rw-r--r-- | technic/machines/register/generator.lua | 158 | ||||
-rw-r--r-- | technic/machines/register/machine_base.lua | 99 |
3 files changed, 293 insertions, 57 deletions
diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 2a45b13..7238d6d 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -2,6 +2,9 @@ local digilines_path = minetest.get_modpath("digilines") local S = technic.getter +local tube_entry = "^pipeworks_tube_connection_metallic.png" + +local fs_helpers = pipeworks.fs_helpers technic.register_power_tool("technic:battery", 10000) technic.register_power_tool("technic:red_energy_crystal", 50000) @@ -50,16 +53,49 @@ local tube = { end local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local onestack = stack:peek_item(1) if direction.y > 0 then - return inv:room_for_item("src", onestack) + if meta:get_int("split_src_stacks") == 1 then + stack = stack:peek_item(1) + end + return inv:room_for_item("src", stack) else - return inv:room_for_item("dst", onestack) + if meta:get_int("split_dst_stacks") == 1 then + stack = stack:peek_item(1) + end + return inv:room_for_item("dst", stack) end end, connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, } +local function add_on_off_buttons(meta, ltier, charge_percent) + local formspec = "" + if ltier == "mv" or ltier == "hv" then + formspec = "image[1,1;1,2;technic_power_meter_bg.png" + .."^[lowpart:"..charge_percent + ..":technic_power_meter_fg.png]".. + fs_helpers.cycling_button( + meta, + "image_button[3,2.0;1,0.6", + "split_src_stacks", + { + pipeworks.button_off, + pipeworks.button_on + } + ).."label[3.9,2.01;Allow splitting incoming 'charge' stacks from tubes]".. + fs_helpers.cycling_button( + meta, + "image_button[3,2.5;1,0.6", + "split_dst_stacks", + { + pipeworks.button_off, + pipeworks.button_on + } + ).."label[3.9,2.51;Allow splitting incoming 'discharge' stacks]" + end + return formspec +end + function technic.register_battery_box(data) local tier = data.tier local ltier = string.lower(tier) @@ -79,6 +115,7 @@ function technic.register_battery_box(data) "listring[current_player;main]".. "listring[context;src]".. "listring[current_player;main]" + if digilines_path then formspec = formspec.."button[0.6,3.7;2,1;edit_channel;edit Channel]" end @@ -150,12 +187,7 @@ function technic.register_battery_box(data) end local charge_percent = math.floor(current_charge / max_charge * 100) - meta:set_string("formspec", - formspec.. - "image[1,1;1,2;technic_power_meter_bg.png" - .."^[lowpart:"..charge_percent - ..":technic_power_meter_fg.png]") - + meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, charge_percent)) local infotext = S("@1 Battery Box: @2/@3", tier, technic.pretty_num(current_charge), technic.pretty_num(max_charge)) if eu_input == 0 then @@ -176,11 +208,16 @@ function technic.register_battery_box(data) groups.tubedevice_receiver = 1 end + local tentry = tube_entry + if ltier == "lv" then + tentry = "" + end + minetest.register_node("technic:"..ltier.."_battery_box"..i, { description = S("%s Battery Box"):format(tier), tiles = { - "technic_"..ltier.."_battery_box_top.png", - "technic_"..ltier.."_battery_box_bottom.png", + "technic_"..ltier.."_battery_box_top.png"..tentry, + "technic_"..ltier.."_battery_box_bottom.png"..tentry, "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png", "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png", "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png", @@ -193,11 +230,17 @@ function technic.register_battery_box(data) drop = "technic:"..ltier.."_battery_box0", on_construct = function(pos) local meta = minetest.get_meta(pos) + local EU_upgrade, tube_upgrade = 0, 0 + if data.upgrade then + EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta) + end + local max_charge = data.max_charge * (1 + EU_upgrade / 10) + local charge = meta:get_int("internal_EU_charge") + local cpercent = math.floor(charge / max_charge * 100) local inv = meta:get_inventory() local node = minetest.get_node(pos) - meta:set_string("infotext", S("%s Battery Box"):format(tier)) - meta:set_string("formspec", formspec) + meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent)) meta:set_string("channel", ltier.."_battery_box"..minetest.pos_to_string(pos)) meta:set_int(tier.."_EU_demand", 0) meta:set_int(tier.."_EU_supply", 0) @@ -216,13 +259,28 @@ function technic.register_battery_box(data) after_place_node = data.tube and pipeworks.after_place, after_dig_node = technic.machine_after_dig_node, on_receive_fields = function(pos, formname, fields, sender) - if not fields.edit_channel then - return - end local meta = minetest.get_meta(pos) - minetest.show_formspec(sender:get_player_name(), + local nodename = minetest.get_node(pos).name + if fields.edit_channel then + minetest.show_formspec(sender:get_player_name(), "technic:battery_box_edit_channel"..minetest.pos_to_string(pos), "field[channel;Digiline Channel;"..meta:get_string("channel").."]") + elseif fields["fs_helpers_cycling:0:split_src_stacks"] + or fields["fs_helpers_cycling:0:split_dst_stacks"] + or fields["fs_helpers_cycling:1:split_src_stacks"] + or fields["fs_helpers_cycling:1:split_dst_stacks"] then + local meta = minetest.get_meta(pos) + if not pipeworks.may_configure(pos, sender) then return end + fs_helpers.on_receive_fields(pos, fields) + local EU_upgrade, tube_upgrade = 0, 0 + if data.upgrade then + EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta) + end + local max_charge = data.max_charge * (1 + EU_upgrade / 10) + local charge = meta:get_int("internal_EU_charge") + local cpercent = math.floor(charge / max_charge * 100) + meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent)) + end end, digiline = { receptor = {action = function() end}, @@ -278,7 +336,6 @@ minetest.register_on_player_receive_fields( end ) - function technic.charge_tools(meta, batt_charge, charge_step) local inv = meta:get_inventory() if inv:is_empty("src") then diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua index f3ada1f..9062d09 100644 --- a/technic/machines/register/generator.lua +++ b/technic/machines/register/generator.lua @@ -1,5 +1,8 @@ local S = technic.getter +local fs_helpers = pipeworks.fs_helpers +local tube_entry = "^pipeworks_tube_connection_metallic.png" + local tube = { insert_object = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) @@ -9,13 +12,16 @@ local tube = { can_insert = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local onestack = stack:peek_item(1) - return inv:room_for_item("src", onestack) + if meta:get_int("splitstacks") == 1 then + stack = stack:peek_item(1) + end + return inv:room_for_item("src", stack) end, connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, } -function technic.register_generator(data) +function technic.register_generator(data) + local tier = data.tier local ltier = string.lower(tier) @@ -77,21 +83,41 @@ function technic.register_generator(data) if burn_totaltime == 0 then burn_totaltime = 1 end local percent = math.floor((burn_time / burn_totaltime) * 100) meta:set_string("infotext", desc.." ("..percent.."%)") - meta:set_string("formspec", - "size[8, 9]".. - "label[0, 0;"..minetest.formspec_escape(desc).."]".. - "list[current_name;src;3, 1;1, 1;]".. - "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. - (percent)..":default_furnace_fire_fg.png]".. - "list[current_player;main;0, 5;8, 4;]".. - "listring[]") + + local form_buttons = "" + if ltier ~= "lv" then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("formspec", + "size[8, 9]".. + "label[0, 0;"..minetest.formspec_escape(desc).."]".. + "list[current_name;src;3, 1;1, 1;]".. + "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. + (percent)..":default_furnace_fire_fg.png]".. + "list[current_player;main;0, 5;8, 4;]".. + "listring[]".. + form_buttons + ) end - + minetest.register_node("technic:"..ltier.."_generator", { description = desc, - tiles = {"technic_"..ltier.."_generator_top.png", "technic_machine_bottom.png", - "technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_side.png", - "technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_front.png"}, + tiles = { + "technic_"..ltier.."_generator_top.png"..tube_entry, + "technic_machine_bottom.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_front.png" + }, paramtype2 = "facedir", groups = groups, connect_sides = {"bottom", "back", "left", "right"}, @@ -100,11 +126,24 @@ function technic.register_generator(data) tube = data.tube and tube or nil, on_construct = function(pos) local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) meta:set_string("infotext", desc) meta:set_int(data.tier.."_EU_supply", 0) meta:set_int("burn_time", 0) meta:set_int("tube_time", 0) - meta:set_string("formspec", generator_formspec) + local form_buttons = "" + if not string.find(node.name, ":lv_") then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("formspec", generator_formspec..form_buttons) local inv = meta:get_inventory() inv:set_size("src", 1) end, @@ -114,14 +153,39 @@ function technic.register_generator(data) allow_metadata_inventory_move = technic.machine_inventory_move, technic_run = run, after_place_node = data.tube and pipeworks.after_place, - after_dig_node = technic.machine_after_dig_node + after_dig_node = technic.machine_after_dig_node, + on_receive_fields = function(pos, formname, fields, sender) + if not pipeworks.may_configure(pos, sender) then return end + fs_helpers.on_receive_fields(pos, fields) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + local form = generator_formspec + local form_buttons = "" + if not string.find(node.name, ":lv_") then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("formspec", generator_formspec..form_buttons) + end, }) minetest.register_node("technic:"..ltier.."_generator_active", { description = desc, - tiles = {"technic_"..ltier.."_generator_top.png", "technic_machine_bottom.png", - "technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_side.png", - "technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_front_active.png"}, + tiles = { + "technic_"..ltier.."_generator_top.png"..tube_entry, + "technic_machine_bottom.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_side.png"..tube_entry, + "technic_"..ltier.."_generator_front_active.png" + }, paramtype2 = "facedir", groups = active_groups, connect_sides = {"bottom"}, @@ -130,6 +194,7 @@ function technic.register_generator(data) tube = data.tube and tube or nil, drop = "technic:"..ltier.."_generator", can_dig = technic.machine_can_dig, + after_dig_node = technic.machine_after_dig_node, allow_metadata_inventory_put = technic.machine_inventory_put, allow_metadata_inventory_take = technic.machine_inventory_take, allow_metadata_inventory_move = technic.machine_inventory_move, @@ -140,7 +205,8 @@ function technic.register_generator(data) end, on_timer = function(pos, node) local meta = minetest.get_meta(pos) - + local node = minetest.get_node(pos) + -- Connected back? if meta:get_int(tier.."_EU_timeout") > 0 then return false end @@ -158,6 +224,19 @@ function technic.register_generator(data) burn_time = burn_time - 1 meta:set_int("burn_time", burn_time) local percent = math.floor(burn_time / burn_totaltime * 100) + + local form_buttons = "" + if not string.find(node.name, ":lv_") then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end meta:set_string("formspec", "size[8, 9]".. "label[0, 0;"..minetest.formspec_escape(desc).."]".. @@ -165,9 +244,44 @@ function technic.register_generator(data) "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. (percent)..":default_furnace_fire_fg.png]".. "list[current_player;main;0, 5;8, 4;]".. - "listring[]") + "listring[]".. + form_buttons + ) return true end, + on_receive_fields = function(pos, formname, fields, sender) + if not pipeworks.may_configure(pos, sender) then return end + fs_helpers.on_receive_fields(pos, fields) + local meta = minetest.get_meta(pos) + local node = minetest.get_node(pos) + local form_buttons = "" + if not string.find(node.name, ":lv_") then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + + local burn_totaltime = meta:get_int("burn_totaltime") or 0 + local burn_time = meta:get_int("burn_time") + local percent = math.floor(burn_time / burn_totaltime * 100) + + meta:set_string("formspec", + "size[8, 9]".. + "label[0, 0;"..minetest.formspec_escape(desc).."]".. + "list[current_name;src;3, 1;1, 1;]".. + "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:".. + (percent)..":default_furnace_fire_fg.png]".. + "list[current_player;main;0, 5;8, 4;]".. + "listring[]".. + form_buttons + ) + end, }) technic.register_machine(tier, "technic:"..ltier.."_generator", technic.producer) diff --git a/technic/machines/register/machine_base.lua b/technic/machines/register/machine_base.lua index d479773..0c6a6b3 100644 --- a/technic/machines/register/machine_base.lua +++ b/technic/machines/register/machine_base.lua @@ -1,6 +1,9 @@ local S = technic.getter +local fs_helpers = pipeworks.fs_helpers +local tube_entry = "^pipeworks_tube_connection_metallic.png" + local tube = { insert_object = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) @@ -10,8 +13,10 @@ local tube = { can_insert = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local onestack = stack:peek_item(1) - return inv:room_for_item("src", onestack) + if meta:get_int("splitstacks") == 1 then + stack = stack:peek_item(1) + end + return inv:room_for_item("src", stack) end, connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1}, } @@ -134,15 +139,21 @@ function technic.register_base_machine(data) inv:set_list("dst", inv:get_list("dst_tmp")) end end - + + local tentry = tube_entry + if ltier == "lv" then + tentry = "" + end minetest.register_node("technic:"..ltier.."_"..machine_name, { description = machine_desc:format(tier), - tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", - "technic_"..ltier.."_"..machine_name.."_bottom.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_front.png"}, + 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, + "technic_"..ltier.."_"..machine_name.."_front.png" + }, paramtype2 = "facedir", groups = groups, tube = data.tube and tube or nil, @@ -152,9 +163,23 @@ function technic.register_base_machine(data) on_construct = function(pos) local node = minetest.get_node(pos) local meta = minetest.get_meta(pos) + + local form_buttons = "" + if not string.find(node.name, ":lv_") then + form_buttons = fs_helpers.cycling_button( + meta, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("infotext", machine_desc:format(tier)) meta:set_int("tube_time", 0) - meta:set_string("formspec", formspec) + meta:set_string("formspec", formspec..form_buttons) local inv = meta:get_inventory() inv:set_size("src", input_size) inv:set_size("dst", 4) @@ -167,17 +192,38 @@ function technic.register_base_machine(data) allow_metadata_inventory_move = technic.machine_inventory_move, technic_run = run, after_place_node = data.tube and pipeworks.after_place, - after_dig_node = technic.machine_after_dig_node + 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, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("formspec", formspec..form_buttons) + end, }) minetest.register_node("technic:"..ltier.."_"..machine_name.."_active",{ description = machine_desc:format(tier), - tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", - "technic_"..ltier.."_"..machine_name.."_bottom.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_side.png", - "technic_"..ltier.."_"..machine_name.."_front_active.png"}, + 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, + "technic_"..ltier.."_"..machine_name.."_front_active.png" + }, paramtype2 = "facedir", drop = "technic:"..ltier.."_"..machine_name, groups = active_groups, @@ -191,6 +237,25 @@ function technic.register_base_machine(data) allow_metadata_inventory_move = technic.machine_inventory_move, technic_run = run, technic_disabled_machine_name = "technic:"..ltier.."_"..machine_name, + 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, + pipeworks.button_base, + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label + end + meta:set_string("formspec", formspec..form_buttons) + end, }) technic.register_machine(tier, "technic:"..ltier.."_"..machine_name, technic.receiver) |