From 2316a655b947c261d8234ddf6d58440b62607a02 Mon Sep 17 00:00:00 2001 From: The4codeblocks <72419529+The4codeblocks@users.noreply.github.com> Date: Wed, 10 Jun 2026 04:32:17 -0500 Subject: [PATCH 01/12] null commit, make branch From 3cbf42d9ec0c99b2fc208b6e589213e5ae0d0451 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 10 Jun 2026 10:06:46 -0500 Subject: [PATCH 02/12] redone battery box GUI --- technic/machines/register/battery_box.lua | 175 ++++++++++++++------ technic/textures/technic_arrowhead.png | Bin 0 -> 194 bytes technic/textures/technic_power_meter_bg.png | Bin 220 -> 243 bytes 3 files changed, 122 insertions(+), 53 deletions(-) create mode 100644 technic/textures/technic_arrowhead.png diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 99173233..14885760 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -1,5 +1,5 @@ -local digilines_path = core.get_modpath("digilines") +local has_digilines = core.global_exists("digilines") local S = technic.getter local tube_entry = "^pipeworks_tube_connection_metallic.png" @@ -114,66 +114,135 @@ function technic.register_battery_box(nodename, data) local tier = def.tier local ltier = string.lower(tier) - local size = core.get_modpath("mcl_formspec") and "size[9,9]" or "size[8,9]" - local formspec = - size.. - "image[1,1;1,2;technic_power_meter_bg.png]".. - "list[context;src;3,1;1,1;]".. - "image[4,1;1,1;technic_battery_reload.png]".. - "list[context;dst;5,1;1,1;]".. - "label[0,0;"..S("@1 Battery Box", S(tier)).."]".. - "label[3,0;"..S("Charge").."]".. - "label[5,0;"..S("Discharge").."]".. - "label[1,3;"..S("Power level").."]".. - (def.upgrade and - "list[context;upgrade1;3.5,3;1,1;]".. - "list[context;upgrade2;4.5,3;1,1;]".. - "label[3.5,4;"..S("Upgrade Slots").."]" - or "") - - if core.get_modpath("mcl_formspec") then - formspec = formspec.. - mcl_formspec.get_itemslot_bg(3,1,1,1).. - mcl_formspec.get_itemslot_bg(5,1,1,1).. - -- player inventory - "list[current_player;main;0,4.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - -- upgrade - (def.upgrade and - mcl_formspec.get_itemslot_bg(3.5,3,1,1).. - mcl_formspec.get_itemslot_bg(4.5,3,1,1) - or "") - else - formspec = formspec.. - "list[current_player;main;0,5;8,4;]" + local has_mcl_formspec = core.global_exists("mcl_formspec") + local has_upgrades = def.upgrade + + local slot_size, slot_spacing = 1, 0.25 + local slot_interval = slot_size + slot_spacing + local margin_x, margin_y = 0.5, 0.5 + local separation = 0.5 + local machine_section_h = 5 + local plrinv_w, plrinv_h = 8, 4 + if has_mcl_formspec then + plrinv_w = 9 + end + local body_width = plrinv_w * slot_interval - slot_spacing + local plrinv_y = machine_section_h + separation + local body_height = plrinv_y + plrinv_h * slot_interval - slot_spacing + + local charge_arrow_length = 2 + local charge_arrow_margin = 0.25 + local charge_arrowhead_length = 0.25 + local upgrades_x, upgrades_y = body_width - (slot_size + slot_spacing + slot_size), machine_section_h - slot_size + local energy_bar_w, energy_bar_h = 1, 2.5 + local subject_w = energy_bar_w + charge_arrow_margin * 2 + charge_arrow_length + slot_size + local subject_h = energy_bar_h + local energy_bar_x, energy_bar_y = (body_width - subject_w)/2, 0.75 + local label_offset = 0.2 + + local formspec_base = {} + table.insert(formspec_base, "formspec_version[4]") + table.insert(formspec_base, ("size[%.2f,%.2f]"):format(2 * margin_x + body_width, 2 * margin_y + body_height)) + local _charge_arrow_begin = margin_x + energy_bar_x + energy_bar_w + charge_arrow_margin + local _charge_slot_x = margin_x + energy_bar_x + subject_w - slot_size + local _charge_begin_y = margin_y + energy_bar_y + local _arrow_thickness = charge_arrowhead_length + table.insert(formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") + :format(_charge_slot_x, _charge_begin_y)) + table.insert(formspec_base, ("list[context;dst;%.2f,%.2f;1,1;]") + :format(_charge_slot_x, _charge_begin_y + subject_h - slot_size)) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(_charge_slot_x, _charge_begin_y + slot_size + label_offset, S("Charge"))) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(_charge_slot_x, _charge_begin_y + subject_h + label_offset, S("Discharge"))) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _charge_arrow_begin, _charge_begin_y + (slot_size - _arrow_thickness)/2, + charge_arrow_length - charge_arrowhead_length, _arrow_thickness, + "blank.png^[invert:ga" + )) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _charge_arrow_begin + charge_arrow_length - charge_arrowhead_length, + _charge_begin_y + slot_size/2 - charge_arrowhead_length, + charge_arrowhead_length, charge_arrowhead_length * 2, + "technic_arrowhead.png^[invert:rb" + )) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _charge_arrow_begin + charge_arrowhead_length, + _charge_begin_y + subject_h - (slot_size + _arrow_thickness)/2, + charge_arrow_length - charge_arrowhead_length, _arrow_thickness, + "blank.png^[invert:ra" + )) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _charge_arrow_begin, + _charge_begin_y + subject_h - slot_size/2 - charge_arrowhead_length, + charge_arrowhead_length, charge_arrowhead_length * 2, + "technic_arrowhead.png^[transformFX^[invert:gb" + )) + if has_upgrades then + table.insert(formspec_base, ("list[context;upgrade1;%.2f,%.2f;1,1;]") + :format(margin_x + upgrades_x, margin_y + upgrades_y)) + table.insert(formspec_base, ("list[context;upgrade2;%.2f,%.2f;1,1;]") + :format(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y)) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(margin_x + upgrades_x, margin_y + upgrades_y + slot_size + label_offset, S("Upgrade Slots"))) end - -- listrings - formspec = formspec.. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]".. - (def.upgrade and - "listring[context;upgrade1]".. - "listring[current_player;main]".. - "listring[context;upgrade2]".. - "listring[current_player;main]" - or "") - + table.insert(formspec_base, "listring[context;dst]") + table.insert(formspec_base, "listring[current_player;main]") + table.insert(formspec_base, "listring[context;src]") + table.insert(formspec_base, "listring[current_player;main]") + if has_upgrades then + table.insert(formspec_base, "listring[context;upgrade1]") + table.insert(formspec_base, "listring[current_player;main]") + table.insert(formspec_base, "listring[context;upgrade2]") + table.insert(formspec_base, "listring[current_player;main]") + end + -- player inventory + if has_mcl_formspec then + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) + table.insert(formspec_base,"list[current_player;main;0,4.5;9,3;9]") + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) + table.insert(formspec_base,"list[current_player;main;0,7.74;9,1;]") + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) + if has_upgrades then + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3.5,3,1,1)) + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(4.5,3,1,1)) + end + else + table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) + end + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;technic_power_meter_bg.png]") + :format(margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h)) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(margin_x, margin_y, S("@1 Battery Box", S(tier)))) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(margin_x + energy_bar_x, margin_y + energy_bar_y + energy_bar_h + label_offset, S("Power level"))) + formspec_base = table.concat(formspec_base) -- -- Generate formspec with power meter -- local function get_formspec(charge_ratio, channel) - return formspec .. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:" .. - math.floor(charge_ratio * 100) .. ":technic_power_meter_fg.png]" .. - (digilines_path and - ("field[0.3,4;2.2,1;channel;"..S("Digiline Channel")..";${channel}]".. - "button[2,3.7;1,1;setchannel;"..S("Save").."]") or "") + local formspec = {formspec_base} + table.insert(formspec, ("image[%.2f,%.2f;%.2f,%.2f;technic_power_meter_bg.png^[lowpart:%d:technic_power_meter_fg.png]"): + format(margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h, charge_ratio * 100)) + if has_digilines then + local channel_w, channel_h = 2.5, 0.8 + local button_w, button_h = 1, channel_h + local channel_x, channel_y = 0, machine_section_h - channel_h + table.insert(formspec, ("field[%.2f,%.2f;%.2f,%.2f;channel;%s;${channel}]") + :format(margin_x + channel_x, margin_y + channel_y, channel_w, channel_h, S("Digiline Channel"))) + table.insert(formspec, ("button[%.2f,%.2f;%.2f,%.2f;setchannel;%s]") + :format(margin_x + channel_x + channel_w, margin_y + channel_y, button_w, button_h, S("Save"))) + end + return table.concat(formspec) end diff --git a/technic/textures/technic_arrowhead.png b/technic/textures/technic_arrowhead.png new file mode 100644 index 0000000000000000000000000000000000000000..164b0f12ebbb4a9c8333992a8e3cac73388881de GIT binary patch literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5!3HFyJAa%3Qk|YIjv*eMN3S|^9Z=wLxhVO* z{&|UNgs+J(cj?l`{{_m2&hUt@W<0=q>DRKZEgu6MZ`lM)WDO7$511fuLMd9IS*B5V z5>uInREGfP2LZ_$6NL sM~3O<4b~|Yj8}fJh9ohR+Z!|3yyS5)Xz<^51?VUSPgg&ebxsLQ0EP@gfB*mh literal 0 HcmV?d00001 diff --git a/technic/textures/technic_power_meter_bg.png b/technic/textures/technic_power_meter_bg.png index bd95e9b10a1365d36ae049a95e1be5235c457c3f..90010c94fd95ccb0eecf47781a5f6e4f59cd2110 100644 GIT binary patch delta 215 zcmV;|04V?50rLTnB!9X|L_t(oh3(WaP6IIzM&Zw~%^Bb}T#gHHi>)ZOMy_*)L=-8g zf`k-ALsn31>aA8g6#gY^ijg%>nx{#46qsG)@D2cFlPTjvbNt~vaYaQ=An6hYXEg`z zU%lKNlyZ{O#ZE%?D=q))4uk`2atFpiJHB!L;5tzYInTZBKu|cqst$~Uwja2BkrK7e zbt&C}aDYwjz%%WHPfWK0Icf36YU+}=G~TCT}pQ#9H8HU@D+pu`~f>{CXYqy RxkCT|002ovPDHLkV1k=-V6OlG delta 192 zcmV;x06+ip0o(zQB!8nxL_t(o!|jwY3c^4TMc>cv<`6ls7w{CO&JCkbt0h<`8DXK(*JcJW|Fp zQ9T6$5{5qT;SBtR2bx;eo}jzKFhYtDf-{gK15GVE?4W;w1UV_q-96wQ*h+Q*9>55M urJRBM7}!X51zv!b<-$GS9&iu*_yZF}1U^if0RQ^{0000 Date: Wed, 10 Jun 2026 11:58:01 -0500 Subject: [PATCH 03/12] batbox tooltip --- technic/machines/register/battery_box.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 14885760..417c9bb6 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -229,10 +229,16 @@ function technic.register_battery_box(nodename, data) -- -- Generate formspec with power meter -- - local function get_formspec(charge_ratio, channel) + local function get_formspec(charge_ratio, current_charge, max_charge) local formspec = {formspec_base} - table.insert(formspec, ("image[%.2f,%.2f;%.2f,%.2f;technic_power_meter_bg.png^[lowpart:%d:technic_power_meter_fg.png]"): - format(margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h, charge_ratio * 100)) + table.insert(formspec, + ("image[%.2f,%.2f;%.2f,%.2f;technic_power_meter_bg.png^[lowpart:%d:technic_power_meter_fg.png]"): + format(margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h, charge_ratio * 100) + ) + table.insert(formspec, ("tooltip[%.2f,%.2f;%.2f,%.2f;%s]"):format( + margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h, + ("%s / %s"):format(technic.EU_string(current_charge), technic.EU_string(max_charge)) + )) if has_digilines then local channel_w, channel_h = 2.5, 0.8 local button_w, button_h = 1, channel_h @@ -277,8 +283,7 @@ function technic.register_battery_box(nodename, data) end meta:set_string("infotext", infotext) if update_formspec then - local channel = meta:get_string("channel") - meta:set_string("formspec", get_formspec(charge_ratio, channel)) + meta:set_string("formspec", get_formspec(charge_ratio, current_charge, max_charge)) end end From 93a1f8ef7a30cf5cff87b733b8c731c7a71ac7bf Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Tue, 16 Jun 2026 16:41:59 -0500 Subject: [PATCH 04/12] generic machine formspec real coordinates --- technic/machines/register/machine_base.lua | 166 +++++++++++++-------- 1 file changed, 100 insertions(+), 66 deletions(-) diff --git a/technic/machines/register/machine_base.lua b/technic/machines/register/machine_base.lua index 36be8302..a966284b 100644 --- a/technic/machines/register/machine_base.lua +++ b/technic/machines/register/machine_base.lua @@ -48,51 +48,95 @@ function technic.register_base_machine(nodename, data) local active_groups = table.copy(groups) active_groups.not_in_creative_inventory = 1 - local size = core.get_modpath("mcl_formspec") and "size[9,10]" or "size[8,9]" - local formspec = - size.. - "list[context;src;"..(4-input_size)..",1;"..input_size..",1;]".. - "list[context;dst;5,1;2,2;]".. - "label[0,0;"..def.description.."]" - if def.upgrade then - formspec = formspec.. - "list[context;upgrade1;1,3;1,1;]".. - "list[context;upgrade2;2,3;1,1;]".. - "label[1,4;"..S("Upgrade Slots").."]" + local has_mcl_formspec = core.global_exists("mcl_formspec") + local has_upgrades = def.upgrade + + local slot_size, slot_spacing = 1, 0.25 + local slot_interval = slot_size + slot_spacing + local margin_x, margin_y = 0.5, 0.5 + local separation = 0.5 + local machine_section_h = 5 + local plrinv_w, plrinv_h = 8, 4 + if has_mcl_formspec then + plrinv_w = 9 end + local body_width = plrinv_w * slot_interval - slot_spacing + local plrinv_y = machine_section_h + separation + local body_height = plrinv_y + plrinv_h * slot_interval - slot_spacing - if core.get_modpath("mcl_formspec") then - formspec = formspec.. - mcl_formspec.get_itemslot_bg(4-input_size,1,input_size,1).. - mcl_formspec.get_itemslot_bg(5,1,2,2).. - -- player inventory - "list[current_player;main;0,5.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,5.5,9,3).. - "list[current_player;main;0,8.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,8.74,9,1) - if def.upgrade then - formspec = formspec.. - mcl_formspec.get_itemslot_bg(1,3,1,1).. - mcl_formspec.get_itemslot_bg(2,3,1,1) + local arrow_length = 1 + local arrow_margin = 0.25 + local arrowhead_length = 0.25 + local upgrades_x, upgrades_y = body_width - (slot_size + slot_spacing + slot_size), machine_section_h - slot_size + local dst_w = (slot_size + slot_spacing + slot_size) + local subject_w = slot_size + arrow_margin * 2 + arrow_length + dst_w + local src_x, src_y = (body_width - subject_w)/2, 1 + local label_offset = 0.2 + + local formspec_base = {} + table.insert(formspec_base, "formspec_version[4]") + table.insert(formspec_base, ("size[%.2f,%.2f]"):format(2 * margin_x + body_width, 2 * margin_y + body_height)) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(margin_x, margin_y, def.description)) + local _arrow_begin = margin_x + src_x + slot_size + arrow_margin + local _dst_x = margin_x + src_x + subject_w - dst_w + local _begin_y = margin_y + src_y + local _arrow_thickness = arrowhead_length + table.insert(formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") + :format(margin_x + src_x, _begin_y)) + table.insert(formspec_base, ("list[context;dst;%.2f,%.2f;2,2;]") + :format(_dst_x, _begin_y)) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _arrow_begin, _begin_y + (slot_size - _arrow_thickness)/2, + arrow_length - arrowhead_length, _arrow_thickness, + "blank.png^[invert:rgba" + )) + table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;%s]") + :format( + _arrow_begin + arrow_length - arrowhead_length, + _begin_y + slot_size/2 - arrowhead_length, + arrowhead_length, arrowhead_length * 2, + "technic_arrowhead.png" + )) + if has_upgrades then + table.insert(formspec_base, ("list[context;upgrade1;%.2f,%.2f;1,1;]") + :format(margin_x + upgrades_x, margin_y + upgrades_y)) + table.insert(formspec_base, ("list[context;upgrade2;%.2f,%.2f;1,1;]") + :format(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y)) + table.insert(formspec_base, ("label[%.2f,%.2f;%s]") + :format(margin_x + upgrades_x, margin_y + upgrades_y + slot_size + label_offset, S("Upgrade Slots"))) + end + -- listrings + table.insert(formspec_base, "listring[context;dst]") + table.insert(formspec_base, "listring[current_player;main]") + table.insert(formspec_base, "listring[context;src]") + table.insert(formspec_base, "listring[current_player;main]") + if has_upgrades then + table.insert(formspec_base, "listring[context;upgrade1]") + table.insert(formspec_base, "listring[current_player;main]") + table.insert(formspec_base, "listring[context;upgrade2]") + table.insert(formspec_base, "listring[current_player;main]") + end + + -- player inventory + if has_mcl_formspec then + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) + table.insert(formspec_base,"list[current_player;main;0,4.5;9,3;9]") + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) + table.insert(formspec_base,"list[current_player;main;0,7.74;9,1;]") + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) + if has_upgrades then + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3.5,3,1,1)) + table.insert(formspec_base, mcl_formspec.get_itemslot_bg(4.5,3,1,1)) end else - formspec = formspec.. - "list[current_player;main;0,5;8,4;]" + table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) end - -- listrings - formspec = formspec.. - "listring[context;dst]".. - "listring[current_player;main]".. - "listring[context;src]".. - "listring[current_player;main]" - if def.upgrade then - formspec = formspec.. - "listring[context;upgrade1]".. - "listring[current_player;main]".. - "listring[context;upgrade2]".. - "listring[current_player;main]" - end + local formspec = table.concat(formspec_base) local tube = technic.new_default_tube() if def.can_insert then @@ -164,6 +208,20 @@ function technic.register_base_machine(nodename, data) tentry = "" end + local presumed_form_buttons = function(meta) + return fs_helpers.cycling_button( + meta, + pipeworks.button_base:gsub("%[0%,4%.3%;1%,0%.6", ("[%.2f,%.2f;%.2f,%.2f") + :format(margin_x, margin_y + machine_section_h - 0.5 + 0.1, 1, 0.5)), + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label:gsub("%[0%.9%,4%.31", ("[%.2f,%.2f") + :format(margin_x + 1, margin_y + machine_section_h - 0.25 + 0.1)) + end + core.register_node(colon..nodename, { description = def.description, tiles = { @@ -189,15 +247,7 @@ function technic.register_base_machine(nodename, data) 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 + form_buttons = presumed_form_buttons(meta) end meta:set_string("infotext", def.description) @@ -227,15 +277,7 @@ function technic.register_base_machine(nodename, data) local meta = core.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 + form_buttons = presumed_form_buttons(meta) end meta:set_string("formspec", formspec..form_buttons) end, @@ -278,15 +320,7 @@ function technic.register_base_machine(nodename, data) local meta = core.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 + form_buttons = presumed_form_buttons(meta) end meta:set_string("formspec", formspec..form_buttons) end, From 7f34bfbbd6c6b17d7ec37ecb49005c43204852b1 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 15:13:26 -0500 Subject: [PATCH 05/12] generator formspec real coordinates --- technic/machines/register/generator.lua | 136 ++++++++++++------------ 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua index f8fc38fd..c2d333f5 100644 --- a/technic/machines/register/generator.lua +++ b/technic/machines/register/generator.lua @@ -20,32 +20,70 @@ local tube = { connect_sides = {left=1, right=1, back=1, top=1, bottom=1}, } -local size = core.get_modpath("mcl_formspec") and "size[9,10]" or "size[8,9]" +local has_mcl_formspec = core.global_exists("mcl_formspec") -local function update_generator_formspec(meta, desc, percent, form_buttons) - local generator_formspec = size.. - "label[0, 0;"..desc.."]".. - "list[context;src;3,1;1,1;]".. - "listring[context;src]".. - "image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:".. - (percent)..":default_furnace_fire_fg.png]".. - form_buttons +local generator_formspec_base = {} +local margin_x, margin_y = 0.5, 0.5 +local slot_size, slot_spacing = 1, 0.25 +local slot_interval = slot_size + slot_spacing +local separation = 0.5 +local machine_section_h = 5 +local plrinv_w, plrinv_h = 8, 4 +if has_mcl_formspec then + plrinv_w = 9 +end +local body_width = plrinv_w * slot_interval - slot_spacing +local plrinv_y = machine_section_h + separation +local body_height = plrinv_y + plrinv_h * slot_interval - slot_spacing - if core.get_modpath("mcl_formspec") then - generator_formspec = generator_formspec.. - mcl_formspec.get_itemslot_bg(3,1,1,1).. - -- player inventory - "list[current_player;main;0,5.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,5.5,9,3).. - "list[current_player;main;0,8.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,8.74,9,1).. - "listring[current_player;main]" - else - generator_formspec = generator_formspec.. - "list[current_player;main;0, 5;8, 4;]".. - "listring[current_player;main]" - end - return meta:set_string("formspec", generator_formspec) +local subject_w = slot_size +local src_x, src_y = (body_width - subject_w)/2, 2 + +table.insert(generator_formspec_base, "formspec_version[4]") +table.insert(generator_formspec_base, ("size[%.2f,%.2f]"):format(2 * margin_x + body_width, 2 * margin_y + body_height)) +table.insert(generator_formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") + :format(margin_x + src_x, margin_y + src_y)) +-- listrings +table.insert(generator_formspec_base, "listring[context;src]") +table.insert(generator_formspec_base, "listring[current_player;main]") +-- player inventory +if has_mcl_formspec then + table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) + table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) + table.insert(generator_formspec_base,"list[current_player;main;0,4.5;9,3;9]") + table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) + table.insert(generator_formspec_base,"list[current_player;main;0,7.74;9,1;]") + table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) +else + table.insert(generator_formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) +end + +generator_formspec_base = table.concat(generator_formspec_base) + +local presumed_form_buttons = function(meta) + return fs_helpers.cycling_button( + meta, + pipeworks.button_base:gsub("%[0%,4%.3%;1%,0%.6", ("[%.2f,%.2f;%.2f,%.2f") + :format(margin_x, margin_y + machine_section_h - 0.5 + 0.1, 1, 0.5)), + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label:gsub("%[0%.9%,4%.31", ("[%.2f,%.2f") + :format(margin_x + 1, margin_y + machine_section_h - 0.25 + 0.1)) +end + +local function update_generator_formspec(meta, desc, percent, form_buttons) + local generator_formspec = {generator_formspec_base, form_buttons} + table.insert(generator_formspec, ("label[%.2f,%.2f;%s]") + :format(margin_x, margin_y, desc)) + table.insert(generator_formspec, ("image[%.2f,%.2f;1,1;%s]") + :format(margin_x + src_x, margin_y + src_y - slot_interval, + ("default_furnace_fire_bg.png^[lowpart:%d:default_furnace_fire_fg.png]"):format(percent) + )) + return meta:set_string("formspec", table.concat(generator_formspec)) end function technic.register_generator(data) @@ -106,15 +144,7 @@ function technic.register_generator(data) 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 + form_buttons = presumed_form_buttons(meta) end update_generator_formspec(meta, desc, percent, form_buttons) end @@ -150,15 +180,7 @@ function technic.register_generator(data) meta:set_int("tube_time", 0) 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 + form_buttons = presumed_form_buttons(meta) end update_generator_formspec(meta, desc, 0, form_buttons) local inv = meta:get_inventory() @@ -178,15 +200,7 @@ function technic.register_generator(data) local node = core.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 + form_buttons = presumed_form_buttons(meta) end local burn_totaltime = meta:get_int("burn_totaltime") or 0 local burn_time = meta:get_int("burn_time") @@ -249,15 +263,7 @@ function technic.register_generator(data) 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 + form_buttons = presumed_form_buttons(meta) end update_generator_formspec(meta, desc, percent, form_buttons) return true @@ -269,15 +275,7 @@ function technic.register_generator(data) local node = core.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 + form_buttons = presumed_form_buttons(meta) end local burn_totaltime = meta:get_int("burn_totaltime") or 0 From 2bcc3940c3fc88510c21e413dedb8abbe6aeba18 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:45:49 -0500 Subject: [PATCH 06/12] mcl compat battery box --- technic/machines/register/battery_box.lua | 49 +++++++++++++++-------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 417c9bb6..0a0b0ada 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -6,6 +6,17 @@ local tube_entry = "^pipeworks_tube_connection_metallic.png" local cable_entry = "^technic_cable_connection_overlay.png" local mat = technic.materials +local function get_itemslot_bg(x, y, w, h) + local out = "" + for i = 0, w - 1, 1 do + for j = 0, h - 1, 1 do + out = out .. "image[" .. x + i*1.25 .. "," .. y + j*1.25 .. ";1,1;mcl_formspec_itemslot.png]" + end + end + return out +end + + -- Battery recipes: -- Tin-copper recipe: core.register_craft({ @@ -125,6 +136,7 @@ function technic.register_battery_box(nodename, data) local plrinv_w, plrinv_h = 8, 4 if has_mcl_formspec then plrinv_w = 9 + plrinv_h = 4.25 end local body_width = plrinv_w * slot_interval - slot_spacing local plrinv_y = machine_section_h + separation @@ -147,6 +159,22 @@ function technic.register_battery_box(nodename, data) local _charge_slot_x = margin_x + energy_bar_x + subject_w - slot_size local _charge_begin_y = margin_y + energy_bar_y local _arrow_thickness = charge_arrowhead_length + -- player inventory + if has_mcl_formspec then + local top_inv_y = margin_y + plrinv_y + local hotbar_y = top_inv_y + 3 * slot_interval + slot_spacing + table.insert(formspec_base, get_itemslot_bg(_charge_slot_x, _charge_begin_y,1,1)) + table.insert(formspec_base, get_itemslot_bg(_charge_slot_x, _charge_begin_y + subject_h - slot_size, 1,1)) + table.insert(formspec_base, get_itemslot_bg(margin_x, top_inv_y, plrinv_w, 3)) + table.insert(formspec_base, get_itemslot_bg(margin_x, hotbar_y, plrinv_w,1)) + table.insert(formspec_base,("list[current_player;main;%.2f,%.2f;%d,3;9]") + :format(margin_x, top_inv_y, plrinv_w)) + table.insert(formspec_base,("list[current_player;main;%.2f,%.2f;%d,1;]") + :format(margin_x, hotbar_y, plrinv_w)) + else + table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) + end table.insert(formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") :format(_charge_slot_x, _charge_begin_y)) table.insert(formspec_base, ("list[context;dst;%.2f,%.2f;1,1;]") @@ -182,6 +210,7 @@ function technic.register_battery_box(nodename, data) charge_arrowhead_length, charge_arrowhead_length * 2, "technic_arrowhead.png^[transformFX^[invert:gb" )) + -- upgrades if has_upgrades then table.insert(formspec_base, ("list[context;upgrade1;%.2f,%.2f;1,1;]") :format(margin_x + upgrades_x, margin_y + upgrades_y)) @@ -189,6 +218,10 @@ function technic.register_battery_box(nodename, data) :format(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y)) table.insert(formspec_base, ("label[%.2f,%.2f;%s]") :format(margin_x + upgrades_x, margin_y + upgrades_y + slot_size + label_offset, S("Upgrade Slots"))) + if has_upgrades then + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x, margin_y + upgrades_y,1,1)) + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y,1,1)) + end end -- listrings table.insert(formspec_base, "listring[context;dst]") @@ -201,22 +234,6 @@ function technic.register_battery_box(nodename, data) table.insert(formspec_base, "listring[context;upgrade2]") table.insert(formspec_base, "listring[current_player;main]") end - -- player inventory - if has_mcl_formspec then - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) - table.insert(formspec_base,"list[current_player;main;0,4.5;9,3;9]") - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) - table.insert(formspec_base,"list[current_player;main;0,7.74;9,1;]") - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) - if has_upgrades then - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3.5,3,1,1)) - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(4.5,3,1,1)) - end - else - table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") - :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) - end table.insert(formspec_base, ("image[%.2f,%.2f;%.2f,%.2f;technic_power_meter_bg.png]") :format(margin_x + energy_bar_x, margin_y + energy_bar_y, energy_bar_w, energy_bar_h)) table.insert(formspec_base, ("label[%.2f,%.2f;%s]") From d0ebbb1fbe80df62770feb6182abb464d9c5ae98 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:46:25 -0500 Subject: [PATCH 07/12] oops --- technic/machines/register/battery_box.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 0a0b0ada..14cdb4da 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -218,7 +218,7 @@ function technic.register_battery_box(nodename, data) :format(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y)) table.insert(formspec_base, ("label[%.2f,%.2f;%s]") :format(margin_x + upgrades_x, margin_y + upgrades_y + slot_size + label_offset, S("Upgrade Slots"))) - if has_upgrades then + if has_mcl_formspec then table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x, margin_y + upgrades_y,1,1)) table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y,1,1)) end From 46bdf7d6ba86afa8319c7316f9aca61ff93b6a7e Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:47:49 -0500 Subject: [PATCH 08/12] oops --- technic/machines/register/battery_box.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 14cdb4da..b8d0eeac 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -212,16 +212,16 @@ function technic.register_battery_box(nodename, data) )) -- upgrades if has_upgrades then + if has_mcl_formspec then + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x, margin_y + upgrades_y,1,1)) + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y,1,1)) + end table.insert(formspec_base, ("list[context;upgrade1;%.2f,%.2f;1,1;]") :format(margin_x + upgrades_x, margin_y + upgrades_y)) table.insert(formspec_base, ("list[context;upgrade2;%.2f,%.2f;1,1;]") :format(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y)) table.insert(formspec_base, ("label[%.2f,%.2f;%s]") :format(margin_x + upgrades_x, margin_y + upgrades_y + slot_size + label_offset, S("Upgrade Slots"))) - if has_mcl_formspec then - table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x, margin_y + upgrades_y,1,1)) - table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y,1,1)) - end end -- listrings table.insert(formspec_base, "listring[context;dst]") From a194ede42e21ac5f783111fd9545d6a7669f32d0 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:49:25 -0500 Subject: [PATCH 09/12] comment --- technic/machines/register/battery_box.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index b8d0eeac..b99363fa 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -6,7 +6,7 @@ local tube_entry = "^pipeworks_tube_connection_metallic.png" local cable_entry = "^technic_cable_connection_overlay.png" local mat = technic.materials -local function get_itemslot_bg(x, y, w, h) +local function get_itemslot_bg(x, y, w, h) -- mcl hasn't moved to real co-ordinates yet local out = "" for i = 0, w - 1, 1 do for j = 0, h - 1, 1 do From 2fb91926923a849c734c2d6512395a0662b8c014 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:54:16 -0500 Subject: [PATCH 10/12] machine base mcl compat --- technic/machines/register/machine_base.lua | 49 ++++++++++++++-------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/technic/machines/register/machine_base.lua b/technic/machines/register/machine_base.lua index a966284b..aaad6bb1 100644 --- a/technic/machines/register/machine_base.lua +++ b/technic/machines/register/machine_base.lua @@ -4,6 +4,16 @@ local S = technic.getter local fs_helpers = pipeworks.fs_helpers local tube_entry = "^pipeworks_tube_connection_metallic.png" +local function get_itemslot_bg(x, y, w, h) -- mcl hasn't moved to real co-ordinates yet + local out = "" + for i = 0, w - 1, 1 do + for j = 0, h - 1, 1 do + out = out .. "image[" .. x + i*1.25 .. "," .. y + j*1.25 .. ";1,1;mcl_formspec_itemslot.png]" + end + end + return out +end + function technic.default_can_insert(pos, node, stack, direction) local meta = core.get_meta(pos) local inv = meta:get_inventory() @@ -59,6 +69,7 @@ function technic.register_base_machine(nodename, data) local plrinv_w, plrinv_h = 8, 4 if has_mcl_formspec then plrinv_w = 9 + plrinv_h = 4.25 end local body_width = plrinv_w * slot_interval - slot_spacing local plrinv_y = machine_section_h + separation @@ -82,6 +93,22 @@ function technic.register_base_machine(nodename, data) local _dst_x = margin_x + src_x + subject_w - dst_w local _begin_y = margin_y + src_y local _arrow_thickness = arrowhead_length + -- player inventory + if has_mcl_formspec then + local top_inv_y = margin_y + plrinv_y + local hotbar_y = top_inv_y + 3 * slot_interval + slot_spacing + table.insert(formspec_base, get_itemslot_bg(margin_x + src_x, _begin_y, 1,1)) + table.insert(formspec_base, get_itemslot_bg(_dst_x, _begin_y, 2,2)) + table.insert(formspec_base, get_itemslot_bg(margin_x, top_inv_y, plrinv_w, 3)) + table.insert(formspec_base, get_itemslot_bg(margin_x, hotbar_y, plrinv_w,1)) + table.insert(formspec_base,("list[current_player;main;%.2f,%.2f;%d,3;9]") + :format(margin_x, top_inv_y, plrinv_w)) + table.insert(formspec_base,("list[current_player;main;%.2f,%.2f;%d,1;]") + :format(margin_x, hotbar_y, plrinv_w)) + else + table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) + end table.insert(formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") :format(margin_x + src_x, _begin_y)) table.insert(formspec_base, ("list[context;dst;%.2f,%.2f;2,2;]") @@ -99,7 +126,12 @@ function technic.register_base_machine(nodename, data) arrowhead_length, arrowhead_length * 2, "technic_arrowhead.png" )) + -- upgrades if has_upgrades then + if has_mcl_formspec then + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x, margin_y + upgrades_y,1,1)) + table.insert(formspec_base, get_itemslot_bg(margin_x + upgrades_x + slot_interval, margin_y + upgrades_y,1,1)) + end table.insert(formspec_base, ("list[context;upgrade1;%.2f,%.2f;1,1;]") :format(margin_x + upgrades_x, margin_y + upgrades_y)) table.insert(formspec_base, ("list[context;upgrade2;%.2f,%.2f;1,1;]") @@ -119,23 +151,6 @@ function technic.register_base_machine(nodename, data) table.insert(formspec_base, "listring[current_player;main]") end - -- player inventory - if has_mcl_formspec then - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) - table.insert(formspec_base,"list[current_player;main;0,4.5;9,3;9]") - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) - table.insert(formspec_base,"list[current_player;main;0,7.74;9,1;]") - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) - if has_upgrades then - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(3.5,3,1,1)) - table.insert(formspec_base, mcl_formspec.get_itemslot_bg(4.5,3,1,1)) - end - else - table.insert(formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") - :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) - end - local formspec = table.concat(formspec_base) local tube = technic.new_default_tube() From 9d0657b65b900d6abf5cbef3ad54ad18a0148064 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Wed, 17 Jun 2026 16:59:15 -0500 Subject: [PATCH 11/12] fuelfired generator mcl compat --- technic/machines/register/generator.lua | 36 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua index c2d333f5..95344b99 100644 --- a/technic/machines/register/generator.lua +++ b/technic/machines/register/generator.lua @@ -3,6 +3,16 @@ local S = technic.getter local fs_helpers = pipeworks.fs_helpers local tube_entry = "^pipeworks_tube_connection_metallic.png" +local function get_itemslot_bg(x, y, w, h) -- mcl hasn't moved to real co-ordinates yet + local out = "" + for i = 0, w - 1, 1 do + for j = 0, h - 1, 1 do + out = out .. "image[" .. x + i*1.25 .. "," .. y + j*1.25 .. ";1,1;mcl_formspec_itemslot.png]" + end + end + return out +end + local tube = { insert_object = function(pos, node, stack, direction) local meta = core.get_meta(pos) @@ -31,6 +41,7 @@ local machine_section_h = 5 local plrinv_w, plrinv_h = 8, 4 if has_mcl_formspec then plrinv_w = 9 + plrinv_h = 4.5 end local body_width = plrinv_w * slot_interval - slot_spacing local plrinv_y = machine_section_h + separation @@ -41,23 +52,26 @@ local src_x, src_y = (body_width - subject_w)/2, 2 table.insert(generator_formspec_base, "formspec_version[4]") table.insert(generator_formspec_base, ("size[%.2f,%.2f]"):format(2 * margin_x + body_width, 2 * margin_y + body_height)) -table.insert(generator_formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") - :format(margin_x + src_x, margin_y + src_y)) --- listrings -table.insert(generator_formspec_base, "listring[context;src]") -table.insert(generator_formspec_base, "listring[current_player;main]") -- player inventory if has_mcl_formspec then - table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(3,1,1,1)) - table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(5,1,1,1)) - table.insert(generator_formspec_base,"list[current_player;main;0,4.5;9,3;9]") - table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(0,4.5,9,3)) - table.insert(generator_formspec_base,"list[current_player;main;0,7.74;9,1;]") - table.insert(generator_formspec_base, mcl_formspec.get_itemslot_bg(0,7.74,9,1)) + local top_inv_y = margin_y + plrinv_y + local hotbar_y = top_inv_y + 3 * slot_interval + slot_spacing + table.insert(generator_formspec_base, get_itemslot_bg(margin_x + src_x, margin_y + src_y, 1,1)) + table.insert(generator_formspec_base, get_itemslot_bg(margin_x, top_inv_y, plrinv_w, 3)) + table.insert(generator_formspec_base, get_itemslot_bg(margin_x, hotbar_y, plrinv_w,1)) + table.insert(generator_formspec_base,("list[current_player;main;%.2f,%.2f;%d,3;9]") + :format(margin_x, top_inv_y, plrinv_w)) + table.insert(generator_formspec_base,("list[current_player;main;%.2f,%.2f;%d,1;]") + :format(margin_x, hotbar_y, plrinv_w)) else table.insert(generator_formspec_base, ("list[current_player;main;%.2f,%.2f;%d,%d;]") :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) end +table.insert(generator_formspec_base, ("list[context;src;%.2f,%.2f;1,1;]") + :format(margin_x + src_x, margin_y + src_y)) +-- listrings +table.insert(generator_formspec_base, "listring[context;src]") +table.insert(generator_formspec_base, "listring[current_player;main]") generator_formspec_base = table.concat(generator_formspec_base) From 71e057b50551c1345e8b453ec26821cef92b8326 Mon Sep 17 00:00:00 2001 From: The4spaceconsts Date: Thu, 18 Jun 2026 13:13:13 -0500 Subject: [PATCH 12/12] =?UTF-8?q?selfcontained=20injector=20real=20co?= =?UTF-8?q?=C3=B6rdinates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- technic/machines/other/injector.lua | 127 +++++++++++++++++++--------- 1 file changed, 88 insertions(+), 39 deletions(-) diff --git a/technic/machines/other/injector.lua b/technic/machines/other/injector.lua index a9756e4f..6b058495 100644 --- a/technic/machines/other/injector.lua +++ b/technic/machines/other/injector.lua @@ -13,50 +13,99 @@ local param2_to_under = { [4] = {x= 1,y= 0,z= 0}, [5] = {x= 0,y= 1,z= 0} } -local size = core.get_modpath("mcl_formspec") and "size[9,10]" or "size[8,9]" -local base_formspec = size.. - "label[0,0;"..S("Self-Contained Injector").."]".. - "list[context;main;0,2;8,2;]".. - "listring[context;main]" - -if core.get_modpath("mcl_formspec") then - base_formspec = base_formspec.. - mcl_formspec.get_itemslot_bg(0,2,8,2).. - -- player inventory - "list[current_player;main;0,5.5;9,3;9]".. - mcl_formspec.get_itemslot_bg(0,5.5,9,3).. - "list[current_player;main;0,8.74;9,1;]".. - mcl_formspec.get_itemslot_bg(0,8.74,9,1).. - "listring[current_player;main]" +local function get_itemslot_bg(x, y, w, h) -- mcl hasn't moved to real co-ordinates yet + local out = "" + for i = 0, w - 1, 1 do + for j = 0, h - 1, 1 do + out = out .. "image[" .. x + i*1.25 .. "," .. y + j*1.25 .. ";1,1;mcl_formspec_itemslot.png]" + end + end + return out +end +local has_mcl_formspec = core.global_exists("mcl_formspec") + +local margin_x, margin_y = 0.5, 0.5 +local slot_size, slot_spacing = 1, 0.25 +local slot_interval = slot_size + slot_spacing +local separation = 0.5 +local machine_section_h = 4.5 +local plrinv_w, plrinv_h = 8, 4 +if has_mcl_formspec then + plrinv_w = 9 + plrinv_h = 4.5 +end +local body_width = plrinv_w * slot_interval - slot_spacing +local plrinv_y = machine_section_h + separation +local body_height = plrinv_y + plrinv_h * slot_interval - slot_spacing + +local subject_w = slot_interval * 8 - slot_spacing +local subject_x, subject_y = (body_width - subject_w)/2, 0.5 +local src_x, src_y = subject_x, subject_y + slot_interval + +local base_formspec = {} + +table.insert(base_formspec, "formspec_version[4]") +table.insert(base_formspec, ("size[%.2f,%.2f]"):format(2 * margin_x + body_width, 2 * margin_y + body_height)) +table.insert(base_formspec, ("label[%.2f,%.2f;%s]") + :format(margin_x, margin_y, S("Self-Contained Injector"))) + +-- player inventory +if has_mcl_formspec then + local top_inv_y = margin_y + plrinv_y + local hotbar_y = top_inv_y + 3 * slot_interval + slot_spacing + table.insert(base_formspec, get_itemslot_bg(margin_x + src_x, margin_y + src_y, 8,2)) + table.insert(base_formspec, get_itemslot_bg(margin_x, top_inv_y, plrinv_w, 3)) + table.insert(base_formspec, get_itemslot_bg(margin_x, hotbar_y, plrinv_w,1)) + table.insert(base_formspec,("list[current_player;main;%.2f,%.2f;%d,3;9]") + :format(margin_x, top_inv_y, plrinv_w)) + table.insert(base_formspec,("list[current_player;main;%.2f,%.2f;%d,1;]") + :format(margin_x, hotbar_y, plrinv_w)) else - base_formspec = base_formspec.. - "list[current_player;main;0,5;8,4;]".. - "listring[current_player;main]" + table.insert(base_formspec, ("list[current_player;main;%.2f,%.2f;%d,%d;]") + :format(margin_x, margin_y + plrinv_y, plrinv_w, plrinv_h)) +end + +table.insert(base_formspec, ("list[context;main;%.2f,%.2f;8,2;]") + :format(margin_x + src_x, margin_y + src_y)) + +-- listrings +table.insert(base_formspec, "listring[context;main]") +table.insert(base_formspec, "listring[current_player;main]") + +base_formspec = table.concat(base_formspec) + +local form_buttons = function(meta) + return fs_helpers.cycling_button( + meta, + pipeworks.button_base:gsub("%[0%,4%.3%;1%,0%.6", ("[%.2f,%.2f;%.2f,%.2f") + :format(margin_x, margin_y + machine_section_h - 0.5 + 0.1, 1, 0.5)), + "splitstacks", + { + pipeworks.button_off, + pipeworks.button_on + } + )..pipeworks.button_label:gsub("%[0%.9%,4%.31", ("[%.2f,%.2f") + :format(margin_x + 1, margin_y + machine_section_h - 0.25 + 0.1)) end local function set_injector_formspec(pos) local meta = core.get_meta(pos) - local formspec = base_formspec.. - fs_helpers.cycling_button( - meta, - pipeworks.button_base, - "splitstacks", - { - pipeworks.button_off, - pipeworks.button_on - } - )..pipeworks.button_label - if meta:get_string("mode") == "whole stacks" then - formspec = formspec.."button[0,1;4,1;mode_item;"..S("Stackwise").."]" - else - formspec = formspec.."button[0,1;4,1;mode_stack;"..S("Itemwise").."]" - end - if core.get_node_timer(pos):is_started() then - formspec = formspec.."button[4,1;4,1;disable;"..S("Enabled").."]" - else - formspec = formspec.."button[4,1;4,1;enable;"..S("Disabled").."]" - end - meta:set_string("formspec", formspec) + local formspec = {base_formspec, form_buttons(meta)} + local is_stackwise = meta:get_string("mode") == "whole stacks" + table.insert(formspec, ("button[%.2f,%.2f;%.2f,%.2f;%s;%s]") + :format( + margin_x + subject_x, margin_y + subject_y, slot_size * 4, slot_size, + is_stackwise and "mode_item" or "mode_stack", + is_stackwise and S("Stackwise") or S("Itemwise") + )) + local is_enabled = core.get_node_timer(pos):is_started() + table.insert(formspec, ("button[%.2f,%.2f;%.2f,%.2f;%s;%s]") + :format( + margin_x + subject_x + subject_w - slot_size * 4, margin_y + subject_y, slot_size * 4, slot_size, + is_enabled and "disable" or "enable", + is_enabled and S("Enabled") or S("Disabled") + )) + meta:set_string("formspec", table.concat(formspec)) end core.register_node("technic:injector", {