Christopher Head
2019-01-26 4f78a69ffc714886c9d6e812f78d543bb33fe674
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,10 +13,15 @@
   can_insert = function(pos, node, stack, direction)
      local meta = minetest.get_meta(pos)
      local inv = meta:get_inventory()
      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},
}
local connect_default = {"bottom", "back", "left", "right"}
local function round(v)
   return math.floor(v + 0.5)
@@ -27,27 +35,33 @@
   local tier = data.tier
   local ltier = string.lower(tier)
   local groups = {cracky = 2, technic_machine = 1}
   local active_groups = {cracky = 2, technic_machine = 1, not_in_creative_inventory = 1}
   local groups = {cracky = 2, technic_machine = 1, ["technic_"..ltier] = 1}
   if data.tube then
      groups.tubedevice = 1
      groups.tubedevice_receiver = 1
      active_groups.tubedevice = 1
      active_groups.tubedevice_receiver = 1
   end
   local active_groups = {not_in_creative_inventory = 1}
   for k, v in pairs(groups) do active_groups[k] = v end
   local formspec =
      "invsize[8,9;]"..
      "size[8,9;]"..
      "list[current_name;src;"..(4-input_size)..",1;"..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).."]"
      "label[0,0;"..machine_desc:format(tier).."]"..
      "listring[current_name;dst]"..
      "listring[current_player;main]"..
      "listring[current_name;src]"..
      "listring[current_player;main]"
   if data.upgrade then
      formspec = formspec..
         "list[current_name;upgrade1;1,3;1,1;]"..
         "list[current_name;upgrade2;2,3;1,1;]"..
         "label[1,4;"..S("Upgrade Slots").."]"
         "label[1,4;"..S("Upgrade Slots").."]"..
         "listring[current_name;upgrade1]"..
         "listring[current_player;main]"..
         "listring[current_name;upgrade2]"..
         "listring[current_player;main]"
   end
   local run = function(pos, node)
@@ -114,6 +128,9 @@
            inv:add_item("dst_tmp", o)
         end
         if not room_for_output 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", round(result.time*10))
            return
         end
@@ -122,26 +139,47 @@
         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,
      connect_sides = data.connect_sides or connect_default,
      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 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)
@@ -153,21 +191,43 @@
      allow_metadata_inventory_take = technic.machine_inventory_take,
      allow_metadata_inventory_move = technic.machine_inventory_move,
      technic_run = run,
      after_place_node = (not tube) or pipeworks.after_place,
      after_dig_node = (not tube) or pipeworks.after_dig
      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)
         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,
      connect_sides = data.connect_sides or connect_default,
      legacy_facedir_simple = true,
      sounds = default.node_sound_wood_defaults(),
      tube = data.tube and tube or nil,
@@ -177,6 +237,25 @@
      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)