RealBadAngel
2013-06-30 8e03d7ded6441b26e9d44102c0cd2ee39f9e90bc
Sync with indev branch, bump version to 0.4.7
75 files added
18 files modified
2 files deleted
4359 ■■■■ changed files
aaa_recipeshook/depends.txt 1 ●●●● patch | view | raw | blame | history
aaa_recipeshook/init.lua 29 ●●●●● patch | view | raw | blame | history
technic/alloy_furnaces_commons.lua 12 ●●●●● patch | view | raw | blame | history
technic/battery_box.lua 669 ●●●● patch | view | raw | blame | history
technic/battery_box_hv.lua 331 ●●●●● patch | view | raw | blame | history
technic/battery_box_mv.lua 617 ●●●● patch | view | raw | blame | history
technic/chainsaw.lua 303 ●●●● patch | view | raw | blame | history
technic/cnc.lua 312 ●●●●● patch | view | raw | blame | history
technic/cnc_api.lua 372 ●●●●● patch | view | raw | blame | history
technic/cnc_nodes.lua 70 ●●●●● patch | view | raw | blame | history
technic/config.lua 49 ●●●● patch | view | raw | blame | history
technic/depends.txt 3 ●●●● patch | view | raw | blame | history
technic/down_converter_hv.lua 225 ●●●●● patch | view | raw | blame | history
technic/down_converter_mv.lua 226 ●●●●● patch | view | raw | blame | history
technic/geothermal.lua 4 ●●●● patch | view | raw | blame | history
technic/grinder.lua 91 ●●●●● patch | view | raw | blame | history
technic/init.lua 21 ●●●● patch | view | raw | blame | history
technic/items.lua 30 ●●●●● patch | view | raw | blame | history
technic/mining_drill.lua 11 ●●●● patch | view | raw | blame | history
technic/rubber.lua 26 ●●●● patch | view | raw | blame | history
technic/solar_array_hv.lua 93 ●●●●● patch | view | raw | blame | history
technic/solar_array_lv.lua 94 ●●●●● patch | view | raw | blame | history
technic/solar_array_mv.lua 95 ●●●●● patch | view | raw | blame | history
technic/solar_panel.lua 37 ●●●●● patch | view | raw | blame | history
technic/sonic_screwdriver.lua 2 ●●● patch | view | raw | blame | history
technic/textures/technic_cnc_bottom.png patch | view | raw | blame | history
technic/textures/technic_cnc_cylinder.png patch | view | raw | blame | history
technic/textures/technic_cnc_cylinder_horizontal.png patch | view | raw | blame | history
technic/textures/technic_cnc_element_cross.png patch | view | raw | blame | history
technic/textures/technic_cnc_element_edge.png patch | view | raw | blame | history
technic/textures/technic_cnc_element_end.png patch | view | raw | blame | history
technic/textures/technic_cnc_element_straight.png patch | view | raw | blame | history
technic/textures/technic_cnc_element_t.png patch | view | raw | blame | history
technic/textures/technic_cnc_front.png patch | view | raw | blame | history
technic/textures/technic_cnc_front_active.png patch | view | raw | blame | history
technic/textures/technic_cnc_full.png patch | view | raw | blame | history
technic/textures/technic_cnc_half.png patch | view | raw | blame | history
technic/textures/technic_cnc_milling_background.png patch | view | raw | blame | history
technic/textures/technic_cnc_onecurvededge.png patch | view | raw | blame | history
technic/textures/technic_cnc_pyramid.png patch | view | raw | blame | history
technic/textures/technic_cnc_side.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_edge.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_edge_upsdwn.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_inner_edge.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_inner_edge_upsdwn.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_lying.png patch | view | raw | blame | history
technic/textures/technic_cnc_slope_upsdwn.png patch | view | raw | blame | history
technic/textures/technic_cnc_sphere.png patch | view | raw | blame | history
technic/textures/technic_cnc_spike.png patch | view | raw | blame | history
technic/textures/technic_cnc_stick.png patch | view | raw | blame | history
technic/textures/technic_cnc_top.png patch | view | raw | blame | history
technic/textures/technic_cnc_top_active.png patch | view | raw | blame | history
technic/textures/technic_cnc_twocurvededge.png patch | view | raw | blame | history
technic/textures/technic_hv_battery_box_bottom.png patch | view | raw | blame | history
technic/textures/technic_hv_battery_box_side0.png patch | view | raw | blame | history
technic/textures/technic_hv_battery_box_top.png patch | view | raw | blame | history
technic/textures/technic_hv_cable.png patch | view | raw | blame | history
technic/textures/technic_hv_cable_wield.png patch | view | raw | blame | history
technic/textures/technic_hv_down_converter_bottom.png patch | view | raw | blame | history
technic/textures/technic_hv_down_converter_side.png patch | view | raw | blame | history
technic/textures/technic_hv_down_converter_top.png patch | view | raw | blame | history
technic/textures/technic_hv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technic_hv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technic_hv_solar_array_top.png patch | view | raw | blame | history
technic/textures/technic_hv_transformer.png patch | view | raw | blame | history
technic/textures/technic_lv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technic_lv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technic_lv_solar_array_top.png patch | view | raw | blame | history
technic/textures/technic_lv_transformer.png patch | view | raw | blame | history
technic/textures/technic_mv_cable_wield.png patch | view | raw | blame | history
technic/textures/technic_mv_down_converter_bottom.png patch | view | raw | blame | history
technic/textures/technic_mv_down_converter_side.png patch | view | raw | blame | history
technic/textures/technic_mv_down_converter_top.png patch | view | raw | blame | history
technic/textures/technic_mv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technic_mv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technic_mv_solar_array_top.png patch | view | raw | blame | history
technic/textures/technicx32/technic_hv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technicx32/technic_hv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technicx32/technic_hv_solar_array_top.png patch | view | raw | blame | history
technic/textures/technicx32/technic_hv_transformer.png patch | view | raw | blame | history
technic/textures/technicx32/technic_lv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technicx32/technic_lv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technicx32/technic_lv_solar_array_top.png patch | view | raw | blame | history
technic/textures/technicx32/technic_lv_transformer.png patch | view | raw | blame | history
technic/textures/technicx32/technic_mv_solar_array_bottom.png patch | view | raw | blame | history
technic/textures/technicx32/technic_mv_solar_array_side.png patch | view | raw | blame | history
technic/textures/technicx32/technic_mv_solar_array_top.png patch | view | raw | blame | history
technic/tree_tap.lua 13 ●●●●● patch | view | raw | blame | history
technic/wires_hv.lua 398 ●●●●● patch | view | raw | blame | history
unified_inventory/api.lua 222 ●●●●● patch | view | raw | blame | history
unified_inventory/depends.txt 3 ●●●● patch | view | raw | blame | history
unified_inventory/textures/ui_furnace_inventory.png patch | view | raw | blame | history
unified_inventory/textures/ui_main_inventory.png patch | view | raw | blame | history
unified_inventory/textures/ui_wooden_chest_inventory.png patch | view | raw | blame | history
aaa_recipeshook/depends.txt
File was deleted
aaa_recipeshook/init.lua
File was deleted
technic/alloy_furnaces_commons.lua
@@ -19,14 +19,12 @@
alloy_recipes[registered_recipes_count].dst_name=string3
alloy_recipes[registered_recipes_count].dst_count=count3
registered_recipes_count=registered_recipes_count+1
if UI_recipes_hook then
    minetest.register_craft({
if unified_inventory then
    unified_inventory.register_craft({
    type = "alloy",
    output = string3.." "..count3,
    recipe = {
        {string1.." "..count1},
        {string2.." "..count2},
            }
    items = {string1.." "..count1,string2.." "..count2},
    width = 2,
    })
    end
end
@@ -38,4 +36,4 @@
register_alloy_recipe ("technic:copper_dust",2, "technic:zinc_dust",1, "technic:brass_dust",3)
register_alloy_recipe ("moreores:copper_ingot",2, "technic:zinc_ingot",1, "technic:brass_ingot",3)
register_alloy_recipe ("default:sand",2, "technic:coal_dust",2, "technic:silicon_wafer",1)
register_alloy_recipe ("technic:silicon_wafer",1, "technic:mithril_dust",1, "technic:doped_silicon_wafer",1)
register_alloy_recipe ("technic:silicon_wafer",1, "technic:gold_dust",1, "technic:doped_silicon_wafer",1)
technic/battery_box.lua
@@ -1,23 +1,18 @@
LV_machines = {}
registered_LV_machines_count=0
function register_LV_machine (string1,string2)
registered_LV_machines_count=registered_LV_machines_count+1
LV_machines[registered_LV_machines_count]={}
LV_machines[registered_LV_machines_count].machine_name=string1
LV_machines[registered_LV_machines_count].machine_type=string2
-- register LV machines here
local LV_machines = {}
function register_LV_machine(string1,string2)
   LV_machines[string1] = string2
end
power_tools ={}
registered_power_tools_count=0
function register_power_tool (string1,max_charge)
registered_power_tools_count=registered_power_tools_count+1
power_tools[registered_power_tools_count]={}
power_tools[registered_power_tools_count].tool_name=string1
power_tools[registered_power_tools_count].max_charge=max_charge
   registered_power_tools_count=registered_power_tools_count+1
   power_tools[registered_power_tools_count]={}
   power_tools[registered_power_tools_count].tool_name=string1
   power_tools[registered_power_tools_count].max_charge=max_charge
end
register_power_tool ("technic:battery",10000)
register_power_tool ("technic:red_energy_crystal",100000)
@@ -25,384 +20,374 @@
register_power_tool ("technic:blue_energy_crystal",500000)
minetest.register_craft({
    output = 'technic:battery 1',
    recipe = {
        {'default:wood', 'moreores:copper_ingot', 'default:wood'},
        {'default:wood', 'moreores:tin_ingot', 'default:wood'},
        {'default:wood', 'moreores:copper_ingot', 'default:wood'},
    }
})
               output = 'technic:battery 1',
               recipe = {
                  {'default:wood', 'moreores:copper_ingot', 'default:wood'},
                  {'default:wood', 'moreores:tin_ingot', 'default:wood'},
                  {'default:wood', 'moreores:copper_ingot', 'default:wood'},
               }
            })
minetest.register_craft({
    output = 'technic:battery_box 1',
    recipe = {
        {'technic:battery', 'default:wood', 'technic:battery'},
        {'technic:battery', 'moreores:copper_ingot', 'technic:battery'},
        {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
    }
})
               output = 'technic:battery_box 1',
               recipe = {
                  {'technic:battery', 'default:wood', 'technic:battery'},
                  {'technic:battery', 'moreores:copper_ingot', 'technic:battery'},
                  {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
               }
            })
minetest.register_tool("technic:battery",
{description = "RE Battery",
inventory_image = "technic_battery.png",
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
               {description = "RE Battery",
            inventory_image = "technic_battery.png",
            tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
minetest.register_craftitem("technic:battery_box", {
    description = "Battery box",
    stack_max = 99,
})
                   description = "Battery box",
                   stack_max = 99,
                })
battery_box_formspec =
    "invsize[8,9;]"..
    "image[1,1;1,2;technic_power_meter_bg.png]"..
    "list[current_name;src;3,1;1,1;]"..
    "image[4,1;1,1;technic_battery_reload.png]"..
    "list[current_name;dst;5,1;1,1;]"..
    "label[0,0;Battery box]"..
    "label[3,0;Charge]"..
    "label[5,0;Discharge]"..
    "label[1,3;Power level]"..
    "list[current_player;main;0,5;8,4;]"
   "invsize[8,9;]"..
   "image[1,1;1,2;technic_power_meter_bg.png]"..
   "list[current_name;src;3,1;1,1;]"..
   "image[4,1;1,1;technic_battery_reload.png]"..
   "list[current_name;dst;5,1;1,1;]"..
   "label[0,0;Battery box]"..
   "label[3,0;Charge]"..
   "label[5,0;Discharge]"..
   "label[1,3;Power level]"..
   "list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:battery_box", {
    description = "Battery box",
    tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png",
        "technic_battery_box_side0.png", "technic_battery_box_side0.png", "technic_battery_box_side0.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
    technic_power_machine=1,
    last_side_shown=0,
    drop="technic:battery_box",
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("infotext", "Battery box")
        meta:set_float("technic_power_machine", 1)
        meta:set_string("formspec", battery_box_formspec)
        local inv = meta:get_inventory()
        inv:set_size("src", 1)
        inv:set_size("dst", 1)
        battery_charge = 0
        max_charge = 60000
        last_side_shown=0
        end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("dst") then
            return false
        elseif not inv:is_empty("src") then
            return false
        end
        return true
    end,
})
minetest.register_node(
   "technic:battery_box", {
      description = "LV Battery Box",
      tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png",
           "technic_battery_box_side0.png", "technic_battery_box_side0.png", "technic_battery_box_side0.png"},
      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
      sounds = default.node_sound_wood_defaults(),
      drop="technic:battery_box",
      on_construct = function(pos)
                 if pos == nil then return end
                 local meta = minetest.env:get_meta(pos)
                 local inv = meta:get_inventory()
                 meta:set_string("infotext", "Battery box")
                 meta:set_float("technic_power_machine", 1)
                 meta:set_string("formspec", battery_box_formspec)
                 meta:set_float("internal_EU_buffer", 0)
                 meta:set_float("internal_EU_buffer_size", 60000)
                 inv:set_size("src", 1)
                 inv:set_size("dst", 1)
              end,
      can_dig = function(pos,player)
            if pos == nil then return end
            local meta = minetest.env:get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("dst") then
               return false
            elseif not inv:is_empty("src") then
               return false
            end
            return true
             end,
   })
for i=1,8,1 do
minetest.register_node("technic:battery_box"..i, {
    description = "Battery box",
    tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png^technic_power_meter"..i..".png",
        "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
    sounds = default.node_sound_wood_defaults(),
    technic_power_machine=1,
    last_side_shown=0,
    drop="technic:battery_box",
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("infotext", "Battery box")
        meta:set_float("technic_power_machine", 1)
        meta:set_string("formspec", battery_box_formspec)
        local inv = meta:get_inventory()
        inv:set_size("src", 1)
        inv:set_size("dst", 1)
        battery_charge = 0
        max_charge = 60000
        last_side_shown=0
        end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("dst") then
            return false
        elseif not inv:is_empty("src") then
            return false
        end
        return true
    end,
})
   minetest.register_node(
      "technic:battery_box"..i, {
     description = "LV Battery Box",
     tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png", "technic_battery_box_side0.png^technic_power_meter"..i..".png",
          "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png", "technic_battery_box_side0.png^technic_power_meter"..i..".png"},
     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
     sounds = default.node_sound_wood_defaults(),
     drop="technic:battery_box",
     on_construct = function(pos)
                 if pos == nil then return end
                 local meta = minetest.env:get_meta(pos)
                 local inv = meta:get_inventory()
                 meta:set_string("infotext", "Battery box")
                 meta:set_float("technic_power_machine", 1)
                 meta:set_string("formspec", battery_box_formspec)
                 meta:set_float("internal_EU_buffer", 0)
                 meta:set_float("internal_EU_buffer_size", 60000)
                 inv:set_size("src", 1)
                 inv:set_size("dst", 1)
              end,
     can_dig = function(pos,player)
            if pos == nil then return end
            local meta = minetest.env:get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("dst") then
               return false
            elseif not inv:is_empty("src") then
               return false
            end
            return true
             end,
      })
end
LV_nodes_visited = {}
function get_RE_item_load (load1,max_load)
if load1==0 then load1=65535 end
local temp = 65536-load1
temp= temp/65535*max_load
return math.floor(temp + 0.5)
   if load1==0 then load1=65535 end
   local temp = 65536-load1
   temp= temp/65535*max_load
   return math.floor(temp + 0.5)
end
function set_RE_item_load (load1,max_load)
if load1 == 0 then return 65535 end
local temp=load1/max_load*65535
temp=65536-temp
return math.floor(temp)
   if load1 == 0 then return 65535 end
   local temp=load1/max_load*65535
   temp=65536-temp
   return math.floor(temp)
end
function set_RE_wear (item_stack,load1,max_load)
local temp=65536-math.floor(load1/max_load*65535)
item_stack["wear"]=tostring(temp)
return item_stack
   local temp=65536-math.floor(load1/max_load*65535)
   item_stack["wear"]=tostring(temp)
   return item_stack
end
minetest.register_abm({
    nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
        "technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"},
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
    local meta = minetest.env:get_meta(pos)
    charge= meta:get_int("battery_charge")
    max_charge= 60000
    local i=math.ceil((charge/max_charge)*8)
    if i>8 then i=8 end
    j=meta:get_float("last_side_shown")
    if i~=j then
    if i>0 then hacky_swap_node(pos,"technic:battery_box"..i)
    elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end
    meta:set_float("last_side_shown",i)
    end
minetest.register_abm(
   {nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
         "technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"},
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta       = minetest.env:get_meta(pos)
        local max_charge = 60000 -- Set maximum charge for the device here
        local charge     = meta:get_int("internal_EU_buffer")
--loading registered power tools
    local inv = meta:get_inventory()
    if inv:is_empty("src")==false  then
        local srcstack = inv:get_stack("src", 1)
        local src_item=srcstack:to_table()
        local src_meta=get_item_meta(src_item["metadata"])
        local item_max_charge=nil
        for i=1,registered_power_tools_count,1 do
            if power_tools[i].tool_name==src_item["name"] then
                src_meta=get_item_meta(src_item["metadata"])
                if src_meta==nil then
                    src_meta={}
                    src_meta["technic_power_tool"]=true
                    src_meta["charge"]=0
                else
                    if src_meta["technic_power_tool"]==nil then
                        src_meta["technic_power_tool"]=true
                        src_meta["charge"]=0
                    end
                end
                item_max_charge=power_tools[i].max_charge
            end
        -- Select node textures
        local i=math.ceil((charge/max_charge)*8)
        if i > 8 then i = 8 end
        local j = meta:get_float("last_side_shown")
        if i~=j then
           if i>0 then hacky_swap_node(pos,"technic:battery_box"..i)
           elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end
           meta:set_float("last_side_shown",i)
        end
        
        if item_max_charge then
            load1=src_meta["charge"]
            load_step=1000
            if load1<item_max_charge and charge>0 then
                if charge-load_step<0 then load_step=charge end
                if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
                load1=load1+load_step
                charge=charge-load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("src", 1, src_item)
            end
            meta:set_int("battery_charge",charge)
        end
    end
-- dischargin registered power tools
        if inv:is_empty("dst") == false then
        srcstack = inv:get_stack("dst", 1)
        src_item=srcstack:to_table()
        local src_meta=get_item_meta(src_item["metadata"])
        local item_max_charge=nil
        for i=1,registered_power_tools_count,1 do
            if power_tools[i].tool_name==src_item["name"] then
                src_meta=get_item_meta(src_item["metadata"])
                if src_meta==nil then
                    src_meta={}
                    src_meta["technic_power_tool"]=true
                    src_meta["charge"]=0
                else
                    if src_meta["technic_power_tool"]==nil then
                        src_meta["technic_power_tool"]=true
                        src_meta["charge"]=0
                    end
                end
                item_max_charge=power_tools[i].max_charge
            end
        end
        if item_max_charge then
        local load1=src_meta["charge"]
        load_step=1000
        if load1>0 and charge<max_charge then
             if charge+load_step>max_charge then load_step=max_charge-charge end
               if load1-load_step<0 then load_step=load1 end
        load1=load1-load_step
        charge=charge+load_step
        set_RE_wear(src_item,load1,item_max_charge)
        src_meta["charge"]=load1
        src_item["metadata"]=set_item_meta(src_meta)
        inv:set_stack("dst", 1, src_item)
        end
        end
        --charge registered power tools
        local inv = meta:get_inventory()
        if inv:is_empty("src")==false  then
           local srcstack = inv:get_stack("src", 1)
           local src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
           local item_max_charge=nil
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             -- Do the charging
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 1000 -- how much to charge per tick
             if load1<item_max_charge and charge>0 then
                if charge-load_step<0 then load_step=charge end
                if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
                load1=load1+load_step
                charge=charge-load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("src", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
        
    meta:set_int("battery_charge",charge)
        -- discharging registered power tools
        if inv:is_empty("dst") == false then
           srcstack = inv:get_stack("dst", 1)
           src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
           local item_max_charge=nil
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 4000 -- how much to discharge per tick
             if load1>0 and charge<max_charge then
                if charge+load_step>max_charge then load_step=max_charge-charge end
                if load1-load_step<0 then load_step=load1 end
                load1=load1-load_step
                charge=charge+load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("dst", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
    local load = math.floor(charge/60000 * 100)
    meta:set_string("formspec",
        local load = math.floor(charge/60000 * 100)
        meta:set_string("formspec",
                battery_box_formspec..
                "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                        (load)..":technic_power_meter_fg.png]")
                   "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                   (load)..":technic_power_meter_fg.png]"
                 )
    local pos1={}
        -- Next index the surrounding network the get the producers and receivers on the power grid
        local pos1={}
        pos1.y=pos.y-1
        pos1.x=pos.x
        pos1.z=pos.z
    pos1.y=pos.y-1
    pos1.x=pos.x
    pos1.z=pos.z
        meta1 = minetest.env:get_meta(pos1)
        if meta1:get_float("cablelike")~=1 then return end
        local LV_nodes = {}
        local PR_nodes = {}
        local RE_nodes = {}
        local BA_nodes = {}
        LV_nodes[1]={}
        LV_nodes[1].x=pos1.x
        LV_nodes[1].y=pos1.y
        LV_nodes[1].z=pos1.z
        LV_nodes[1].visited=false
        local table_index=1
        repeat
           check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,table_index)
           table_index=table_index+1
           if LV_nodes[table_index]==nil then break end
        until false
    meta1 = minetest.env:get_meta(pos1)
    if meta1:get_float("cablelike")~=1 then return end
        -- Get power from all connected producers
        local pr_pos
                for _,pr_pos in ipairs(PR_nodes) do
           local meta1              = minetest.env:get_meta(pr_pos)
           local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
           local charge_to_take     = 200
           if charge<max_charge then
              if internal_EU_buffer-charge_to_take<=0 then
             charge_to_take=internal_EU_buffer
              end
              if charge_to_take>0 then
             charge=charge+charge_to_take
             internal_EU_buffer=internal_EU_buffer-charge_to_take
             meta1:set_float("internal_EU_buffer",internal_EU_buffer)
              end
           end
        end
    local LV_nodes = {}
    local PR_nodes = {}
    local RE_nodes = {}
        if charge>max_charge then charge=max_charge end
    LV_nodes[1]={}
    LV_nodes[1].x=pos1.x
    LV_nodes[1].y=pos1.y
    LV_nodes[1].z=pos1.z
    LV_nodes[1].visited=false
        -- Provide power to all connected receivers
        local re_pos
                for _,re_pos in ipairs(RE_nodes) do
           local meta1                   = minetest.env:get_meta(re_pos)
           local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
           local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
           local charge_to_give          = math.min(200, charge/table.getn(RE_nodes))
           if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
           end
           if charge-charge_to_give<0 then charge_to_give=charge end
           internal_EU_buffer=internal_EU_buffer+charge_to_give
           meta1:set_float("internal_EU_buffer",internal_EU_buffer)
           charge=charge-charge_to_give;
        end
        charge=math.floor(charge)
        meta:set_string("infotext", "LV Battery box: "..charge.."/"..max_charge);
        meta:set_int("internal_EU_buffer",charge)
         end
 })
table_index=1
    repeat
    check_LV_node (PR_nodes,RE_nodes,LV_nodes,table_index)
    table_index=table_index+1
    if LV_nodes[table_index]==nil then break end
    until false
local pos1={}
i=1
    repeat
    if PR_nodes[i]==nil then break end -- gettin power from all connected producers
        pos1.x=PR_nodes[i].x
        pos1.y=PR_nodes[i].y
        pos1.z=PR_nodes[i].z
    local meta1 = minetest.env:get_meta(pos1)
    local internal_EU_buffer=meta1:get_float("internal_EU_buffer")
    if charge<max_charge then
    charge_to_take=200
    if internal_EU_buffer-charge_to_take<=0 then
        charge_to_take=internal_EU_buffer
    end
    if charge_to_take>0 then
    charge=charge+charge_to_take
    internal_EU_buffer=internal_EU_buffer-charge_to_take
    meta1:set_float("internal_EU_buffer",internal_EU_buffer)
    end
    end
    i=i+1
    until false
if charge>max_charge then charge=max_charge end
i=1
    repeat
    if RE_nodes[i]==nil then break end
        pos1.x=RE_nodes[i].x         -- loading all conected machines buffers
        pos1.y=RE_nodes[i].y
        pos1.z=RE_nodes[i].z
    local meta1 = minetest.env:get_meta(pos1)
    local internal_EU_buffer=meta1:get_float("internal_EU_buffer")
    local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size")
    local charge_to_give=200
    if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
        charge_to_give=internal_EU_buffer_size-internal_EU_buffer
    end
    if charge-charge_to_give<0 then charge_to_give=charge end
    internal_EU_buffer=internal_EU_buffer+charge_to_give
    meta1:set_float("internal_EU_buffer",internal_EU_buffer)
    charge=charge-charge_to_give;
    i=i+1
    until false
    charge=math.floor(charge)
    charge_string=tostring(charge)
    meta:set_string("infotext", "Battery box: "..charge_string.."/"..max_charge);
    meta:set_int("battery_charge",charge)
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
register_LV_machine("technic:battery_box","BA")
for i=1,8,1 do
   register_LV_machine("technic:battery_box"..i,"BA")
end
})
function add_new_cable_node (LV_nodes,pos1)
    local i=1
    repeat
        if LV_nodes[i]==nil then break end
        if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end
        i=i+1
    until false
    LV_nodes[i]={}
    LV_nodes[i].x=pos1.x
    LV_nodes[i].y=pos1.y
    LV_nodes[i].z=pos1.z
    LV_nodes[i].visited=false
    return true
   if LV_nodes == nil then return true end
   local i=1
   repeat
      if LV_nodes[i]==nil then break end
      if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end
      i=i+1
   until false
   LV_nodes[i]={}
   LV_nodes[i].x=pos1.x
   LV_nodes[i].y=pos1.y
   LV_nodes[i].z=pos1.z
   return true
end
function check_LV_node (PR_nodes,RE_nodes,LV_nodes,i)
    local pos1={}
    pos1.x=LV_nodes[i].x
    pos1.y=LV_nodes[i].y
    pos1.z=LV_nodes[i].z
    LV_nodes[i].visited=true
    new_node_added=false
function check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,i)
   local pos1={}
   pos1.x=LV_nodes[i].x
   pos1.y=LV_nodes[i].y
   pos1.z=LV_nodes[i].z
    pos1.x=pos1.x+1
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.x=pos1.x-2
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.x=pos1.x+1
   pos1.x=pos1.x+1
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.x=pos1.x-2
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.x=pos1.x+1
    pos1.y=pos1.y+1
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.y=pos1.y-2
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.y=pos1.y+1
   pos1.y=pos1.y+1
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.y=pos1.y-2
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.y=pos1.y+1
    pos1.z=pos1.z+1
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.z=pos1.z-2
    check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
    pos1.z=pos1.z+1
return new_node_added
   pos1.z=pos1.z+1
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.z=pos1.z-2
   check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   pos1.z=pos1.z+1
   return new_node_added
end
function check_LV_node_subp (PR_nodes,RE_nodes,LV_nodes,pos1)
meta = minetest.env:get_meta(pos1)
if meta:get_float("cablelike")==1 then new_node_added=add_new_cable_node(LV_nodes,pos1) end
for i in ipairs(LV_machines) do
    if minetest.env:get_node(pos1).name == LV_machines[i].machine_name then
        if LV_machines[i].machine_type == "PR" then
            new_node_added=add_new_cable_node(PR_nodes,pos1)
            end
        if LV_machines[i].machine_type == "RE" then
            new_node_added=add_new_cable_node(RE_nodes,pos1)
            end
    end
end
function check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
   local meta = minetest.env:get_meta(pos1)
   local name = minetest.env:get_node(pos1).name
   if meta:get_float("cablelike")==1 then
      add_new_cable_node(LV_nodes,pos1)
   elseif LV_machines[name] then
      --print(name.." is a "..LV_machines[name])
      if     LV_machines[name] == "PR" then
     add_new_cable_node(PR_nodes,pos1)
      elseif LV_machines[name] == "RE" then
     add_new_cable_node(RE_nodes,pos1)
      elseif LV_machines[name] == "BA" then
     add_new_cable_node(BA_nodes,pos1)
      end
   end
end
technic/battery_box_hv.lua
New file
@@ -0,0 +1,331 @@
-- register MV machines here
technic.HV_machines = {}
local HV_machines = technic.HV_machines
function register_HV_machine(string1,string2)
   technic.HV_machines[string1] = string2
end
minetest.register_craft({
               output = 'technic:hv_battery_box 1',
               recipe = {
                  {'technic:mv_battery_box', 'technic:mv_battery_box', 'mv_technic:battery_box'},
                  {'technic:mv_battery_box', 'technic:hv_transformer', 'mv_technic:battery_box'},
                  {'', 'technic:hv_cable', ''},
               }
            })
hv_battery_box_formspec =
   "invsize[8,9;]"..
   "image[1,1;1,2;technic_power_meter_bg.png]"..
   "list[current_name;src;3,1;1,1;]"..
   "image[4,1;1,1;technic_battery_reload.png]"..
   "list[current_name;dst;5,1;1,1;]"..
   "label[0,0;HV Battery Box]"..
   "label[3,0;Charge]"..
   "label[5,0;Discharge]"..
   "label[1,3;Power level]"..
   "list[current_player;main;0,5;8,4;]"
minetest.register_node(
   "technic:hv_battery_box", {
      description = "HV Battery Box",
      tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png",
           "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"},
      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
      sounds = default.node_sound_wood_defaults(),
      drop="technic:hv_battery_box",
      on_construct = function(pos)
            if pos==nil then return end
            local meta = minetest.env:get_meta(pos)
            local inv = meta:get_inventory()
            meta:set_string("infotext", "HV Battery Box")
            meta:set_float("technic_hv_power_machine", 1)
            meta:set_string("formspec", battery_box_formspec)
            inv:set_size("src", 1)
            inv:set_size("dst", 1)
             end,
      can_dig = function(pos,player)
           if pos==nil then return end
           local meta = minetest.env:get_meta(pos);
           local inv = meta:get_inventory()
           if not inv:is_empty("dst") then
              return false
           elseif not inv:is_empty("src") then
              return false
           end
           return true
        end,
   })
for i=1,8,1 do
   minetest.register_node(
      "technic:hv_battery_box"..i, {
     description = "HV Battery Box",
     tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
          "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"},
     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
     sounds = default.node_sound_wood_defaults(),
     paramtype="light",
     light_source=9,
     drop="technic:hv_battery_box",
     on_construct = function(pos)
               local meta = minetest.env:get_meta(pos)
               local inv = meta:get_inventory()
               meta:set_string("infotext", "HV Battery box")
               meta:set_float("technic_hv_power_machine", 1)
               meta:set_string("formspec", battery_box_formspec)
               inv:set_size("src", 1)
               inv:set_size("dst", 1)
            end,
     can_dig = function(pos,player)
              local meta = minetest.env:get_meta(pos);
              local inv = meta:get_inventory()
              if not inv:is_empty("dst") then
             return false
              elseif not inv:is_empty("src") then
             return false
              end
              return true
           end,
      })
end
minetest.register_abm(
   {nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4",
         "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8"
          },
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta       = minetest.env:get_meta(pos)
        local max_charge = 1500000
        local charge     = meta:get_int("internal_EU_buffer")
        -- Select node textures
        local i = math.ceil((charge/max_charge)*8)
        if i > 8 then i = 8 end
        local j = meta:get_float("last_side_shown")
        if i~=j then
           if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i)
           elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end
           meta:set_float("last_side_shown",i)
        end
        --charge registered power tools
        local inv = meta:get_inventory()
        if inv:is_empty("src")==false  then
           local srcstack = inv:get_stack("src", 1)
           local src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             -- Do the charging
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 16000 -- how much to charge per tick
             if load1<item_max_charge and charge>0 then
                if charge-load_step<0 then load_step=charge end
                if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
                load1=load1+load_step
                charge=charge-load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("src", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
        -- discharging registered power tools
        if inv:is_empty("dst") == false then
           srcstack = inv:get_stack("dst", 1)
           src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
           local item_max_charge=nil
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 16000 -- how much to discharge per tick
             if load1>0 and charge<max_charge then
                if charge+load_step>max_charge then load_step=max_charge-charge end
                if load1-load_step<0 then load_step=load1 end
                load1=load1-load_step
                charge=charge+load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("dst", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
        local load = math.floor((charge/1500000) * 100)
        meta:set_string("formspec",
                hv_battery_box_formspec..
                   "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                   (load)..":technic_power_meter_fg.png]"
                 )
        -- Next index the surrounding network the get the producers and receivers on the
        local pos1={}
        pos1.y=pos.y-1
        pos1.x=pos.x
        pos1.z=pos.z
        meta1 = minetest.env:get_meta(pos1)
        if meta1:get_float("hv_cablelike")~=1 then return end
        local HV_nodes = {}
        local PR_nodes = {}
        local RE_nodes = {}
        local BA_nodes = {}
        HV_nodes[1]={}
        HV_nodes[1].x=pos1.x
        HV_nodes[1].y=pos1.y
        HV_nodes[1].z=pos1.z
        HV_nodes[1].visited=false
        local table_index=1
        repeat
           check_HV_node (PR_nodes,RE_nodes,BA_nodes,HV_nodes,table_index)
           table_index=table_index+1
           if HV_nodes[table_index]==nil then break end
        until false
        -- Get power from all connected producers
        local pr_pos
                for _,pr_pos in ipairs(PR_nodes) do
           local meta1              = minetest.env:get_meta(pr_pos)
           local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
           local charge_to_take     = 4000
           if charge<max_charge then
              if internal_EU_buffer-charge_to_take<=0 then
             charge_to_take=internal_EU_buffer
              end
              if charge_to_take>0 then
             charge=charge+charge_to_take
             internal_EU_buffer=internal_EU_buffer-charge_to_take
             meta1:set_float("internal_EU_buffer",internal_EU_buffer)
              end
           end
        end
        if charge>max_charge then charge=max_charge end
        -- Provide power to all connected receivers
        local re_pos
                for _,re_pos in ipairs(RE_nodes) do
           local meta1                   = minetest.env:get_meta(re_pos)
           local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
           local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
           local charge_to_give          = math.min(4000, charge/table.getn(RE_nodes))
           if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
           end
           if charge-charge_to_give<0 then charge_to_give=charge end
           internal_EU_buffer=internal_EU_buffer+charge_to_give
           meta1:set_float("internal_EU_buffer",internal_EU_buffer)
           charge=charge-charge_to_give;
        end
        charge=math.floor(charge)
        meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge);
        meta:set_int("internal_EU_buffer",charge)
         end
 })
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
register_HV_machine("technic:hv_battery_box","BA")
for i=1,8,1 do
   register_HV_machine("technic:hv_battery_box"..i,"BA")
end
function add_new_HVcable_node (HV_nodes,pos1)
   if HV_nodes == nil then return true end
   local i=1
   repeat
      if HV_nodes[i]==nil then break end
      if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end
      i=i+1
   until false
   HV_nodes[i]={}
   HV_nodes[i].x=pos1.x
   HV_nodes[i].y=pos1.y
   HV_nodes[i].z=pos1.z
   return true
end
function check_HV_node(PR_nodes,RE_nodes,BA_nodes,HV_nodes,i)
   local pos1={}
   pos1.x=HV_nodes[i].x
   pos1.y=HV_nodes[i].y
   pos1.z=HV_nodes[i].z
   pos1.x=pos1.x+1
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.x=pos1.x-2
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.x=pos1.x+1
   pos1.y=pos1.y+1
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.y=pos1.y-2
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.y=pos1.y+1
   pos1.z=pos1.z+1
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.z=pos1.z-2
   check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   pos1.z=pos1.z+1
end
function check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
   local meta = minetest.env:get_meta(pos1)
   local name = minetest.env:get_node(pos1).name
   if meta:get_float("hv_cablelike")==1 then
      add_new_HVcable_node(HV_nodes,pos1)
   elseif HV_machines[name] then
      --print(name.." is a "..HV_machines[name])
      if     HV_machines[name] == "PR" then
     add_new_HVcable_node(PR_nodes,pos1)
      elseif HV_machines[name] == "RE" then
     add_new_HVcable_node(RE_nodes,pos1)
      elseif HV_machines[name] == "BA" then
     add_new_HVcable_node(BA_nodes,pos1)
      end
   end
end
technic/battery_box_mv.lua
@@ -1,355 +1,338 @@
MV_machines = {}
registered_MV_machines_count=0
function register_MV_machine (string1,string2)
registered_MV_machines_count=registered_MV_machines_count+1
MV_machines[registered_MV_machines_count]={}
MV_machines[registered_MV_machines_count].machine_name=string1
MV_machines[registered_MV_machines_count].machine_type=string2
-- register MV machines here
technic.MV_machines = {}
--local MV_machines = {}
local MV_machines = technic.MV_machines
function register_MV_machine(string1,string2)
   technic.MV_machines[string1] = string2
end
minetest.register_craft({
    output = 'technic:mv_battery_box 1',
    recipe = {
        {'technic:battery_box', 'technic:battery_box', 'technic:battery_box'},
        {'technic:battery_box', 'technic:mv_transformer', 'technic:battery_box'},
        {'', 'technic:mv_cable', ''},
    }
})
minetest.register_craft(
   {
      output = 'technic:mv_battery_box 1',
      recipe = {
     {'technic:battery_box', 'technic:battery_box', 'technic:battery_box'},
     {'technic:battery_box', 'technic:mv_transformer', 'technic:battery_box'},
     {'', 'technic:mv_cable', ''},
      }
   })
mv_battery_box_formspec =
    "invsize[8,9;]"..
    "image[1,1;1,2;technic_power_meter_bg.png]"..
    "list[current_name;src;3,1;1,1;]"..
    "image[4,1;1,1;technic_battery_reload.png]"..
    "list[current_name;dst;5,1;1,1;]"..
    "label[0,0;MV_Battery box]"..
    "label[3,0;Charge]"..
    "label[5,0;Discharge]"..
    "label[1,3;Power level]"..
    "list[current_player;main;0,5;8,4;]"
   "invsize[8,9;]"..
   "image[1,1;1,2;technic_power_meter_bg.png]"..
   "list[current_name;src;3,1;1,1;]"..
   "image[4,1;1,1;technic_battery_reload.png]"..
   "list[current_name;dst;5,1;1,1;]"..
   "label[0,0;MV_Battery box]"..
   "label[3,0;Charge]"..
   "label[5,0;Discharge]"..
   "label[1,3;Power level]"..
   "list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:mv_battery_box", {
    description = "MV Battery Box",
    tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png",
        "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
    technic_mv_power_machine=1,
    last_side_shown=0,
    drop="technic:mv_battery_box",
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("infotext", "MV Battery box")
        meta:set_float("technic_mv_power_machine", 1)
        meta:set_string("formspec", battery_box_formspec)
        local inv = meta:get_inventory()
        inv:set_size("src", 1)
        inv:set_size("dst", 1)
        battery_charge = 0
        max_charge = 300000
        last_side_shown=0
        end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("dst") then
            return false
        elseif not inv:is_empty("src") then
            return false
minetest.register_node(
   "technic:mv_battery_box", {
      description = "MV Battery Box",
      tiles  = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png",
            "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png"},
      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
      sounds = default.node_sound_wood_defaults(),
      drop   = "technic:mv_battery_box",
      on_construct = function(pos)
            if pos==nil then return end
            local meta = minetest.env:get_meta(pos);
            local inv = meta:get_inventory()
            meta:set_string("infotext", "MV Battery box")
            meta:set_float("technic_mv_power_machine", 1)
            meta:set_string("formspec", battery_box_formspec)
            meta:set_float("internal_EU_buffer", 0)
            meta:set_float("internal_EU_buffer_size", 300000)
            inv:set_size("src", 1)
            inv:set_size("dst", 1)
             end,
      can_dig = function(pos,player)
           if pos==nil then return end
           local meta = minetest.env:get_meta(pos);
           local inv = meta:get_inventory()
           if not inv:is_empty("dst") then
              return false
           elseif not inv:is_empty("src") then
              return false
           end
           return true
        end
        return true
    end,
})
   })
for i=1,8,1 do
minetest.register_node("technic:mv_battery_box"..i, {
    description = "MV Battery Box",
    tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png",
        "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
    sounds = default.node_sound_wood_defaults(),
    technic_power_machine=1,
    last_side_shown=0,
    drop="technic:mv_battery_box",
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("infotext", "MV Battery box")
        meta:set_float("technic_mv_power_machine", 1)
        meta:set_string("formspec", battery_box_formspec)
        local inv = meta:get_inventory()
        inv:set_size("src", 1)
        inv:set_size("dst", 1)
        battery_charge = 0
        max_charge = 300000
        last_side_shown=0
        end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("dst") then
            return false
        elseif not inv:is_empty("src") then
            return false
        end
        return true
    end,
})
   minetest.register_node(
      "technic:mv_battery_box"..i, {
     description = "MV Battery Box",
     tiles  = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png",
           "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"},
     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
     sounds = default.node_sound_wood_defaults(),
     drop   = "technic:mv_battery_box",
     on_construct = function(pos)
               if pos==nil then return end
               local meta = minetest.env:get_meta(pos);
               local inv = meta:get_inventory()
               meta:set_string("infotext", "MV Battery box")
               meta:set_float("technic_mv_power_machine", 1)
               meta:set_string("formspec", battery_box_formspec)
               meta:set_float("internal_EU_buffer", 0)
               meta:set_float("internal_EU_buffer_size", 300000)
               inv:set_size("src", 1)
               inv:set_size("dst", 1)
            end,
     can_dig = function(pos,player)
              if pos==nil then return end
              local meta = minetest.env:get_meta(pos);
              local inv = meta:get_inventory()
              if not inv:is_empty("dst") then
             return false
              elseif not inv:is_empty("src") then
             return false
              end
              return true
           end
      })
end
minetest.register_abm(
   {nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4",
         "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8"
          },
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta       = minetest.env:get_meta(pos)
        local max_charge = 300000 -- Set maximum charge for the device here
        local charge     = meta:get_int("internal_EU_buffer")
MV_nodes_visited = {}
minetest.register_abm({
    nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4",
             "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8"
            },
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
    local meta = minetest.env:get_meta(pos)
    charge= meta:get_int("battery_charge")
    max_charge= 300000
    local i=math.ceil((charge/max_charge)*8)
    if i>8 then i=8 end
    j=meta:get_float("last_side_shown")
    if i~=j then
    if i>0 then hacky_swap_node(pos,"technic:mv_battery_box"..i)
    elseif i==0 then hacky_swap_node(pos,"technic:mv_battery_box") end
    meta:set_float("last_side_shown",i)
    end
--loading registered power tools
    local inv = meta:get_inventory()
    if inv:is_empty("src")==false  then
        local srcstack = inv:get_stack("src", 1)
        local src_item=srcstack:to_table()
        local src_meta=get_item_meta(src_item["metadata"])
        local item_max_charge=nil
        for i=1,registered_power_tools_count,1 do
            if power_tools[i].tool_name==src_item["name"] then
                src_meta=get_item_meta(src_item["metadata"])
                if src_meta==nil then
                    src_meta={}
                    src_meta["technic_power_tool"]=true
                    src_meta["charge"]=0
                else
                    if src_meta["technic_power_tool"]==nil then
                        src_meta["technic_power_tool"]=true
                        src_meta["charge"]=0
                    end
                end
                item_max_charge=power_tools[i].max_charge
            end
        end
        if item_max_charge then
            load1=src_meta["charge"]
            load_step=4000
            if load1<item_max_charge and charge>0 then
                if charge-load_step<0 then load_step=charge end
                if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
                load1=load1+load_step
                charge=charge-load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("src", 1, src_item)
            end
            meta:set_int("battery_charge",charge)
        end
    end
-- dischargin registered power tools
        if inv:is_empty("dst") == false then
        srcstack = inv:get_stack("dst", 1)
        src_item=srcstack:to_table()
        local src_meta=get_item_meta(src_item["metadata"])
        local item_max_charge=nil
        for i=1,registered_power_tools_count,1 do
            if power_tools[i].tool_name==src_item["name"] then
                src_meta=get_item_meta(src_item["metadata"])
                if src_meta==nil then
                    src_meta={}
                    src_meta["technic_power_tool"]=true
                    src_meta["charge"]=0
                else
                    if src_meta["technic_power_tool"]==nil then
                        src_meta["technic_power_tool"]=true
                        src_meta["charge"]=0
                    end
                end
                item_max_charge=power_tools[i].max_charge
            end
        -- Select node textures
        local i = math.ceil((charge/max_charge)*8)
        if i > 8 then i = 8 end
        local j = meta:get_float("last_side_shown")
        if i~=j then
           if i>0 then hacky_swap_node(pos,"technic:mv_battery_box"..i)
           elseif i==0 then hacky_swap_node(pos,"technic:mv_battery_box") end
           meta:set_float("last_side_shown",i)
        end
        if item_max_charge then
        local load1=src_meta["charge"]
        load_step=4000
        if load1>0 and charge<max_charge then
             if charge+load_step>max_charge then load_step=max_charge-charge end
               if load1-load_step<0 then load_step=load1 end
        load1=load1-load_step
        charge=charge+load_step
        set_RE_wear(src_item,load1,item_max_charge)
        src_meta["charge"]=load1
        src_item["metadata"]=set_item_meta(src_meta)
        inv:set_stack("dst", 1, src_item)
        end
        end
        end
    meta:set_int("battery_charge",charge)
        --charge registered power tools
        local inv = meta:get_inventory()
        if inv:is_empty("src")==false  then
           local srcstack = inv:get_stack("src", 1)
           local src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
    local load = math.floor((charge/300000) * 100)
    meta:set_string("formspec",
           -- Power tools should really be made into a hash table to avoid linear search. But the list is short so okay...
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             -- What is this code doing? Setting tool properties if not set already????
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             -- Do the charging
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 4000 -- how much to charge per tick
             if load1<item_max_charge and charge>0 then
                if charge-load_step<0 then load_step=charge end
                if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
                load1=load1+load_step
                charge=charge-load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]   = load1
                src_item["metadata"] = set_item_meta(src_meta)
                inv:set_stack("src", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
        -- discharging registered power tools
        if inv:is_empty("dst") == false then
           srcstack = inv:get_stack("dst", 1)
           src_item=srcstack:to_table()
           local src_meta=get_item_meta(src_item["metadata"])
           local item_max_charge=nil
           for i=1,registered_power_tools_count,1 do
              if power_tools[i].tool_name==src_item["name"] then
             src_meta=get_item_meta(src_item["metadata"])
             if src_meta==nil then
                src_meta={}
                src_meta["technic_power_tool"]=true
                src_meta["charge"]=0
             else
                if src_meta["technic_power_tool"]==nil then
                   src_meta["technic_power_tool"]=true
                   src_meta["charge"]=0
                end
             end
             local item_max_charge = power_tools[i].max_charge
             local load1           = src_meta["charge"]
             local load_step       = 4000 -- how much to discharge per tick
             if load1>0 and charge<max_charge then
                if charge+load_step>max_charge then load_step=max_charge-charge end
                if load1-load_step<0 then load_step=load1 end
                load1=load1-load_step
                charge=charge+load_step
                set_RE_wear(src_item,load1,item_max_charge)
                src_meta["charge"]=load1
                src_item["metadata"]=set_item_meta(src_meta)
                inv:set_stack("dst", 1, src_item)
             end
             meta:set_int("internal_EU_buffer",charge)
             break
              end
           end
        end
        local load = math.floor((charge/300000) * 100)
        meta:set_string("formspec",
                mv_battery_box_formspec..
                "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                        (load)..":technic_power_meter_fg.png]"
                )
    local pos1={}
                   "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                   (load)..":technic_power_meter_fg.png]"
                 )
    pos1.y=pos.y-1
    pos1.x=pos.x
    pos1.z=pos.z
        -- Next index the surrounding network the get the producers and receivers on the power grid
        local pos1 = {}
        pos1.y = pos.y-1
        pos1.x = pos.x
        pos1.z = pos.z
    meta1 = minetest.env:get_meta(pos1)
    if meta1:get_float("mv_cablelike")~=1 then return end
        meta1 = minetest.env:get_meta(pos1)
        if meta1:get_float("mv_cablelike")~=1 then return end
        local MV_nodes = {}
        local PR_nodes = {}
        local RE_nodes = {}
        local BA_nodes = {}
         MV_nodes[1]={}
         MV_nodes[1].x=pos1.x
        MV_nodes[1].y=pos1.y
        MV_nodes[1].z=pos1.z
        MV_nodes[1].visited=false
table_index=1
    repeat
    check_MV_node (PR_nodes,RE_nodes,MV_nodes,table_index)
    table_index=table_index+1
    if MV_nodes[table_index]==nil then break end
    until false
        MV_nodes[1]   = {}
        MV_nodes[1].x = pos1.x
        MV_nodes[1].y = pos1.y
        MV_nodes[1].z = pos1.z
        local table_index=1
        repeat
           check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,table_index)
           table_index=table_index+1
           if MV_nodes[table_index]==nil then break end
        until false
local pos1={}
i=1
    repeat
    if PR_nodes[i]==nil then break end -- gettin power from all connected producers
        pos1.x=PR_nodes[i].x
        pos1.y=PR_nodes[i].y
        pos1.z=PR_nodes[i].z
    local meta1 = minetest.env:get_meta(pos1)
    local internal_EU_buffer=meta1:get_float("internal_EU_buffer")
    if charge<max_charge then
    charge_to_take=1000
    if internal_EU_buffer-charge_to_take<=0 then
        charge_to_take=internal_EU_buffer
    end
    if charge_to_take>0 then
    charge=charge+charge_to_take
    internal_EU_buffer=internal_EU_buffer-charge_to_take
    meta1:set_float("internal_EU_buffer",internal_EU_buffer)
    end
    end
    i=i+1
    until false
        -- Get power from all connected producers
        local pr_pos
                for _,pr_pos in ipairs(PR_nodes) do
           local meta1              = minetest.env:get_meta(pr_pos)
           local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
           local charge_to_take     = 1000
           if charge<max_charge then
              if internal_EU_buffer-charge_to_take<=0 then
             charge_to_take=internal_EU_buffer
              end
              if charge_to_take>0 then
             charge=charge+charge_to_take
             internal_EU_buffer=internal_EU_buffer-charge_to_take
             meta1:set_float("internal_EU_buffer",internal_EU_buffer)
              end
           end
        end
if charge>max_charge then charge=max_charge end
        if charge>max_charge then charge=max_charge end
i=1
    repeat
    if RE_nodes[i]==nil then break end
        pos1.x=RE_nodes[i].x         -- loading all conected machines buffers
        pos1.y=RE_nodes[i].y
        pos1.z=RE_nodes[i].z
    local meta1 = minetest.env:get_meta(pos1)
    local internal_EU_buffer=meta1:get_float("internal_EU_buffer")
    local internal_EU_buffer_size=meta1:get_float("internal_EU_buffer_size")
        -- Provide power to all connected receivers
        local re_pos
                for _,re_pos in ipairs(RE_nodes) do
           local meta1                   = minetest.env:get_meta(re_pos)
           local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
           local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
           local charge_to_give          = math.min(1000, charge/table.getn(RE_nodes))
           if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
           end
           if charge-charge_to_give<0 then charge_to_give=charge end
    local charge_to_give=1000
    if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
        charge_to_give=internal_EU_buffer_size-internal_EU_buffer
    end
    if charge-charge_to_give<0 then charge_to_give=charge end
           internal_EU_buffer=internal_EU_buffer+charge_to_give
           meta1:set_float("internal_EU_buffer",internal_EU_buffer)
           charge=charge-charge_to_give;
        end
        charge=math.floor(charge)
        meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge);
        meta:set_int("internal_EU_buffer",charge)
         end
 })
    internal_EU_buffer=internal_EU_buffer+charge_to_give
    meta1:set_float("internal_EU_buffer",internal_EU_buffer)
    charge=charge-charge_to_give;
    i=i+1
    until false
    charge=math.floor(charge)
    charge_string=tostring(charge)
    meta:set_string("infotext", "Battery box: "..charge_string.."/"..max_charge);
    meta:set_int("battery_charge",charge)
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
register_MV_machine("technic:mv_battery_box","BA")
for i=1,8,1 do
   register_MV_machine("technic:mv_battery_box"..i,"BA")
end
})
function add_new_MVcable_node (MV_nodes,pos1)
local i=1
    repeat
        if MV_nodes[i]==nil then break end
        if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end
        i=i+1
    until false
MV_nodes[i]={}
MV_nodes[i].x=pos1.x
MV_nodes[i].y=pos1.y
MV_nodes[i].z=pos1.z
MV_nodes[i].visited=false
return true
   if MV_nodes == nil then return true end
   local i=1
   repeat
      if MV_nodes[i]==nil then break end
      if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end
      i=i+1
   until false
   MV_nodes[i]={}
   MV_nodes[i].x=pos1.x
   MV_nodes[i].y=pos1.y
   MV_nodes[i].z=pos1.z
   return true
end
function check_MV_node (PR_nodes,RE_nodes,MV_nodes,i)
        local pos1={}
        pos1.x=MV_nodes[i].x
        pos1.y=MV_nodes[i].y
        pos1.z=MV_nodes[i].z
        MV_nodes[i].visited=true
        new_node_added=false
        pos1.x=pos1.x+1
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.x=pos1.x-2
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.x=pos1.x+1
        pos1.y=pos1.y+1
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.y=pos1.y-2
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.y=pos1.y+1
function check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,i)
   local pos1={}
   pos1.x=MV_nodes[i].x
   pos1.y=MV_nodes[i].y
   pos1.z=MV_nodes[i].z
        pos1.z=pos1.z+1
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.z=pos1.z-2
        check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
        pos1.z=pos1.z+1
return new_node_added
   pos1.x=pos1.x+1
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.x=pos1.x-2
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.x=pos1.x+1
   pos1.y=pos1.y+1
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.y=pos1.y-2
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.y=pos1.y+1
   pos1.z=pos1.z+1
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.z=pos1.z-2
   check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   pos1.z=pos1.z+1
end
function check_MV_node_subp (PR_nodes,RE_nodes,MV_nodes,pos1)
meta = minetest.env:get_meta(pos1)
if meta:get_float("mv_cablelike")==1 then new_node_added=add_new_MVcable_node(MV_nodes,pos1) end
for i in ipairs(MV_machines) do
    if minetest.env:get_node(pos1).name == MV_machines[i].machine_name then
        if MV_machines[i].machine_type == "PR" then
            new_node_added=add_new_MVcable_node(PR_nodes,pos1)
            end
        if MV_machines[i].machine_type == "RE" then
            new_node_added=add_new_MVcable_node(RE_nodes,pos1)
            end
    end
function check_MV_node_subp (PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
   local meta = minetest.env:get_meta(pos1)
   local name = minetest.env:get_node(pos1).name
   if meta:get_float("mv_cablelike")==1 then
      add_new_MVcable_node(MV_nodes,pos1)
   elseif MV_machines[name] then
      --print(name.." is a "..MV_machines[name])
      if     MV_machines[name] == "PR" then
     add_new_MVcable_node(PR_nodes,pos1)
      elseif MV_machines[name] == "RE" then
     add_new_MVcable_node(RE_nodes,pos1)
      elseif MV_machines[name] == "BA" then
     add_new_MVcable_node(BA_nodes,pos1)
      end
   end
end
end
technic/chainsaw.lua
@@ -1,63 +1,268 @@
chainsaw_max_charge=30000
-- Configuration
local chainsaw_max_charge      = 30000 -- 30000 - Maximum charge of the saw
local chainsaw_charge_per_node = 12    -- 12    - Gives 2500 nodes on a single charge (about 50 complete normal trees)
local chainsaw_leaves          = true  -- true  - Cut down entire trees, leaves and all
register_power_tool ("technic:chainsaw",chainsaw_max_charge)
minetest.register_tool("technic:chainsaw", {
    description = "Chainsaw",
    inventory_image = "technic_chainsaw.png",
    stack_max = 1,
    on_use = function(itemstack, user, pointed_thing)
        if pointed_thing.type=="node" then
        item=itemstack:to_table()
        local meta=get_item_meta(item["metadata"])
        if meta==nil then return end --tool not charghed
        if meta["charge"]==nil then return end
        charge=meta["charge"]
        charge_to_take=600;
        if charge-charge_to_take>0 then
         charge_to_take=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge_to_take)
         charge=charge-charge_to_take;
        set_RE_wear(item,charge,chainsaw_max_charge)
        meta["charge"]=charge
        item["metadata"]=set_item_meta(meta)
        itemstack:replace(item)
        return itemstack
        end
        end
    end,
        description = "Chainsaw",
        inventory_image = "technic_chainsaw.png",
        stack_max = 1,
        on_use = function(itemstack, user, pointed_thing)
                if pointed_thing.type=="node" then
                        item=itemstack:to_table()
                        local meta=get_item_meta(item["metadata"])
                        if meta==nil then return end --tool not charged
                        if meta["charge"]==nil then return end
                        -- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
                        local charge=meta["charge"]
                        if charge < chainsaw_charge_per_node then return end -- only cut if charged
                        charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge)
                        set_RE_wear(item,charge,chainsaw_max_charge)
                        meta["charge"]=charge
                        item["metadata"]=set_item_meta(meta)
                        itemstack:replace(item)
                        return itemstack
                end
        end,
})
minetest.register_craft({
    output = 'technic:chainsaw',
    recipe = {
        {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
        {'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'},
        {'','','moreores:copper_ingot'},
    }
        output = 'technic:chainsaw',
        recipe = {
                {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
                {'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'},
                {'','','moreores:copper_ingot'},
        }
})
-- The default stuff
local timber_nodenames={["default:jungletree"] = true,
                        ["default:papyrus"]    = true,
                        ["default:cactus"]     = true,
                        ["default:tree"]       = true,
                        ["default:apple"]      = true
}
if chainsaw_leaves == true then
        timber_nodenames["default:leaves"] = true
end
-- Support moretrees if it is there
if( minetest.get_modpath("moretrees") ~= nil ) then
        timber_nodenames["moretrees:apple_tree_trunk"]                 = true
        timber_nodenames["moretrees:apple_tree_trunk_sideways"]        = true
        timber_nodenames["moretrees:beech_trunk"]                      = true
        timber_nodenames["moretrees:beech_trunk_sideways"]             = true
        timber_nodenames["moretrees:birch_trunk"]                      = true
        timber_nodenames["moretrees:birch_trunk_sideways"]             = true
        timber_nodenames["moretrees:fir_trunk"]                        = true
        timber_nodenames["moretrees:fir_trunk_sideways"]               = true
        timber_nodenames["moretrees:oak_trunk"]                        = true
        timber_nodenames["moretrees:oak_trunk_sideways"]               = true
        timber_nodenames["moretrees:palm_trunk"]                       = true
        timber_nodenames["moretrees:palm_trunk_sideways"]              = true
        timber_nodenames["moretrees:pine_trunk"]                       = true
        timber_nodenames["moretrees:pine_trunk_sideways"]              = true
        timber_nodenames["moretrees:rubber_tree_trunk"]                = true
        timber_nodenames["moretrees:rubber_tree_trunk_sideways"]       = true
        timber_nodenames["moretrees:rubber_tree_trunk_empty"]          = true
        timber_nodenames["moretrees:rubber_tree_trunk_sideways_empty"] = true
        timber_nodenames["moretrees:sequoia_trunk"]                    = true
        timber_nodenames["moretrees:sequoia_trunk_sideways"]           = true
        timber_nodenames["moretrees:spruce_trunk"]                     = true
        timber_nodenames["moretrees:spruce_trunk_sideways"]            = true
        timber_nodenames["moretrees:willow_trunk"]                     = true
        timber_nodenames["moretrees:willow_trunk_sideways"]            = true
        timber_nodenames["moretrees:jungletree_trunk"]                 = true
        timber_nodenames["moretrees:jungletree_trunk_sideways"]        = true
timber_nodenames={"default:jungletree", "default:papyrus", "default:cactus", "default:tree"}
        if chainsaw_leaves == true then
                timber_nodenames["moretrees:apple_tree_leaves"]        = true
                timber_nodenames["moretrees:oak_leaves"]               = true
                timber_nodenames["moretrees:sequoia_leaves"]           = true
                timber_nodenames["moretrees:birch_leaves"]             = true
                timber_nodenames["moretrees:birch_leaves"]             = true
                timber_nodenames["moretrees:palm_leaves"]              = true
                timber_nodenames["moretrees:spruce_leaves"]            = true
                timber_nodenames["moretrees:spruce_leaves"]            = true
                timber_nodenames["moretrees:pine_leaves"]              = true
                timber_nodenames["moretrees:willow_leaves"]            = true
                timber_nodenames["moretrees:rubber_tree_leaves"]       = true
                timber_nodenames["moretrees:jungletree_leaves_green"]  = true
                timber_nodenames["moretrees:jungletree_leaves_yellow"] = true
                timber_nodenames["moretrees:jungletree_leaves_red"]    = true
        end
end
function chainsaw_dig_it (pos, player,charge_to_take)
    charge_to_take=0
    local node=minetest.env:get_node(pos)
    local i=1
    while timber_nodenames[i]~=nil do
        if node.name==timber_nodenames[i] then
            charge_to_take=600
            np={x=pos.x, y=pos.y, z=pos.z}
            while minetest.env:get_node(np).name==timber_nodenames[i] do
                minetest.env:remove_node(np)
                minetest.env:add_item(np, timber_nodenames[i])
                np={x=np.x, y=np.y+1, z=np.z}
            end
            minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,})
            return charge_to_take
        end
        i=i+1
    end
-- Support growing_trees if it is there
if( minetest.get_modpath("growing_trees") ~= nil ) then
        timber_nodenames["growing_trees:trunk"]         = true
        timber_nodenames["growing_trees:medium_trunk"]  = true
        timber_nodenames["growing_trees:big_trunk"]     = true
        timber_nodenames["growing_trees:trunk_top"]     = true
        timber_nodenames["growing_trees:trunk_sprout"]  = true
        timber_nodenames["growing_trees:branch_sprout"] = true
        timber_nodenames["growing_trees:branch"]        = true
        timber_nodenames["growing_trees:branch_xmzm"]   = true
        timber_nodenames["growing_trees:branch_xpzm"]   = true
        timber_nodenames["growing_trees:branch_xmzp"]   = true
        timber_nodenames["growing_trees:branch_xpzp"]   = true
        timber_nodenames["growing_trees:branch_zz"]     = true
        timber_nodenames["growing_trees:branch_xx"]     = true
return charge_to_take
        if chainsaw_leaves == true then
                timber_nodenames["growing_trees:leaves"] = true
        end
end
-- Support growing_cactus if it is there
if( minetest.get_modpath("growing_cactus") ~= nil ) then
        timber_nodenames["growing_cactus:sprout"]                       = true
        timber_nodenames["growing_cactus:branch_sprout_vertical"]       = true
        timber_nodenames["growing_cactus:branch_sprout_vertical_fixed"] = true
        timber_nodenames["growing_cactus:branch_sprout_xp"]             = true
        timber_nodenames["growing_cactus:branch_sprout_xm"]             = true
        timber_nodenames["growing_cactus:branch_sprout_zp"]             = true
        timber_nodenames["growing_cactus:branch_sprout_zm"]             = true
        timber_nodenames["growing_cactus:trunk"]                        = true
        timber_nodenames["growing_cactus:branch_trunk"]                 = true
        timber_nodenames["growing_cactus:branch"]                       = true
        timber_nodenames["growing_cactus:branch_xp"]                    = true
        timber_nodenames["growing_cactus:branch_xm"]                    = true
        timber_nodenames["growing_cactus:branch_zp"]                    = true
        timber_nodenames["growing_cactus:branch_zm"]                    = true
        timber_nodenames["growing_cactus:branch_zz"]                    = true
        timber_nodenames["growing_cactus:branch_xx"]                    = true
end
-- Support farming_plus if it is there
if( minetest.get_modpath("farming_plus") ~= nil ) then
   if chainsaw_leaves == true then
      timber_nodenames["farming_plus:cocoa_leaves"] = true
   end
end
-- Table for saving what was sawed down
local produced
-- Saw down trees entry point
chainsaw_dig_it = function(pos, player,current_charge)
        local remaining_charge=current_charge
        -- Save the currently installed dropping mechanism so we can restore it.
    local original_handle_node_drops = minetest.handle_node_drops
        -- A bit of trickery here: use a different node drop callback
        -- and restore the original afterwards.
        minetest.handle_node_drops = chainsaw_handle_node_drops
        -- clear result and start sawing things down
        produced = {}
        remaining_charge = recursive_dig(pos, remaining_charge, player)
        minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,})
        -- Restore the original noder drop handler
        minetest.handle_node_drops = original_handle_node_drops
        -- Now drop items for the player
        local number, produced_item, p
        for produced_item,number in pairs(produced) do
                --print("ADDING ITEM: " .. produced_item .. " " .. number)
                -- Drop stacks of 99 or less
                p = {
                        x = pos.x + math.random()*4,
                        y = pos.y,
                        z = pos.z + math.random()*4
                }
                while number > 99 do
                        minetest.env:add_item(p, produced_item .. " 99")
                        p = {
                                x = pos.x + math.random()*4,
                                y = pos.y,
                                z = pos.z + math.random()*4
                        }
                        number = number - 99
                end
                minetest.env:add_item(p, produced_item .. " " .. number)
        end
        return remaining_charge
end
-- Override the default handling routine to be able to count up the
-- items sawed down so that we can drop them i an nice single stack
chainsaw_handle_node_drops = function(pos, drops, digger)
        -- Add dropped items to list of collected nodes
        local _, dropped_item
        for _, dropped_item in ipairs(drops) do
                if produced[dropped_item] == nil then
                        produced[dropped_item] = 1
                else
                        produced[dropped_item] = produced[dropped_item] + 1
                end
        end
end
-- This function does all the hard work. Recursively we dig the node at hand
-- if it is in the table and then search the surroundings for more stuff to dig.
recursive_dig = function(pos, remaining_charge, player)
        local node=minetest.env:get_node(pos)
        local i=1
        -- Lookup node name in timber table:
        if timber_nodenames[node.name] ~= nil then
                -- Return if we are out of power
                if remaining_charge < chainsaw_charge_per_node then
                        return 0
                end
                local np
                -- wood found - cut it.
                minetest.env:dig_node(pos)
                remaining_charge=remaining_charge-chainsaw_charge_per_node
                -- check surroundings and run recursively if any charge left
                np={x=pos.x+1, y=pos.y, z=pos.z}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x+1, y=pos.y, z=pos.z+1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x+1, y=pos.y, z=pos.z-1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x-1, y=pos.y, z=pos.z}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x-1, y=pos.y, z=pos.z+1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x-1, y=pos.y, z=pos.z-1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x, y=pos.y+1, z=pos.z}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x, y=pos.y, z=pos.z+1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                np={x=pos.x, y=pos.y, z=pos.z-1}
                if timber_nodenames[minetest.env:get_node(np).name] ~= nil then
                        remaining_charge = recursive_dig(np, remaining_charge)
                end
                return remaining_charge
        end
        -- Nothing sawed down
        return remaining_charge
end
technic/cnc.lua
New file
@@ -0,0 +1,312 @@
-- Technic CNC v1.0 by kpo
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck
-- Idea:
--   Somehw have a tabbed/paged panel if the number of shapes should expand
--   beyond what is available in the panel today.
--   I could imagine some form of API allowing modders to come with their own node
--   box definitions and easily stuff it in the this machine for production.
local shape = {}
local onesize_products = {
   slope                    = 2,
   slope_edge               = 1,
   slope_inner_edge         = 1,
   pyramid                  = 2,
   spike                    = 1,
   cylinder                 = 2,
   sphere                   = 1,
   stick                    = 8,
   slope_upsdown            = 2,
   slope_edge_upsdown       = 1,
   slope_inner_edge_upsdown = 1,
   cylinder_horizontal      = 2,
   slope_lying              = 2,
   onecurvededge            = 1,
   twocurvededge            = 1,
}
local twosize_products = {
   element_straight         = 4,
   element_end              = 2,
   element_cross            = 1,
   element_t                = 1,
   element_edge             = 2,
}
--cnc_recipes ={}
--registered_cnc_recipes_count=1
--
--function register_cnc_recipe (string1,string2)
--   cnc_recipes[registered_cnc_recipes_count]={}
--   cnc_recipes[registered_cnc_recipes_count].src_name=string1
--   cnc_recipes[registered_cnc_recipes_count].dst_name=string2
--   registered_cnc_recipes_count=registered_cnc_recipes_count+1
--   if unified_inventory then
--      unified_inventory.register_craft({
--                      type = "cnc milling",
--                      output = string2,
--                      items = {string1},
--                      width = 0,
--                       })
--   end
--end
local cnc_formspec =
   "invsize[9,11;]"..
   "label[1,0;Choose Milling Program:]"..
   "image_button[1,0.5;1,1;technic_cnc_slope.png;slope; ]"..
   "image_button[2,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]"..
   "image_button[3,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]"..
   "image_button[4,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]"..
   "image_button[5,0.5;1,1;technic_cnc_spike.png;spike; ]"..
   "image_button[6,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]"..
   "image_button[7,0.5;1,1;technic_cnc_sphere.png;sphere; ]"..
   "image_button[8,0.5;1,1;technic_cnc_stick.png;stick; ]"..
   "image_button[1,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdown; ]"..
   "image_button[2,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_edge_upsdown; ]"..
   "image_button[3,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_inner_edge_upsdown; ]"..
   "image_button[4,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]"..
   "image_button[1,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]"..
   "image_button[2,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]"..
   "image_button[3,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]"..
   "label[1,3.5;Slim Elements half / normal height:]"..
   "image_button[1,4;1,0.5;technic_cnc_full.png;full; ]"..
   "image_button[1,4.5;1,0.5;technic_cnc_half.png;half; ]"..
   "image_button[2,4;1,1;technic_cnc_element_straight.png;element_straight; ]"..
   "image_button[3,4;1,1;technic_cnc_element_end.png;element_end; ]"..
   "image_button[4,4;1,1;technic_cnc_element_cross.png;element_cross; ]"..
   "image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]"..
   "image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]"..
   "label[0, 5.5;In:]"..
   "list[current_name;src;0.5,5.5;1,1;]"..
   "label[4, 5.5;Out:]"..
   "list[current_name;dst;5,5.5;4,1;]"..
   "list[current_player;main;0,7;8,4;]"
local cnc_power_formspec=
   "label[0,3;Power]"..
   "image[0,1;1,2;technic_power_meter_bg.png]"
local size     = 1;
-- The form handler is declared here because we need it in both the inactive and active modes
-- in order to be able to change programs wile it is running.
local form_handler = function(pos, formname, fields, sender)
                   -- REGISTER MILLING PROGRAMS AND OUTPUTS:
                   ------------------------------------------
                   -- Program for half/full size
                   if fields["full"] then
                  size = 1
                  return
                   end
                   if fields["half"] then
                  size = 2
                  return
                   end
                   -- Resolve the node name and the number of items to make
                   local meta       = minetest.env:get_meta(pos)
                   local inv        = meta:get_inventory()
                   local inputstack = inv:get_stack("src", 1)
                   local inputname  = inputstack:get_name()
                   local multiplier = 0
                   for k, _ in pairs(fields) do
                  -- Set a multipier for the half/full size capable blocks
                  if twosize_products[k] ~= nil then
                     multiplier = size*twosize_products[k]
                  else
                     multiplier = onesize_products[k]
                  end
                  if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
                     meta:set_float( "cnc_multiplier", multiplier)
                     meta:set_string("cnc_user", sender:get_player_name())
                  end
                  if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
                     meta:set_string("cnc_product",  inputname .. "_technic_cnc_" .. k)
                     print(inputname .. "_technic_cnc_" .. k)
                     break
                  end
                  if twosize_products[k] ~= nil and size==1 then
                     meta:set_string("cnc_product",  inputname .. "_technic_cnc_" .. k .. "_double")
                     print(inputname .. "_technic_cnc_" .. k .. "_double")
                     break
                  end
                   end
                   return
                end -- callback function
-- The actual block inactive state
minetest.register_node("technic:cnc", {
    description = "CNC Milling Machine",
        tiles       = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
               "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"},
        drawtype    = "nodebox",
        paramtype   = "light",
        paramtype2  = "facedir",
        node_box    = {
       type  = "fixed",
       fixed = {
          {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
       },
        },
        selection_box = {
       type = "fixed",
       fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
        },
        groups = {cracky=2},
    legacy_facedir_simple = true,
    technic_power_machine=1,
    internal_EU_buffer=0;
    internal_EU_buffer_size=5000;
    cnc_time = 0;
    src_time = 0; -- fixme
    on_construct = function(pos)
              local meta = minetest.env:get_meta(pos)
              meta:set_string("infotext", "CNC Machine Inactive")
              meta:set_float("technic_power_machine", 1)
              meta:set_float("internal_EU_buffer", 0)
              meta:set_float("internal_EU_buffer_size", 5000)
              meta:set_string("formspec", cnc_formspec..cnc_power_formspec)
              meta:set_float("cnc_time", 0)
              local inv = meta:get_inventory()
              inv:set_size("src", 1)
              inv:set_size("dst", 4)
               end,
    can_dig = function(pos,player)
             local meta = minetest.env:get_meta(pos);
             local inv = meta:get_inventory()
             if not inv:is_empty("src") or not inv:is_empty("dst") then
            minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty");
            return false
             end
             return true
          end,
    on_receive_fields = form_handler,
     })
-- Active state block
minetest.register_node("technic:cnc_active", {
    description = "CNC Machine",
        tiles       = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
               "technic_cnc_side.png",       "technic_cnc_side.png",   "technic_cnc_front_active.png"},
    paramtype2 = "facedir",
    groups = {cracky=2,not_in_creative_inventory=1},
    legacy_facedir_simple = true,
    can_dig = function(pos,player)
             local meta = minetest.env:get_meta(pos);
             local inv = meta:get_inventory()
             if not inv:is_empty("src") or not inv:is_empty("dst") then
            minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty");
            return false
             end
             return true
          end,
    on_receive_fields = form_handler,
})
-- Action code performing the transformation
minetest.register_abm(
   {
      nodenames = {"technic:cnc","technic:cnc_active"},
      interval = 1,
      chance = 1,
      action = function(pos, node, active_object_count, active_object_count_wider)
          local meta = minetest.env:get_meta(pos)
          local charge= meta:get_float("internal_EU_buffer")
          local max_charge= meta:get_float("internal_EU_buffer_size")
          local cnc_cost=350
          local load = math.floor((charge/max_charge)*100)
          meta:set_string("formspec", cnc_formspec..
                  "image[0,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                  (load)..":technic_power_meter_fg.png]"
                )
          local inv = meta:get_inventory()
          local srclist = inv:get_list("src")
          if inv:is_empty("src") then
             meta:set_float("cnc_on",0)
             meta:set_string("cnc_product", "") -- Reset the program
          end
          if (meta:get_float("cnc_on") == 1) then
             if charge>=cnc_cost then
            charge=charge-cnc_cost;
            meta:set_float("internal_EU_buffer",charge)
            meta:set_float("src_time", meta:get_float("src_time") + 1)
            if meta:get_float("src_time") >= meta:get_float("cnc_time") then
               local product = meta:get_string("cnc_product")
               if inv:room_for_item("dst",product) then
                  -- CNC does the transformation
                  ------------------------------
                  if minetest.registered_nodes[product] ~= nil then
                 inv:add_item("dst",product .. " " .. meta:get_float("cnc_multiplier"))
                 srcstack = inv:get_stack("src", 1)
                 srcstack:take_item()
                 inv:set_stack("src",1,srcstack)
                 if inv:is_empty("src") then
                    meta:set_float("cnc_on",0)
                    meta:set_string("cnc_product", "") -- Reset the program
--                    print("cnc product reset")
                 end
                  else
                 minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it.");
                  end
               else
                  minetest.chat_send_player(meta:get_string("cnc_user"), "CNC inventory full!")
               end
               meta:set_float("src_time", 0)
            end
             end
          end
          if (meta:get_float("cnc_on")==0) then
             if not inv:is_empty("src") then
            local product = meta:get_string("cnc_product")
            if minetest.registered_nodes[product] ~= nil then
               meta:set_float("cnc_on",1)
               hacky_swap_node(pos,"technic:cnc_active")
               meta:set_string("infotext", "CNC Machine Active")
               cnc_time=3
               meta:set_float("cnc_time",cnc_time)
               meta:set_float("src_time", 0)
               return
            end
             else
            hacky_swap_node(pos,"technic:cnc")
            meta:set_string("infotext", "CNC Machine Inactive")
             end
          end
           end
   })
register_LV_machine ("technic:cnc","RE")
register_LV_machine ("technic:cnc_active","RE")
-------------------------
-- CNC Machine Recipe
-------------------------
minetest.register_craft({
               output = 'technic:cnc',
               recipe = {
                  {'default:glass',              'technic:diamond_drill_head', 'default:glass'},
                  {'technic:control_logic_unit', 'technic:motor',              'default:steel_ingot'},
                  {'default:steel_ingot',        'default:copper_ingot',       'default:steel_ingot'},
               },
            })
-------------------------
technic/cnc_api.lua
New file
@@ -0,0 +1,372 @@
-- API for the technic CNC machine
-- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck
technic_cnc_api = {}
-- HERE YOU CAN CHANGE THE DETAIL-LEVEL:
----------------------------------------
technic_cnc_api.detail_level = 16 -- 16; 1-32
-- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES:
------------------------------------------------------
local cnc_sphere =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      local sehne
      for i = 1, detail-1 do
     sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
     nodebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne}
      end
      return nodebox
   end
local cnc_cylinder_horizontal =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      local sehne
      for i = 1, detail-1 do
     sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
     nodebox[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne}
      end
      return nodebox
   end
local cnc_cylinder =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      local sehne
      for i = 1, detail-1 do
     sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
     nodebox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne}
      end
      return nodebox
   end
local cnc_twocurvededge =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level*2
      local sehne
      for i = (detail/2)-1, detail-1 do
     sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
     nodebox[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
      end
      return nodebox
   end
local cnc_onecurvededge =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level*2
      local sehne
      for i = (detail/2)-1, detail-1 do
     sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
     nodebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
      end
     return nodebox
   end
local cnc_spike =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)}
end
      return nodebox
   end
local cnc_pyramid =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level/2
      for i = 0, detail-1 do
     nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)}
      end
      return nodebox
   end
local cnc_slope_inner_edge_upsdown =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
     nodebox[i+detail+1]={-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
local cnc_slope_edge_upsdown =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
local cnc_slope_inner_edge =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
     nodebox[i+detail+1]={-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
local cnc_slope_edge =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
local cnc_slope_upsdown =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
local cnc_slope_lying =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5}
      end
      return nodebox
   end
local cnc_slope =
   function()
      local nodebox = {}
      local detail = technic_cnc_api.detail_level
      for i = 0, detail-1 do
     nodebox[i+1]={-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
      end
      return nodebox
   end
-- Define slope boxes for the various nodes
-------------------------------------------
technic_cnc_api.cnc_programs = {
   {suffix  = "technic_cnc_stick",
    nodebox = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15},
    desc    = "Stick"},
   {suffix  = "technic_cnc_element_end_double",
    nodebox = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5},
    desc    = "Element End Double"},
   {suffix  = "technic_cnc_element_cross_double",
    nodebox = {
       {0.3, -0.5, -0.3, 0.5, 0.5, 0.3},
       {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
       {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
    desc    = "Element Cross Double"},
   {suffix  = "technic_cnc_element_t_double",
    nodebox = {
       {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
       {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3},
       {0.3, -0.5, -0.3, 0.5, 0.5, 0.3}},
    desc    = "Element T Double"},
   {suffix  = "technic_cnc_element_edge_double",
    nodebox = {
       {-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
       {-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
    desc    = "Element Edge Double"},
   {suffix  = "technic_cnc_element_straight_double",
    nodebox = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
    desc    = "Element Straight Double"},
   {suffix  = "technic_cnc_element_end",
    nodebox = {-0.3, -0.5, -0.3, 0.3, 0, 0.5},
    desc    = "Element End"},
   {suffix  = "technic_cnc_element_cross",
    nodebox = {
       {0.3, -0.5, -0.3, 0.5, 0, 0.3},
       {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
       {-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
    desc    = "Element Cross"},
   {suffix  = "technic_cnc_element_t",
    nodebox = {
       {-0.3, -0.5, -0.5, 0.3, 0, 0.3},
       {-0.5, -0.5, -0.3, -0.3, 0, 0.3},
       {0.3, -0.5, -0.3, 0.5, 0, 0.3}},
    desc    = "Element T"},
   {suffix  = "technic_cnc_element_edge",
    nodebox = {
       {-0.3, -0.5, -0.5, 0.3, 0, 0.3},
       {-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
    desc    = "Element Edge"},
   {suffix  = "technic_cnc_element_straight",
    nodebox = {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
    desc    = "Element Straight"},
   {suffix  = "technic_cnc_sphere",
    nodebox = cnc_sphere(),
    desc    = "Sphere"},
   {suffix  = "technic_cnc_cylinder_horizontal",
    nodebox = cnc_cylinder_horizontal(),
    desc    = "Cylinder Horizontal"},
   {suffix  = "technic_cnc_cylinder",
    nodebox = cnc_cylinder(),
    desc    = ""},
   {suffix  = "technic_cnc_twocurvededge",
    nodebox = cnc_twocurvededge(),
    desc    = "One Curved Edge Block"},
   {suffix  = "technic_cnc_onecurvededge",
    nodebox = cnc_onecurvededge(),
    desc    = "Two Curved Edge Block"},
   {suffix  = "technic_cnc_spike",
    nodebox = cnc_spike(),
    desc    = "Spike"},
   {suffix  = "technic_cnc_pyramid",
    nodebox = cnc_pyramid(),
    desc    = "Pyramid"},
   {suffix  = "technic_cnc_slope_inner_edge_upsdown",
    nodebox = cnc_slope_inner_edge_upsdown(),
    desc    = "Slope Upside Down Inner Edge"},
   {suffix  = "technic_cnc_slope_edge_upsdown",
    nodebox = cnc_slope_edge_upsdown(),
    desc    = "Slope Upside Down Edge"},
   {suffix  = "technic_cnc_slope_inner_edge",
    nodebox = cnc_slope_inner_edge(),
    desc    = "Slope Inner Edge"},
   {suffix  = "technic_cnc_slope_edge",
    nodebox = cnc_slope_edge(),
    desc    = "Slope Edge"},
   {suffix  = "technic_cnc_slope_upsdown",
    nodebox = cnc_slope_upsdown(),
    desc    = "Slope Upside Down"},
   {suffix  = "technic_cnc_slope_lying",
    nodebox = cnc_slope_lying(),
    desc    = "Slope Lying"},
   {suffix  = "technic_cnc_slope",
    nodebox = cnc_slope(),
    desc    = "Slope"},
--   {suffix  = "",
--    nodebox =},
}
-- Allow disabling certain programs for some node. Default is allowing all types for all nodes
technic_cnc_api.cnc_programs_disable = {
   -- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick
   -- ...
   ["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", "technic_cnc_edge",
               "technic_cnc_inner_edge", "technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown",
               "technic_cnc_stick", "technic_cnc_cylinder_horizontal"}
}
-- Generic function for registering all the different node types
function technic_cnc_api.register_cnc_program(recipeitem, suffix, nodebox, groups, images, description)
   minetest.register_node(":" .. recipeitem .. "_" .. suffix, {
                 description   = description,
                 drawtype      = "nodebox",
                 tiles         = images,
                 paramtype     = "light",
                 paramtype2    = "facedir",
                 walkable      = true,
                 selection_box = {
                type  = "fixed",
                fixed = nodebox
                 },
                 node_box      = {
                type  = "fixed",
                fixed = nodebox
                 },
                 groups        = groups,
              })
end
-- function to iterate over all the programs the CNC machine knows
function technic_cnc_api.register_all(recipeitem, groups, images, description)
   for _, data in ipairs(technic_cnc_api.cnc_programs) do
      -- Disable node creation for disabled node types for some material
      local do_register = true
      if technic_cnc_api.cnc_programs_disable[recipeitem] ~= nil then
     for __, disable in ipairs(technic_cnc_api.cnc_programs_disable[recipeitem]) do
        if disable == data.suffix then
           do_register = false
        end
     end
      end
      -- Create the node if it passes the test
      if do_register then
     technic_cnc_api.register_cnc_program(recipeitem, data.suffix, data.nodebox, groups, images, description.." "..data.desc)
      end
   end
end
-- REGISTER NEW TECHNIC_CNC_API's PART 2: technic_cnc_api.register_element_end(subname, recipeitem, groups, images, desc_element_xyz)
-----------------------------------------------------------------------------------------------------------------------
function technic_cnc_api.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end)
         technic_cnc_api.register_slope(recipeitem, groups, images, desc_slope)
         technic_cnc_api.register_slope_lying(recipeitem, groups, images, desc_slope_lying)
         technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown)
         technic_cnc_api.register_slope_edge(recipeitem, groups, images, desc_slope_edge)
         technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge)
         technic_cnc_api.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge)
         technic_cnc_api.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge)
         technic_cnc_api.register_pyramid(recipeitem, groups, images, desc_pyramid)
         technic_cnc_api.register_spike(recipeitem, groups, images, desc_spike)
         technic_cnc_api.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge)
         technic_cnc_api.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge)
         technic_cnc_api.register_cylinder(recipeitem, groups, images, desc_cylinder)
         technic_cnc_api.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal)
         technic_cnc_api.register_sphere(recipeitem, groups, images, desc_sphere)
         technic_cnc_api.register_element_straight(recipeitem, groups, images, desc_element_straight)
         technic_cnc_api.register_element_edge(recipeitem, groups, images, desc_element_edge)
         technic_cnc_api.register_element_t(recipeitem, groups, images, desc_element_t)
         technic_cnc_api.register_element_cross(recipeitem, groups, images, desc_element_cross)
         technic_cnc_api.register_element_end(recipeitem, groups, images, desc_element_end)
end
-- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz)
------------------------------------------------------------------------------------------------------------
function technic_cnc_api.register_stick_etc(recipeitem, groups, images, desc_stick)
         technic_cnc_api.register_stick(recipeitem, groups, images, desc_stick)
end
function technic_cnc_api.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double)
         technic_cnc_api.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double)
         technic_cnc_api.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double)
         technic_cnc_api.register_element_t_double(recipeitem, groups, images, desc_element_t_double)
         technic_cnc_api.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double)
         technic_cnc_api.register_element_end_double(recipeitem, groups, images, desc_element_end_double)
end
technic/cnc_nodes.lua
New file
@@ -0,0 +1,70 @@
-- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS:
-----------------------------------------------------------
-- DIRT
-------
technic_cnc_api.register_all("default:dirt",
                {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
                {"default_grass.png", "default_dirt.png", "default_grass.png"},
                "Dirt")
technic_cnc_api.cnc_programs_disable["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown",
                            "technic_cnc_edge",   "technic_cnc_inner_edge",
                            "technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown",
                            "technic_cnc_stick", "technic_cnc_cylinder_horizontal"}
-- TREE
-------
technic_cnc_api.register_all("default:tree",
                {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
                {"default_tree.png"},
                "Wooden")
-- WOOD
-------
technic_cnc_api.register_all("default:wood",
                {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
                {"default_wood.png"},
                "Wooden")
-- STONE
--------
technic_cnc_api.register_all("default:stone",
                {cracky=3,not_in_creative_inventory=1},
                {"default_stone.png"},
                "Stone")
-- COBBLE
---------
technic_cnc_api.register_all("default:cobble",
                {cracky=3,not_in_creative_inventory=1},
                {"default_cobble.png"},
                "Cobble")
-- BRICK
--------
technic_cnc_api.register_all("default:brick",
                {cracky=3,not_in_creative_inventory=1},
                {"default_brick.png"},
                "Brick")
-- SANDSTONE
------------
technic_cnc_api.register_all("default:sandstone",
                {crumbly=2,cracky=2,not_in_creative_inventory=1},
                {"default_sandstone.png"},
                "Sandstone")
-- LEAVES
---------
technic_cnc_api.register_all("default:leaves",
                {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
                {"default_leaves.png"},
                "Leaves")
-- TREE
-------
technic_cnc_api.register_all("default:tree",
                {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1},
                {"default_tree.png"},
                "Tree")
-- STEEL
--------
technic_cnc_api.register_all("default:steel",
                {snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1},
                {"default_steel_block.png"},
                "Steel")
technic/config.lua
@@ -1,7 +1,42 @@
enable_technic_inventory=true
enable_mining_drill=true
enable_mining_laser=true
enable_flashlight=true
enable_rubber_tree_generation=true
enable_marble_generation=true
enable_granite_generation=true
technic.config = {}
technic.config.loaded = {}
technic.config.default = {
    enable_mining_drill = "true",
    enable_mining_laser = "true",
    enable_flashlight = "true",
    enable_item_drop = "true",
    enable_item_pickup = "true",
    enable_rubber_tree_generation = "true",
    enable_marble_generation = "true",
    enable_granite_generation = "true"
}
function technic.config:load(filename)
    file, error = io.open(filename, "r")
    if error then return end
    local line = file:read("*l")
    while line do
        local found, _, setting, value = line:find("^([^#%s=]+)%s?=%s?([^%s#]+)")
        if found then
            self.loaded[setting] = value
        end
        line = file:read("*l")
    end
    file:close()
end
technic.config:load(minetest.get_worldpath().."/technic.conf")
function technic.config:get(setting)
    if self.loaded[setting] then
        return self.loaded[setting]
    else
        return self.default[setting]
    end
end
function technic.config:getBool(setting)
    return string.lower(self:get(setting)) == "true"
end
technic/depends.txt
@@ -2,5 +2,4 @@
moreores
pipeworks
mesecons
technic_worldgen
moretrees
technic/down_converter_hv.lua
New file
@@ -0,0 +1,225 @@
-- The HV down converter will step down HV EUs to MV EUs
-- If we take the solar panel as calibration then the
-- 1 HVEU = 5 MVEU as we stack 5 MV arrays to get a HV array.
-- The downconverter does of course have a conversion loss.
-- This loses 30% of the power.
-- The converter does not store any energy by itself.
minetest.register_node("technic:down_converter_hv", {
        description = "HV Down Converter",
    tiles  = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png",
          "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
    drawtype = "nodebox",
    paramtype = "light",
    is_ground_content = true,
    node_box = {
       type = "fixed",
       fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
    },
    selection_box = {
       type = "fixed",
       fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
    },
    on_construct = function(pos)
              local meta = minetest.env:get_meta(pos)
              meta:set_float("technic_hv_power_machine", 1)
              meta:set_float("technic_mv_power_machine", 1)
              meta:set_float("internal_EU_buffer",0)
              meta:set_float("internal_EU_buffer_size",0)
              meta:set_string("infotext", "HV Down Converter")
              meta:set_float("active", false)
               end,
     })
minetest.register_craft({
    output = 'technic:down_converter_hv 1',
    recipe = {
        {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'},
        {'technic:hv_transformer',        'technic:hv_cable',             'technic:mv_transformer'},
        {'technic:hv_cable',              'technic:rubber',               'technic:mv_cable'},
    }
})
minetest.register_abm(
    {nodenames = {"technic:down_converter_hv"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
            -- HV->MV conversion factor
            local hv_mv_factor = 5
            -- The maximun charge a single converter can handle. Let's set this to
            -- what 5 HV solar arrays can produce - 30% loss (2880*5*0.7)
            local max_charge = 10080*hv_mv_factor
            local meta             = minetest.env:get_meta(pos)
            local meta1            = nil
            local pos1             = {}
            local available_charge = 0 -- counted in MV units
            local used_charge      = 0 -- counted in MV units
            -- Index all HV nodes connected to the network
            -- HV cable comes in through the bottom
            pos1.y = pos.y-1
            pos1.x = pos.x
            pos1.z = pos.z
            meta1  = minetest.env:get_meta(pos1)
            if meta1:get_float("hv_cablelike")~=1 then return end
            local HV_nodes    = {} -- HV type
            local HV_PR_nodes = {} -- HV type
            local HV_BA_nodes = {} -- HV type
            HV_nodes[1]         = {}
            HV_nodes[1].x       = pos1.x
            HV_nodes[1].y       = pos1.y
            HV_nodes[1].z       = pos1.z
            local table_index = 1
            repeat
               check_HV_node(HV_PR_nodes,nil,HV_BA_nodes,HV_nodes,table_index)
               table_index = table_index + 1
               if HV_nodes[table_index] == nil then break end
            until false
            --print("HV_nodes: PR="..table.getn(HV_PR_nodes).." BA="..table.getn(HV_BA_nodes))
            -- Index all MV nodes connected to the network
            -- MV cable comes out of the top
            pos1.y = pos.y+1
            pos1.x = pos.x
            pos1.z = pos.z
            meta1  = minetest.env:get_meta(pos1)
            if meta1:get_float("mv_cablelike")~=1 then return end
            local MV_nodes    = {} -- MV type
            local MV_RE_nodes = {} -- MV type
            local MV_BA_nodes = {} -- MV type
            MV_nodes[1]         = {}
            MV_nodes[1].x       = pos1.x
            MV_nodes[1].y       = pos1.y
            MV_nodes[1].z       = pos1.z
            table_index = 1
            repeat
               check_MV_node(nil,MV_RE_nodes,MV_BA_nodes,MV_nodes,table_index)
               table_index = table_index + 1
               if MV_nodes[table_index] == nil then break end
            until false
            --print("MV_nodes: RE="..table.getn(MV_RE_nodes).." BA="..table.getn(MV_BA_nodes))
            -- First get available power from all the attached HV suppliers
            -- Get the supplier internal EU buffer and read the EUs from it
            -- No update yet!
            local pos1
-- FIXME: Until further leave the producers out of it and just let the batteries be the hub
--            for _,pos1 in ipairs(HV_PR_nodes) do
--               meta1  = minetest.env:get_meta(pos1)
--               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
--               available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor
--               -- Limit conversion capacity
--               if available_charge > max_charge then
--              available_charge = max_charge
--              break
--               end
--            end
--            --print("Available_charge PR:"..available_charge)
            for _,pos1 in ipairs(HV_BA_nodes) do
               meta1  = minetest.env:get_meta(pos1)
               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
               available_charge = available_charge + meta1:get_float("internal_EU_buffer") * hv_mv_factor
               -- Limit conversion capacity
               if available_charge > max_charge then
              available_charge = max_charge
              break
               end
            end
            --print("Available_charge PR+BA:"..available_charge)
            -- Calculate total number of receivers:
            local MV_receivers = table.getn(MV_RE_nodes)+table.getn(MV_BA_nodes)
            -- Next supply power to all connected MV machines
            -- Get the power receiver internal EU buffer and give EUs to it
            -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery
--            for _,pos1 in ipairs(MV_RE_nodes) do
--               local meta1                   = minetest.env:get_meta(pos1)
--               local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
--               local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
--               local charge_to_give = math.min(4000, available_charge/MV_receivers) -- power rating limit on the MV wire
--               -- How much can this unit take?
--               if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then
--              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
--               end
--               -- If we are emptying the supply take the remainder
--               if available_charge<used_charge+charge_to_give then charge_to_give=available_charge-used_charge end
--               -- Update the unit supplied to
--               internal_EU_buffer = internal_EU_buffer + charge_to_give
--               meta1:set_float("internal_EU_buffer",internal_EU_buffer)
--               -- Do the accounting
--               used_charge = used_charge + charge_to_give
--               if available_charge == used_charge then break end -- bail out if supply depleted
--            end
            --print("used_charge RE:"..used_charge)
            for _,pos1 in ipairs(MV_BA_nodes) do
               local meta1 = minetest.env:get_meta(pos1)
               local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
               local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
               --print("internal_EU_buffer:"..internal_EU_buffer)
               --print("internal_EU_buffer_size:"..internal_EU_buffer_size)
               local charge_to_give = math.min(math.floor(available_charge/MV_receivers), 4000) -- power rating limit on the MV wire
               --print("charge_to_give:"..charge_to_give)
               -- How much can this unit take?
               if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then
              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
               end
               --print("charge_to_give2:"..charge_to_give)
               -- If we are emptying the supply take the remainder
               if available_charge<used_charge+charge_to_give then charge_to_give=available_charge-used_charge end
               -- Update the unit supplied to
               --print("charge_to_give3:"..charge_to_give)
               internal_EU_buffer = internal_EU_buffer + charge_to_give
               --print("internal_EU_buffer:"..internal_EU_buffer)
               meta1:set_float("internal_EU_buffer",internal_EU_buffer)
               -- Do the accounting
               used_charge = used_charge + charge_to_give
               --print("used_charge:"..used_charge)
               if available_charge == used_charge then break end -- bail out if supply depleted
            end
            --print("used_charge RE+BA:"..used_charge)
            -- Last update the HV suppliers with the actual demand.
            -- Get the supplier internal EU buffer and update the EUs from it
            -- Note: So far PR nodes left out and only BA nodes are updated
            local HV_BA_size = table.getn(HV_BA_nodes)
            for _,pos1 in ipairs(HV_BA_nodes) do
               meta1  = minetest.env:get_meta(pos1)
               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
               local charge_to_take = math.floor(used_charge/HV_BA_size/hv_mv_factor) -- HV units
               if internal_EU_buffer-charge_to_take <= 0 then
              charge_to_take = internal_EU_buffer
               end
               if charge_to_take > 0 then
              internal_EU_buffer = internal_EU_buffer-charge_to_take
              meta1:set_float("internal_EU_buffer",internal_EU_buffer)
               end
            end
            if used_charge>0 then
               meta:set_string("infotext", "HV Down Converter is active (HV:"..available_charge.."/MV:"..used_charge..")");
               meta:set_float("active",1) -- used for setting textures someday maybe
            else
               meta:set_string("infotext", "HV Down Converter is inactive (HV:"..available_charge.."/MV:"..used_charge..")");
               meta:set_float("active",0) -- used for setting textures someday maybe
               return
            end
    end,
})
-- This machine does not store energy it receives energy from the HV side and outputs it on the MV side
register_HV_machine ("technic:down_converter_hv","RE")
register_MV_machine ("technic:down_converter_hv","PR")
technic/down_converter_mv.lua
New file
@@ -0,0 +1,226 @@
-- The MV down converter will step down MV EUs to LV EUs
-- If we take the solar panel as calibration then the
-- 1 MVEU = 5 LVEU as we stack 5 LV arrays to get an MV array.
-- The downconverter does of course have a conversion loss.
-- This loses 30% of the power.
-- The converter does not store any energy by itself.
minetest.register_node(
   "technic:down_converter_mv", {
      description = "MV Down Converter",
      tiles  = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png",
        "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"},
      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
      sounds = default.node_sound_wood_defaults(),
      drawtype = "nodebox",
      paramtype = "light",
      is_ground_content = true,
      node_box = {
     type = "fixed",
     fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
      },
      selection_box = {
     type = "fixed",
     fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
      },
      on_construct = function(pos)
            local meta = minetest.env:get_meta(pos)
            meta:set_float("technic_mv_power_machine", 1)
            meta:set_float("technic_power_machine", 1)
            meta:set_float("internal_EU_buffer",0)
            meta:set_float("internal_EU_buffer_size",0)
            meta:set_string("infotext", "MV Down Converter")
              meta:set_float("active", false)
               end,
   })
minetest.register_craft({
    output = 'technic:down_converter_mv 1',
    recipe = {
        {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'},
        {'technic:mv_transformer',        'technic:mv_cable',             'technic:lv_transformer'},
        {'technic:mv_cable',              'technic:rubber',               'technic:lv_cable'},
    }
})
minetest.register_abm(
    {nodenames = {"technic:down_converter_mv"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
            -- MV->LV conversion factor
            local mv_lv_factor = 5
            -- The maximun charge a single converter can handle. Let's set this to
            -- what 5 MV solar arrays can produce - 30% loss (720*5*0.7)
            local max_charge = 2520*mv_lv_factor
            local meta             = minetest.env:get_meta(pos)
            local meta1            = nil
            local pos1             = {}
            local available_charge = 0 -- counted in LV units
            local used_charge      = 0 -- counted in LV units
            -- Index all MV nodes connected to the network
            -- MV cable comes in through the bottom
            pos1.y = pos.y-1
            pos1.x = pos.x
            pos1.z = pos.z
            meta1  = minetest.env:get_meta(pos1)
            if meta1:get_float("mv_cablelike")~=1 then return end
            local MV_nodes    = {} -- MV type
            local MV_PR_nodes = {} -- MV type
            local MV_BA_nodes = {} -- MV type
            MV_nodes[1]         = {}
            MV_nodes[1].x       = pos1.x
            MV_nodes[1].y       = pos1.y
            MV_nodes[1].z       = pos1.z
            local table_index = 1
            repeat
               check_MV_node(MV_PR_nodes,nil,MV_BA_nodes,MV_nodes,table_index)
               table_index = table_index + 1
               if MV_nodes[table_index] == nil then break end
            until false
            --print("MV_nodes: PR="..table.getn(MV_PR_nodes).." BA="..table.getn(MV_BA_nodes))
            -- Index all LV nodes connected to the network
            -- LV cable comes out of the top
            pos1.y = pos.y+1
            pos1.x = pos.x
            pos1.z = pos.z
            meta1  = minetest.env:get_meta(pos1)
            if meta1:get_float("cablelike")~=1 then return end
            local LV_nodes    = {} -- LV type
            local LV_RE_nodes = {} -- LV type
            local LV_BA_nodes = {} -- LV type
            LV_nodes[1]         = {}
            LV_nodes[1].x       = pos1.x
            LV_nodes[1].y       = pos1.y
            LV_nodes[1].z       = pos1.z
            table_index = 1
            repeat
               check_LV_node(nil,LV_RE_nodes,LV_BA_nodes,LV_nodes,table_index)
               table_index = table_index + 1
               if LV_nodes[table_index] == nil then break end
            until false
            --print("LV_nodes: RE="..table.getn(LV_RE_nodes).." BA="..table.getn(LV_BA_nodes))
            -- First get available power from all the attached MV suppliers
            -- Get the supplier internal EU buffer and read the EUs from it
            -- No update yet!
            local pos1
-- FIXME: Until further leave the producers out of it and just let the batteries be the hub
--            for _,pos1 in ipairs(MV_PR_nodes) do
--               meta1  = minetest.env:get_meta(pos1)
--               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
--               available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor
--               -- Limit conversion capacity
--               if available_charge > max_charge then
--              available_charge = max_charge
--              break
--               end
--            end
--            print("Available_charge PR:"..available_charge)
            for _,pos1 in ipairs(MV_BA_nodes) do
               meta1  = minetest.env:get_meta(pos1)
               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
               available_charge = available_charge + meta1:get_float("internal_EU_buffer") * mv_lv_factor
               -- Limit conversion capacity
               if available_charge > max_charge then
              available_charge = max_charge
              break
               end
            end
            --print("Available_charge PR+BA:"..available_charge)
            -- Calculate total number of receivers:
            local LV_receivers = table.getn(LV_RE_nodes)+table.getn(LV_BA_nodes)
            -- Next supply power to all connected LV machines
            -- Get the power receiver internal EU buffer and give EUs to it
            -- Note: for now leave out RE type machines until producers distribute power themselves even without a battery
--            for _,pos1 in ipairs(LV_RE_nodes) do
--               local meta1                   = minetest.env:get_meta(pos1)
--               local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
--               local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
--               local charge_to_give = math.min(1000, available_charge/LV_receivers) -- power rating limit on the LV wire
--               -- How much can this unit take?
--               if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then
--              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
--               end
--               -- If we are emptying the supply take the remainder
--               if available_charge<used_charge+charge_to_give then charge_to_give=available_charge-used_charge end
--               -- Update the unit supplied to
--               internal_EU_buffer = internal_EU_buffer + charge_to_give
--               meta1:set_float("internal_EU_buffer",internal_EU_buffer)
--               -- Do the accounting
--               used_charge = used_charge + charge_to_give
--               if available_charge == used_charge then break end -- bail out if supply depleted
--            end
            --print("used_charge RE:"..used_charge)
            for _,pos1 in ipairs(LV_BA_nodes) do
               local meta1 = minetest.env:get_meta(pos1)
               local internal_EU_buffer      = meta1:get_float("internal_EU_buffer")
               local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
               --print("internal_EU_buffer:"..internal_EU_buffer)
               --print("internal_EU_buffer_size:"..internal_EU_buffer_size)
               local charge_to_give = math.min(math.floor(available_charge/LV_receivers), 1000) -- power rating limit on the LV wire
               --print("charge_to_give:"..charge_to_give)
               -- How much can this unit take?
               if internal_EU_buffer+charge_to_give > internal_EU_buffer_size then
              charge_to_give=internal_EU_buffer_size-internal_EU_buffer
               end
               --print("charge_to_give2:"..charge_to_give)
               -- If we are emptying the supply take the remainder
               if available_charge<used_charge+charge_to_give then charge_to_give=available_charge-used_charge end
               -- Update the unit supplied to
               --print("charge_to_give3:"..charge_to_give)
               internal_EU_buffer = internal_EU_buffer + charge_to_give
               --print("internal_EU_buffer:"..internal_EU_buffer)
               meta1:set_float("internal_EU_buffer",internal_EU_buffer)
               -- Do the accounting
               used_charge = used_charge + charge_to_give
               --print("used_charge:"..used_charge)
               if available_charge == used_charge then break end -- bail out if supply depleted
            end
            --print("used_charge RE+BA:"..used_charge)
            -- Last update the MV suppliers with the actual demand.
            -- Get the supplier internal EU buffer and update the EUs from it
            -- Note: So far PR nodes left out and only BA nodes are updated
            local MV_BA_size = table.getn(MV_BA_nodes)
            for _,pos1 in ipairs(MV_BA_nodes) do
               meta1  = minetest.env:get_meta(pos1)
               local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
               local charge_to_take = math.floor(used_charge/MV_BA_size/mv_lv_factor) -- MV units
               if internal_EU_buffer-charge_to_take <= 0 then
              charge_to_take = internal_EU_buffer
               end
               if charge_to_take > 0 then
              internal_EU_buffer = internal_EU_buffer-charge_to_take
              meta1:set_float("internal_EU_buffer",internal_EU_buffer)
               end
            end
            if used_charge>0 then
               meta:set_string("infotext", "MV Down Converter is active (MV:"..available_charge.."/LV:"..used_charge..")");
               meta:set_float("active",1) -- used for setting textures someday maybe
            else
               meta:set_string("infotext", "MV Down Converter is inactive (MV:"..available_charge.."/LV:"..used_charge..")");
               meta:set_float("active",0) -- used for setting textures someday maybe
               return
            end
    end,
})
-- This machine does not store energy it receives energy from the MV side and outputs it on the LV side
register_MV_machine ("technic:down_converter_mv","RE")
register_LV_machine ("technic:down_converter_mv","PR")
technic/geothermal.lua
@@ -4,8 +4,8 @@
    output = 'technic:geothermal',
    recipe = {
        {'default:stone', 'default:stone', 'default:stone'},
        {'moreores:copper_ingot', 'technic:diamond', 'moreores:copper_ingot'},
        {'default:stone', 'moreores:copper_ingot', 'default:stone'},
        {'default:copper_ingot', 'default:diamond', 'default:copper_ingot'},
        {'default:stone', 'default:copper_ingot', 'default:stone'},
    }
})
technic/grinder.lua
@@ -7,11 +7,12 @@
grinder_recipes[registered_grinder_recipes_count].src_name=string1
grinder_recipes[registered_grinder_recipes_count].dst_name=string2
registered_grinder_recipes_count=registered_grinder_recipes_count+1
if UI_recipes_hook then
    minetest.register_craft({
if unified_inventory then
    unified_inventory.register_craft({
    type = "grinding",
    output = string2,
    recipe = string1,
    items = {string1},
    width = 0,
    })
    end
end
@@ -20,26 +21,36 @@
register_grinder_recipe("default:cobble","default:gravel")
register_grinder_recipe("default:gravel","default:dirt")
register_grinder_recipe("default:desert_stone","default:desert_sand")
register_grinder_recipe("default:iron_lump","technic:iron_dust 2")
register_grinder_recipe("default:coal_lump","technic:coal_dust 2")
register_grinder_recipe("moreores:copper_lump","technic:copper_dust 2")
register_grinder_recipe("default:iron_lump","technic:iron_dust 2")
register_grinder_recipe("default:steel_ingot","technic:iron_dust 1")
register_grinder_recipe("default:coal_lump","technic:coal_dust 2")
register_grinder_recipe("default:copper_lump","technic:copper_dust 2")
register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2")
register_grinder_recipe("default:copper_ingot","technic:copper_dust 1")
register_grinder_recipe("default:gold_lump","technic:gold_dust 2")
register_grinder_recipe("default:gold_ingot","technic:gold_dust 1")
--register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1")  -- Dust does not exist yet
--register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod
register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2")
register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1")
register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2")
register_grinder_recipe("moreores:gold_lump","technic:gold_dust 2")
register_grinder_recipe("default:gold_lump","technic:gold_dust 2")
register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2")
register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2")
register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2")
register_grinder_recipe("technic:coal_dust","dye:black 2")
register_grinder_recipe("default:cactus","dye:green 2")
register_grinder_recipe("default:dry_shrub","dye:brown 2")
register_grinder_recipe("flowers:flower_geranium","dye:blue 2")
register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2")
register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2")
register_grinder_recipe("flowers:flower_tulip","dye:orange 2")
register_grinder_recipe("flowers:flower_rose","dye:red 2")
register_grinder_recipe("flowers:flower_viola","dye:violet 2")
register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1")
register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2")
register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1")
register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2")
register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1")
register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1")
register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1")
register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2")
register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1")
register_grinder_recipe("technic:coal_dust","dye:black 2")
register_grinder_recipe("default:cactus","dye:green 2")
register_grinder_recipe("default:dry_shrub","dye:brown 2")
register_grinder_recipe("flowers:flower_geranium","dye:blue 2")
register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2")
register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2")
register_grinder_recipe("flowers:flower_tulip","dye:orange 2")
register_grinder_recipe("flowers:flower_rose","dye:red 2")
register_grinder_recipe("flowers:flower_viola","dye:violet 2")
minetest.register_craftitem( "technic:coal_dust", {
    description = "Coal Dust",
@@ -57,7 +68,7 @@
    type = "cooking",
    output = "default:steel_ingot",
    recipe = "technic:iron_dust",
})
})
minetest.register_craftitem( "technic:copper_dust", {
    description = "Copper Dust",
@@ -68,7 +79,7 @@
    type = "cooking",
    output = "moreores:copper_ingot",
    recipe = "technic:copper_dust",
})
})
minetest.register_craftitem( "technic:tin_dust", {
    description = "Tin Dust",
@@ -79,7 +90,7 @@
    type = "cooking",
    output = "moreores:tin_ingot",
    recipe = "technic:tin_dust",
})
})
minetest.register_craftitem( "technic:silver_dust", {
    description = "Silver Dust",
@@ -90,7 +101,7 @@
    type = "cooking",
    output = "moreores:silver_ingot",
    recipe = "technic:silver_dust",
})
})
minetest.register_craftitem( "technic:gold_dust", {
    description = "Gold Dust",
@@ -101,7 +112,7 @@
    type = "cooking",
    output = "moreores:gold_ingot",
    recipe = "technic:gold_dust",
})
})
minetest.register_craftitem( "technic:mithril_dust", {
    description = "Mithril Dust",
@@ -112,7 +123,7 @@
    type = "cooking",
    output = "moreores:mithril_ingot",
    recipe = "technic:mithril_dust",
})
})
minetest.register_craftitem( "technic:chromium_dust", {
    description = "Chromium Dust",
@@ -123,7 +134,7 @@
    type = "cooking",
    output = "technic:chromium_ingot",
    recipe = "technic:chromium_dust",
})
})
minetest.register_craftitem( "technic:bronze_dust", {
    description = "Bronze Dust",
@@ -134,7 +145,7 @@
    type = "cooking",
    output = "moreores:bronze_ingot",
    recipe = "technic:bronze_dust",
})
})
minetest.register_craftitem( "technic:brass_dust", {
    description = "Brass Dust",
@@ -145,7 +156,7 @@
    type = "cooking",
    output = "technic:brass_ingot",
    recipe = "technic:brass_dust",
})
})
minetest.register_craftitem( "technic:stainless_steel_dust", {
    description = "Stainless Steel Dust",
@@ -156,7 +167,7 @@
    type = "cooking",
    output = "technic:stainless_steel_ingot",
    recipe = "technic:stainless_steel_dust",
})
})
minetest.register_craftitem( "technic:zinc_dust", {
    description = "Zinc Dust",
@@ -167,7 +178,7 @@
    type = "cooking",
    output = "technic:zinc_ingot",
    recipe = "technic:zinc_dust",
})
})
minetest.register_alias("grinder", "technic:grinder")
minetest.register_craft({
@@ -182,7 +193,7 @@
minetest.register_craftitem("technic:grinder", {
    description = "Grinder",
    stack_max = 99,
})
})
grinder_formspec =
    "invsize[8,9;]"..
@@ -279,7 +290,7 @@
        local inv = meta:get_inventory()
        local srclist = inv:get_list("src")
        if inv:is_empty("src") then meta:set_float("grinder_on",0) end
        if inv:is_empty("src") then meta:set_float("grinder_on",0) end
        if (meta:get_float("grinder_on") == 1) then
            if charge>=grind_cost then
@@ -288,7 +299,7 @@
            meta:set_float("src_time", meta:get_float("src_time") + 1)
            if meta:get_float("src_time") >= meta:get_float("grind_time") then
                -- check if there's room for output in "dst" list
                grinded = get_grinded_item (inv:get_stack("src", 1))
                grinded = get_grinded_item (inv:get_stack("src", 1))
                if inv:room_for_item("dst",grinded) then
                    -- Put result in "dst" list
                    inv:add_item("dst", grinded)
@@ -296,7 +307,7 @@
                    srcstack = inv:get_stack("src", 1)
                    srcstack:take_item()
                    inv:set_stack("src", 1, srcstack)
                    if inv:is_empty("src") then meta:set_float("grinder_on",0) end
                    if inv:is_empty("src") then meta:set_float("grinder_on",0) end
                else
                    print("Grinder inventory full!")
                end
@@ -305,10 +316,10 @@
            end
        end
        if (meta:get_float("grinder_on")==0) then
        local grinded=nil
        local grinded=nil
        if not inv:is_empty("src") then
            grinded = get_grinded_item (inv:get_stack("src", 1))
            if grinded then
            if grinded then
                meta:set_float("grinder_on",1)
                hacky_swap_node(pos,"technic:grinder_active")
                meta:set_string("infotext", "Grinder Active")
@@ -317,13 +328,13 @@
                meta:set_float("src_time", 0)
                return
            end
            else
            else
                hacky_swap_node(pos,"technic:grinder")
                meta:set_string("infotext", "Grinder Inactive")
        end
        end
    end
})
})
function get_grinded_item (items)
new_item =nil
technic/init.lua
@@ -2,6 +2,8 @@
-- namespace: technic
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
technic = {}
modpath=minetest.get_modpath("technic")
--Read technic config file
@@ -18,6 +20,7 @@
dofile(modpath.."/alloy_furnaces_commons.lua")
dofile(modpath.."/alloy_furnace.lua")
dofile(modpath.."/solar_panel.lua")
dofile(modpath.."/solar_array_lv.lua")
dofile(modpath.."/geothermal.lua")
dofile(modpath.."/water_mill.lua")
dofile(modpath.."/electric_furnace.lua")
@@ -25,19 +28,29 @@
dofile(modpath.."/music_player.lua")
dofile(modpath.."/generator.lua")
dofile(modpath.."/grinder.lua")
dofile(modpath.."/cnc.lua")
dofile(modpath.."/cnc_api.lua")
dofile(modpath.."/cnc_nodes.lua")
--MV machines
dofile(modpath.."/wires_mv.lua")
dofile(modpath.."/battery_box_mv.lua")
dofile(modpath.."/solar_panel_mv.lua")
dofile(modpath.."/solar_array_mv.lua")
dofile(modpath.."/down_converter_mv.lua")
dofile(modpath.."/electric_furnace_mv.lua")
dofile(modpath.."/alloy_furnace_mv.lua")
dofile(modpath.."/forcefield.lua")
--HV machines
dofile(modpath.."/wires_hv.lua")
dofile(modpath.."/battery_box_hv.lua")
dofile(modpath.."/solar_array_hv.lua")
dofile(modpath.."/down_converter_hv.lua")
--Tools
if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end
if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end
if enable_flashlight==true then dofile(modpath.."/flashlight.lua") end
if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end
if technic.config:getBool("enable_mining_laser") then dofile(modpath.."/mining_laser_mk1.lua") end
if technic.config:getBool("enable_flashlight") then dofile(modpath.."/flashlight.lua") end
dofile(modpath.."/cans.lua")
dofile(modpath.."/chainsaw.lua")
dofile(modpath.."/tree_tap.lua")
technic/items.lua
@@ -160,6 +160,21 @@
    }
})
minetest.register_craftitem( "technic:lv_transformer", {
    description = "Low Voltage Transformer",
    inventory_image = "technic_lv_transformer.png",
    on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
    output = 'technic:lv_transformer',
    recipe = {
        {'default:iron_lump',   'default:iron_lump', 'default:iron_lump'},
        {'technic:copper_coil', 'default:iron_lump', 'technic:copper_coil'},
        {'default:iron_lump',   'default:iron_lump', 'default:iron_lump'},
    }
})
minetest.register_craftitem( "technic:mv_transformer", {
    description = "Medium Voltage Transformer",
    inventory_image = "technic_mv_transformer.png",
@@ -175,6 +190,21 @@
    }
})
minetest.register_craftitem( "technic:hv_transformer", {
    description = "High Voltage Transformer",
    inventory_image = "technic_hv_transformer.png",
    on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
    output = 'technic:hv_transformer',
    recipe = {
        {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
        {'technic:copper_coil',           'technic:stainless_steel_ingot', 'technic:copper_coil'},
        {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
    }
})
minetest.register_craftitem( "technic:control_logic_unit", {
    description = "Control Logic Unit",
    inventory_image = "technic_control_logic_unit.png",
technic/mining_drill.lua
@@ -217,11 +217,11 @@
    stack_max = 1,
    on_use = function(itemstack, user, pointed_thing)
        if pointed_thing.type=="node" then 
        item=itemstack:to_table()
        local item=itemstack:to_table()
        local meta=get_item_meta(item["metadata"])
        if meta==nil then return end --tool not charghed
        if meta["charge"]==nil then return end
        charge=meta["charge"]
        local charge=meta["charge"]
        if charge-mining_drill_power_usage>0 then
            charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,1,1)
            charge =charge-mining_drill_power_usage;
@@ -287,7 +287,7 @@
    local keys=user:get_player_control()
    local player_name=user:get_player_name()
    local item=itemstack:to_table()
    meta=get_item_meta(item["metadata"])
    local meta=get_item_meta(item["metadata"])
    if meta==nil or keys["sneak"]==true then return mining_drill_mk2_setmode(user,itemstack) end
    if meta["mode"]==nil then return mining_drill_mk2_setmode(user,itemstack) end
    if pointed_thing.type~="node" then return end
@@ -309,14 +309,13 @@
    local keys=user:get_player_control()
    local player_name=user:get_player_name()
    local item=itemstack:to_table()
    meta=get_item_meta(item["metadata"])
    local meta=get_item_meta(item["metadata"])
    if meta==nil or keys["sneak"]==true then return mining_drill_mk3_setmode(user,itemstack) end
    if meta["mode"]==nil then return mining_drill_mk3_setmode(user,itemstack) end
    if pointed_thing.type~="node" then return end
    if meta["charge"]==nil then return end
    charge=meta["charge"]
    local charge=meta["charge"]
    if charge-mining_drill_power_usage>0 then
        print(dump(meta))
        local charge_to_take=drill_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,3,meta["mode"])
        charge=charge-charge_to_take;
        if charge<0 then charge=0 end
technic/rubber.lua
@@ -88,14 +88,12 @@
    end
})
minetest.register_on_generated(function(minp, maxp, blockseed)
    if math.random(1, 100) > 5 then
        return
    end
    local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
    local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
    if pos ~= nil then
            rubber_tree={
if technic.config:getBool("enable_rubber_tree_generation") then
    minetest.register_on_generated(function(minp, maxp, blockseed)
        if math.random(1, 100) > 5 then
            return
        end
        local rubber_tree={
            axiom="FFFFA",
            rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]",
            rules_b="[&FFA]////[&FFA]////[&FFA]",
@@ -107,10 +105,14 @@
            thin_trunks=false;
            fruit_tree=false,
            fruit=""
            }
            minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z},rubber_tree)
    end
end)
        }
        local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
        local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
        if pos ~= nil then
            minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z}, rubber_tree)
        end
    end)
end
-- ========= FUEL =========
technic/solar_array_hv.lua
New file
@@ -0,0 +1,93 @@
-- The high voltage solar array is an assembly of medium voltage arrays.
-- The assembly can deliver high voltage levels and is a 20% less efficient
-- compared to 5 individual medium voltage arrays due to losses in the transformer.
-- However high voltage is supplied.
-- Solar arrays are not able to store large amounts of energy.
minetest.register_node("technic:solar_array_hv", {
    tiles = {"technic_hv_solar_array_top.png", "technic_hv_solar_array_bottom.png", "technic_hv_solar_array_side.png",
         "technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
        description="HV Solar Array",
    active = false,
    technic_hv_power_machine=1,
    internal_EU_buffer=0;
    internal_EU_buffer_size=3000;
    drawtype = "nodebox",
    paramtype = "light",
    is_ground_content = true,
    node_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_float("technic_hv_power_machine", 1)
        meta:set_float("internal_EU_buffer", 0)
        meta:set_float("internal_EU_buffer_size", 3000)
        meta:set_string("infotext", "HV Solar Array")
        meta:set_float("active", false)
    end,
})
minetest.register_craft({
    output = 'technic:solar_array_hv 1',
    recipe = {
        {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'},
        {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'},
        {'default:steel_ingot',    'technic:hv_cable',      'default:steel_ingot'},
    }
})
minetest.register_abm(
    {nodenames = {"technic:solar_array_hv"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        -- The action here is to make the solar array produce power
        -- Power is dependent on the light level and the height above ground
        -- 130m and above is optimal as it would be above cloud level.
                -- Height gives 1/4 of the effect, light 3/4. Max. effect is 2880EU for the array.
                -- There are many ways to cheat by using other light sources like lamps.
                -- As there is no way to determine if light is sunlight that is just a shame.
                -- To take care of some of it solar panels do not work outside daylight hours or if
                -- built below -10m
        local pos1={}
        pos1.y=pos.y+1
        pos1.x=pos.x
        pos1.z=pos.z
        local light = minetest.env:get_node_light(pos1, nil)
        local time_of_day = minetest.env:get_timeofday()
        local meta = minetest.env:get_meta(pos)
        if light == nil then light = 0 end
        -- turn on array only during day time and if sufficient light
                -- I know this is counter intuitive when cheating by using other light sources.
        if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
            local internal_EU_buffer      = meta:get_float("internal_EU_buffer")
            local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size")
            local charge_to_give          = math.floor(light*(light*9.6+pos1.y/130*48))
            if charge_to_give<0   then charge_to_give=0 end
            if charge_to_give>2880 then charge_to_give=2880 end
            if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
               charge_to_give=internal_EU_buffer_size-internal_EU_buffer
            end
            meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
            meta:set_float("active",1)
            internal_EU_buffer=internal_EU_buffer+charge_to_give
            meta:set_float("internal_EU_buffer",internal_EU_buffer)
        else
            meta:set_string("infotext", "Solar Array is inactive");
            meta:set_float("active",0)
        end
    end,
})
register_HV_machine ("technic:solar_array_hv","PR")
technic/solar_array_lv.lua
New file
@@ -0,0 +1,94 @@
-- The solar array is an assembly of panels into a powerful array
-- The assembly can deliver more energy than the individual panel because
-- of the transformer unit which converts the panel output variations into
-- a stable supply.
-- Solar arrays are not able to store large amounts of energy.
-- The LV arrays are used to make medium voltage arrays.
minetest.register_node("technic:solar_array_lv", {
    tiles = {"technic_lv_solar_array_top.png", "technic_lv_solar_array_bottom.png", "technic_lv_solar_array_side.png",
        "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
        description="LV Solar Array",
    active = false,
    technic_power_machine=1,
    internal_EU_buffer=0;
    internal_EU_buffer_size=1000;
    drawtype = "nodebox",
    paramtype = "light",
    is_ground_content = true,
    node_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_float("technic_power_machine", 1)
        meta:set_float("internal_EU_buffer", 0)
        meta:set_float("internal_EU_buffer_size", 1000)
        meta:set_string("infotext", "LV Solar Array")
        meta:set_float("active", false)
    end,
})
minetest.register_craft({
    output = 'technic:solar_array_lv 1',
    recipe = {
        {'technic:solar_panel', 'technic:solar_panel',    'technic:solar_panel'},
        {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'},
        {'default:steel_ingot', 'technic:lv_cable',       'default:steel_ingot'},
    }
})
minetest.register_abm(
    {nodenames = {"technic:solar_array_lv"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        -- The action here is to make the solar array produce power
        -- Power is dependent on the light level and the height above ground
        -- 130m and above is optimal as it would be above cloud level.
                -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array.
                -- There are many ways to cheat by using other light sources like lamps.
                -- As there is no way to determine if light is sunlight that is just a shame.
                -- To take care of some of it solar arrays do not work outside daylight hours or if
                -- built below -10m
        local pos1={}
        pos1.y=pos.y+1
        pos1.x=pos.x
        pos1.z=pos.z
        local light = minetest.env:get_node_light(pos1, nil)
        local time_of_day = minetest.env:get_timeofday()
        local meta = minetest.env:get_meta(pos)
        if light == nil then light = 0 end
        -- turn on array only during day time and if sufficient light
                -- I know this is counter intuitive when cheating by using other light sources.
        if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
            local internal_EU_buffer      = meta:get_float("internal_EU_buffer")
            local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size")
            local charge_to_give          = math.floor(light*(light*0.5333+pos1.y/130*2.6667))
            if charge_to_give<0   then charge_to_give=0 end
            if charge_to_give>160 then charge_to_give=160 end
            if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
               charge_to_give=internal_EU_buffer_size-internal_EU_buffer
            end
            meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
            meta:set_float("active",1)
            internal_EU_buffer=internal_EU_buffer+charge_to_give
            meta:set_float("internal_EU_buffer",internal_EU_buffer)
        else
            meta:set_string("infotext", "Solar Array is inactive");
            meta:set_float("active",0)
        end
    end,
})
register_LV_machine ("technic:solar_array_lv","PR")
technic/solar_array_mv.lua
New file
@@ -0,0 +1,95 @@
-- The medium voltage solar array is an assembly of low voltage arrays.
-- The assembly can deliver medium voltage levels and is a 10% less efficient
-- compared to 5 individual low voltage arrays due to losses in the transformer.
-- However medium voltage is supplied.
-- Solar arrays are not able to store large amounts of energy.
-- The MV arrays are used to make high voltage arrays.
minetest.register_node("technic:solar_array_mv", {
    tiles = {"technic_mv_solar_array_top.png", "technic_mv_solar_array_bottom.png", "technic_mv_solar_array_side.png",
         "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
        description="MV Solar Array",
    active = false,
    technic_mv_power_machine=1,
    internal_EU_buffer=0;
    internal_EU_buffer_size=1000;
    drawtype = "nodebox",
    paramtype = "light",
    is_ground_content = true,
    node_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_float("technic_mv_power_machine", 1)
        meta:set_float("internal_EU_buffer", 0)
        meta:set_float("internal_EU_buffer_size", 1000)
        meta:set_string("infotext", "MV Solar Array")
        meta:set_float("active", false)
    end,
})
minetest.register_craft({
    output = 'technic:solar_array_mv 1',
    recipe = {
        {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'},
        {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'},
        {'default:steel_ingot',    'technic:mv_cable',      'default:steel_ingot'},
    }
})
minetest.register_abm(
    {nodenames = {"technic:solar_array_mv"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        -- The action here is to make the solar array produce power
        -- Power is dependent on the light level and the height above ground
        -- 130m and above is optimal as it would be above cloud level.
                -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array.
                -- There are many ways to cheat by using other light sources like lamps.
                -- As there is no way to determine if light is sunlight that is just a shame.
                -- To take care of some of it solar panels do not work outside daylight hours or if
                -- built below -10m
        local pos1={}
        pos1.y=pos.y+1
        pos1.x=pos.x
        pos1.z=pos.z
        local light = minetest.env:get_node_light(pos1, nil)
        local time_of_day = minetest.env:get_timeofday()
        local meta = minetest.env:get_meta(pos)
        if light == nil then light = 0 end
        -- turn on array only during day time and if sufficient light
                -- I know this is counter intuitive when cheating by using other light sources.
        if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
            local internal_EU_buffer      = meta:get_float("internal_EU_buffer")
            local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size")
            local charge_to_give          = math.floor(light*(light*2.4+pos1.y/130*12))
            if charge_to_give<0   then charge_to_give=0 end
            if charge_to_give>720 then charge_to_give=720 end
            if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
               charge_to_give=internal_EU_buffer_size-internal_EU_buffer
            end
            meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
            meta:set_float("active",1)
            internal_EU_buffer=internal_EU_buffer+charge_to_give
            meta:set_float("internal_EU_buffer",internal_EU_buffer)
            -- Idea: How about letting solar panels provide power without battery boxes?
            -- This could provide an even distribution to all receivers.
        else
            meta:set_string("infotext", "Solar Array is inactive");
            meta:set_float("active",0)
        end
    end,
})
register_MV_machine ("technic:solar_array_mv","PR")
technic/solar_panel.lua
@@ -1,3 +1,6 @@
-- Solar panels are the building blocks of LV solar arrays
-- They can however also be used separately but with reduced efficiency due to the missing transformer.
-- Individual panels are 20% less efficient than when the panels are combined into full arrays.
minetest.register_node("technic:solar_panel", {
    tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
        "technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"},
@@ -7,7 +10,7 @@
    active = false,
    technic_power_machine=1,
    internal_EU_buffer=0;
    internal_EU_buffer_size=1000;
    internal_EU_buffer_size=160;
    drawtype = "nodebox",
    paramtype = "light",
    is_ground_content = true,    
@@ -23,7 +26,7 @@
        local meta = minetest.env:get_meta(pos)
        meta:set_float("technic_power_machine", 1)
        meta:set_float("internal_EU_buffer", 0)
        meta:set_float("internal_EU_buffer_size", 1000)
        meta:set_float("internal_EU_buffer_size", 160)
        meta:set_string("infotext", "Solar Panel")
        meta:set_float("active", false)
@@ -34,7 +37,7 @@
    output = 'technic:solar_panel 1',
    recipe = {
        {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
        {'technic:doped_silicon_wafer', 'moreores:copper_ingot','technic:doped_silicon_wafer'},
        {'technic:doped_silicon_wafer', 'technic:lv_cable',           'technic:doped_silicon_wafer'},
        {'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
    }
@@ -42,29 +45,39 @@
minetest.register_abm(
    {nodenames = {"technic:solar_panel"},
    interval = 1,
    chance = 1,
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        -- The action here is to make the solar panel prodice power
        -- Power is dependent on the light level and the height above ground
        -- 130m and above is optimal as it would be above cloud level.
                -- Height gives 1/4 of the effect, light 3/4. Max. effect is 26EU.
                -- There are many ways to cheat by using other light sources like lamps.
                -- As there is no way to determine if light is sunlight that is just a shame.
                -- To take care of some of it solar panels do not work outside daylight hours or if
                -- built below -10m
        local pos1={}
        pos1.y=pos.y+1
        pos1.x=pos.x
        pos1.z=pos.z
        local light = minetest.env:get_node_light(pos1, nil)
        local time_of_day = minetest.env:get_timeofday()
        local meta = minetest.env:get_meta(pos)
        if light == nil then light = 0 end
        if light >= 12 then
            meta:set_string("infotext", "Solar Panel is active ")
            meta:set_float("active",1)
        -- turn on panel only during day time and if sufficient light
                -- I know this is counter intuitive when cheating by using other light sources underground.
        if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
            local internal_EU_buffer=meta:get_float("internal_EU_buffer")
            local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size")
            local charge_to_give=40+(pos1.y/250*40) -- make solar energy depending on height
            local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333))
            if charge_to_give<0 then charge_to_give=0 end
            if charge_to_give>160 then charge_to_give=160 end
            if charge_to_give>26 then charge_to_give=26 end
            if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
            charge_to_give=internal_EU_buffer_size-internal_EU_buffer
               charge_to_give=internal_EU_buffer_size-internal_EU_buffer
            end
            meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)")
            meta:set_float("active",1)
            internal_EU_buffer=internal_EU_buffer+charge_to_give
            meta:set_float("internal_EU_buffer",internal_EU_buffer)
            
technic/sonic_screwdriver.lua
@@ -52,7 +52,7 @@
minetest.register_craft({
    output = "technic:sonic_screwdriver",
    recipe = {
        {"technic:diamond"},
        {"default:diamond"},
        {"technic:battery"},
        {"technic:stainless_steel_ingot"}
        }
technic/textures/technic_cnc_bottom.png
technic/textures/technic_cnc_cylinder.png
technic/textures/technic_cnc_cylinder_horizontal.png
technic/textures/technic_cnc_element_cross.png
technic/textures/technic_cnc_element_edge.png
technic/textures/technic_cnc_element_end.png
technic/textures/technic_cnc_element_straight.png
technic/textures/technic_cnc_element_t.png
technic/textures/technic_cnc_front.png
technic/textures/technic_cnc_front_active.png
technic/textures/technic_cnc_full.png
technic/textures/technic_cnc_half.png
technic/textures/technic_cnc_milling_background.png
technic/textures/technic_cnc_onecurvededge.png
technic/textures/technic_cnc_pyramid.png
technic/textures/technic_cnc_side.png
technic/textures/technic_cnc_slope.png
technic/textures/technic_cnc_slope_edge.png
technic/textures/technic_cnc_slope_edge_upsdwn.png
technic/textures/technic_cnc_slope_inner_edge.png
technic/textures/technic_cnc_slope_inner_edge_upsdwn.png
technic/textures/technic_cnc_slope_lying.png
technic/textures/technic_cnc_slope_upsdwn.png
technic/textures/technic_cnc_sphere.png
technic/textures/technic_cnc_spike.png
technic/textures/technic_cnc_stick.png
technic/textures/technic_cnc_top.png
technic/textures/technic_cnc_top_active.png
technic/textures/technic_cnc_twocurvededge.png
technic/textures/technic_hv_battery_box_bottom.png
technic/textures/technic_hv_battery_box_side0.png
technic/textures/technic_hv_battery_box_top.png
technic/textures/technic_hv_cable.png
technic/textures/technic_hv_cable_wield.png
technic/textures/technic_hv_down_converter_bottom.png
technic/textures/technic_hv_down_converter_side.png
technic/textures/technic_hv_down_converter_top.png
technic/textures/technic_hv_solar_array_bottom.png
technic/textures/technic_hv_solar_array_side.png
technic/textures/technic_hv_solar_array_top.png
technic/textures/technic_hv_transformer.png
technic/textures/technic_lv_solar_array_bottom.png
technic/textures/technic_lv_solar_array_side.png
technic/textures/technic_lv_solar_array_top.png
technic/textures/technic_lv_transformer.png
technic/textures/technic_mv_cable_wield.png

technic/textures/technic_mv_down_converter_bottom.png
technic/textures/technic_mv_down_converter_side.png
technic/textures/technic_mv_down_converter_top.png
technic/textures/technic_mv_solar_array_bottom.png
technic/textures/technic_mv_solar_array_side.png
technic/textures/technic_mv_solar_array_top.png
technic/textures/technicx32/technic_hv_solar_array_bottom.png
technic/textures/technicx32/technic_hv_solar_array_side.png
technic/textures/technicx32/technic_hv_solar_array_top.png
technic/textures/technicx32/technic_hv_transformer.png
technic/textures/technicx32/technic_lv_solar_array_bottom.png
technic/textures/technicx32/technic_lv_solar_array_side.png
technic/textures/technicx32/technic_lv_solar_array_top.png
technic/textures/technicx32/technic_lv_transformer.png
technic/textures/technicx32/technic_mv_solar_array_bottom.png
technic/textures/technicx32/technic_mv_solar_array_side.png
technic/textures/technicx32/technic_mv_solar_array_top.png
technic/tree_tap.lua
@@ -7,7 +7,8 @@
                            local pos=minetest.get_pointed_thing_position(pointed_thing,above)
                            local node=minetest.env:get_node(pos)
                            local node_name=node.name
                            if node_name == "farming_plus:rubber_tree_full" or node_name == "farming:rubber_tree_full" or node_name == "technic:rubber_tree_full" then
                            if node_name == "moretrees:rubber_tree_trunk" then
                                    node.name = "moretrees:rubber_tree_trunk_empty"
                                    user:get_inventory():add_item("main",ItemStack("technic:raw_latex"))
                                    minetest.env:set_node(pos,node)
                                    local item=itemstack:to_table()
@@ -47,3 +48,13 @@
            description = "Rubber Fiber",
            inventory_image = "technic_rubber.png",
    })
minetest.register_abm({
    nodenames = {"moretrees:rubber_tree_trunk_empty"},
    interval = 60,
    chance = 15,
    action = function(pos, node)
        node.name = "moretrees:rubber_tree_trunk"
        minetest.env:set_node(pos, node)
    end
})
technic/wires_hv.lua
New file
@@ -0,0 +1,398 @@
--HV cable node boxes
minetest.register_craft({
    output = 'technic:hv_cable 3',
    recipe ={
        {'technic:rubber','technic:rubber','technic:rubber'},
        {'technic:mv_cable','technic:mv_cable','technic:mv_cable'},
        {'technic:rubber','technic:rubber','technic:rubber'},
        }
})
minetest.register_craftitem("technic:hv_cable", {
    description = "Gigh Voltage Copper Cable",
    stack_max = 99,
})
minetest.register_node("technic:hv_cable", {
    description = "High Voltage Copper Cable",
    tiles = {"technic_hv_cable.png"},
    inventory_image = "technic_hv_cable_wield.png",
    wield_image = "technic_hv_cable_wield.png",
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
    sounds = default.node_sound_wood_defaults(),
    drop = "technic:hv_cable",
    hv_cablelike=1,
    rules_x1=0,
    rules_x2=0,
    rules_y1=0,
    rules_y2=0,
    rules_z1=0,
    rules_z2=0,
    paramtype = "light",
        drawtype = "nodebox",
    selection_box = {
        type = "fixed",
                fixed = {
        { -0.1 , -0.1 , -0.1 , 0.1 ,  0.1 , 0.1  },
        }},
    node_box = {
        type = "fixed",
                fixed = {
        { -0.125 , -0.125 , -0.125 , 0.125 ,  0.125 , 0.125  },
        }},
    on_construct = function(pos)
    meta=minetest.env:get_meta(pos)
    meta:set_float("hv_cablelike",1)
    meta:set_float("x1",0)
    meta:set_float("x2",0)
    meta:set_float("y1",0)
    meta:set_float("y2",0)
    meta:set_float("z1",0)
    meta:set_float("z2",0)
    HV_check_connections (pos)
    end,
    after_dig_node = function (pos, oldnode, oldmetadata, digger)
    HV_check_connections_on_destroy (pos)
    end,
})
str_y1=        { -0.125 , -0.125 , -0.125 , 0.125 , 0.5, 0.125  }    --0 y+
str_x1=        { -0.125 , -0.125 , -0.125 , 0.5, 0.125 , 0.125  }    --0 x+
str_z1=        { -0.125 , -0.125 ,  0.125 ,  0.125 , 0.125 , 0.5 }   --0 z+
str_z2=        { -0.125 , -0.125, -0.5 ,  0.125 ,  0.125 , 0.125  }  --0 z-
str_y2=        { -0.125 , -0.5, -0.125 ,  0.125 ,  0.125 , 0.125  }  --0 y-
str_x2=        { -0.5 , -0.125, -0.125 ,  0.125 ,  0.125 , 0.125  }  --0 x-
local x1,x2,y1,y2,z1,z2
local count=0
for x1 = 0, 1, 1 do    --x-
for x2 = 0, 1, 1 do    --x+
for y1 = 0, 1, 1 do    --y-
for y2 = 0, 1, 1 do    --y-
for z1 = 0, 1, 1 do    --z-
for z2 = 0, 1, 1 do    --z+
temp_x1={} temp_x2={} temp_y1={} temp_y2={} temp_z1={} temp_z2={}
if x1==1 then     temp_x1=str_x1  end
if x2==1 then     temp_x2=str_x2  end
if y1==1 then     temp_y1=str_y1  end
if y2==1 then     temp_y2=str_y2  end
if z1==1 then     temp_z1=str_z1  end
if z2==1 then     temp_z2=str_z2  end
minetest.register_node("technic:hv_cable"..count, {
    description = "Gigh Voltage Copper Cable",
    tiles = {"technic_hv_cable.png"},
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
    sounds = default.node_sound_wood_defaults(),
    drop = "technic:hv_cable",
    rules_x1=0,
    rules_x2=0,
    rules_y1=0,
    rules_y2=0,
    rules_z1=0,
    rules_z2=0,
    cablelike=1,
    paramtype = "light",
        drawtype = "nodebox",
    selection_box = {
        type = "fixed",
           fixed = {
        temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
        }},
    node_box = {
        type = "fixed",
           fixed = {
        temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
        }},
    after_dig_node = function (pos, oldnode, oldmetadata, digger)
    HV_check_connections_on_destroy (pos)
    end,
})
count=count+1 end end end end end end
HV_check_connections = function(pos)
        local pos1={}
        pos1.x=pos.x
        pos1.y=pos.y
        pos1.z=pos.z
        pos1.x=pos1.x+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        x2=1
        x1=minetest.env:get_meta(pos1):get_float("x1")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("x2",x2)
        meta=minetest.env:get_meta(pos)
        x1=1
        x2=minetest.env:get_meta(pos):get_float("x2")
        y1=minetest.env:get_meta(pos):get_float("y1")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z1=minetest.env:get_meta(pos):get_float("z1")
        z2=minetest.env:get_meta(pos):get_float("z2")
        meta:set_float("x1",x1)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        pos1.x=pos1.x-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        x1=1
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("x1",x1)
        meta=minetest.env:get_meta(pos)
        x2=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        y1=minetest.env:get_meta(pos):get_float("y1")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z1=minetest.env:get_meta(pos):get_float("z1")
        z2=minetest.env:get_meta(pos):get_float("z2")
        meta:set_float("x2",x2)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        pos1.x=pos1.x+1
        pos1.y=pos1.y+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        y2=1
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("y2",y2)
        meta=minetest.env:get_meta(pos)
        y1=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        x2=minetest.env:get_meta(pos):get_float("x2")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z1=minetest.env:get_meta(pos):get_float("z1")
        z2=minetest.env:get_meta(pos):get_float("z2")
        meta:set_float("y1",y1)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        if minetest.env:get_meta(pos1):get_float("technic_hv_power_machine")==1 then
        y1=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        x2=minetest.env:get_meta(pos):get_float("x2")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z1=minetest.env:get_meta(pos):get_float("z1")
        z2=minetest.env:get_meta(pos):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos)
        meta:set_float("y1",y1)
        end
        pos1.y=pos1.y-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        y1=1
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("y1",y1)
        meta=minetest.env:get_meta(pos)
        y2=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        x2=minetest.env:get_meta(pos):get_float("x2")
        y1=minetest.env:get_meta(pos):get_float("y1")
        z1=minetest.env:get_meta(pos):get_float("z1")
        z2=minetest.env:get_meta(pos):get_float("z2")
        meta:set_float("y2",y2)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        pos1.y=pos1.y+1
        pos1.z=pos1.z+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        z2=1
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("z2",z2)
        meta=minetest.env:get_meta(pos)
        z1=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        x2=minetest.env:get_meta(pos):get_float("x2")
        y1=minetest.env:get_meta(pos):get_float("y1")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z2=minetest.env:get_meta(pos):get_float("z2")
        meta:set_float("z1",z1)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        pos1.z=pos1.z-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        z1=1
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos1,"technic:hv_cable"..rule)
        meta=minetest.env:get_meta(pos1)
        meta:set_float("z1",z1)
        meta=minetest.env:get_meta(pos)
        z2=1
        x1=minetest.env:get_meta(pos):get_float("x1")
        x2=minetest.env:get_meta(pos):get_float("x2")
        y1=minetest.env:get_meta(pos):get_float("y1")
        y2=minetest.env:get_meta(pos):get_float("y2")
        z1=minetest.env:get_meta(pos):get_float("z1")
        meta:set_float("z2",z2)
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        hacky_swap_node(pos,"technic:hv_cable"..rule)
        end
        pos1.z=pos1.z+1
end
HV_check_connections_on_destroy = function(pos)
        local pos1={}
        pos1.x=pos.x
        pos1.y=pos.y
        pos1.z=pos.z
        pos1.x=pos1.x+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        x2=0
        x1=minetest.env:get_meta(pos1):get_float("x1")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("x2",x2)
        end
        pos1.x=pos1.x-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        x1=0
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("x1",x1)
        end
        pos1.x=pos1.x+1
        pos1.y=pos1.y+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        y2=0
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("y2",y2)
        end
        pos1.y=pos1.y-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        y1=0
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("y1",y1)
        end
        pos1.y=pos1.y+1
        pos1.z=pos1.z+1
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        z2=0
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z1=minetest.env:get_meta(pos1):get_float("z1")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("z2",z2)
        end
        pos1.z=pos1.z-2
        if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
        z1=0
        x1=minetest.env:get_meta(pos1):get_float("x1")
        x2=minetest.env:get_meta(pos1):get_float("x2")
        y1=minetest.env:get_meta(pos1):get_float("y1")
        y2=minetest.env:get_meta(pos1):get_float("y2")
        z2=minetest.env:get_meta(pos1):get_float("z2")
        rule=make_rule_number(x1,x2,y1,y2,z1,z2)
        if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
        if rule>0  then    hacky_swap_node(pos1,"technic:hv_cable"..rule) end
        meta=minetest.env:get_meta(pos1)
        meta:set_float("z1",z1)
        end
        pos1.y=pos1.y+1
end
unified_inventory/api.lua
@@ -10,6 +10,8 @@
unified_inventory.activefilter = {}
unified_inventory.alternate = {}
unified_inventory.current_item = {}
unified_inventory.crafts_table ={}
unified_inventory.crafts_table_count=0
-- default inventory page
unified_inventory.default = "craft"
@@ -26,8 +28,18 @@
        if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
                and def.description and def.description ~= "" then
            table.insert(unified_inventory.items_list, name)
            local recipes=minetest.get_all_craft_recipes(name)
            if unified_inventory.crafts_table[name]==nil then
                unified_inventory.crafts_table[name] = {}
            end
            if recipes then
                for i=1,#recipes,1 do
                    table.insert(unified_inventory.crafts_table[name],recipes[i])
                end
            end
        end
    end
    --print(dump(unified_inventory.crafts_table))
    table.sort(unified_inventory.items_list)
    unified_inventory.items_list_size = #unified_inventory.items_list
    print ("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
@@ -37,7 +49,6 @@
minetest.register_on_joinplayer(function(player)
    local player_name = player:get_player_name()
    unified_inventory.players[player_name]={}
    unified_inventory.players[player_name]["sound_volume"]=minetest.setting_get("sound_volume")*10
    unified_inventory.current_index[player_name] = 1
    unified_inventory.filtered_items_list[player_name] = {}
    unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list
@@ -47,8 +58,8 @@
    unified_inventory.alternate[player_name] = 1
    unified_inventory.current_item[player_name] =nil
    unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default))
--crafting guide inventories
--crafting guide inventories
local inv = minetest.create_detached_inventory(player:get_player_name().."craftrecipe",{
    allow_put = function(inv, listname, index, stack, player)
        return 0
@@ -64,8 +75,8 @@
            return 0
        end,
    })
    inv:set_size("output", 1)
    inv:set_size("build", 3*3)
inv:set_size("output", 1)
inv:set_size("build", 3*3)
-- refill slot
unified_inventory.refill = minetest.create_detached_inventory(player_name.."refill", {
@@ -82,7 +93,6 @@
    end,
})
unified_inventory.refill:set_size("main", 1)
end)
-- trash slot
unified_inventory.trash = minetest.create_detached_inventory("trash", {
@@ -100,24 +110,18 @@
    end,
})
unified_inventory.trash:set_size("main", 1)
end)
-- set_inventory_formspec
unified_inventory.set_inventory_formspec = function(player,formspec)
    if player then
        if minetest.setting_getbool("creative_mode") then
            -- if creative mode is on then wait a bit
            minetest.after(0.01,function()
            player:set_inventory_formspec(formspec)
            end)
        else
        player:set_inventory_formspec(formspec)
        end
    end
end
-- get_formspec
unified_inventory.get_formspec = function(player,page)
    if player==nil then    return "" end
    if player==nil then return "" end
    local player_name = player:get_player_name()
    unified_inventory.current_page[player_name]=page
    
@@ -206,9 +210,9 @@
            formspec = formspec.."label[2,0;"..item_name.."]"    
            local alternates = 0
            local alternate = unified_inventory.alternate[player_name]
            local crafts = crafts_table[item_name]
            local crafts = unified_inventory.crafts_table[item_name]
            if crafts ~= nil then
            if crafts ~= nil and #crafts>0 then
                alternates = #crafts
                local craft = crafts[alternate]
                local method = "Crafting"
@@ -440,7 +444,7 @@
        if item_name then
            local alternates = 0
            local alternate=unified_inventory.alternate[player_name]
            local crafts = crafts_table[item_name]
            local crafts = unified_inventory.crafts_table[item_name]
            if crafts ~= nil then
                alternates = #crafts
            end
@@ -537,134 +541,63 @@
-- update_recipe
unified_inventory.update_recipe = function(player, stack_name, alternate)
    --print("Lookup:"..stack_name)
    local inv = minetest.get_inventory({type="detached", name=player:get_player_name().."craftrecipe"})    
    for i=0,inv:get_size("build"),1 do
        inv:set_stack("build", i, nil)
    end
    inv:set_stack("cook", 1, nil)
    inv:set_stack("fuel", 1, nil)
    inv:set_stack("output", 1, stack_name)
    local def
    inv:set_stack("output", 1, nil)
    alternate = tonumber(alternate) or 1
    local crafts = crafts_table[stack_name]
    if crafts == nil then
        --minetest.chat_send_player(player:get_player_name(), "no recipe available for "..stack_name)
        return
    end
    local crafts = unified_inventory.crafts_table[stack_name]
    print(dump(crafts))
    local next=next
    if next(crafts) == nil then return end -- no craft recipes
    if alternate < 1 or alternate > #crafts then
        alternate = 1
    end
    local craft = crafts[alternate]
    --print (dump(craft))
    --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack_name..": "..dump(craft))
    local itemstack = ItemStack(craft.output)
    inv:set_stack("output", 1, itemstack)
    inv:set_stack("output", 1, craft.output)
    local items=craft.items
    -- cook, fuel, grinding recipes
    if craft.type == "cooking" or craft.type == "fuel" or craft.type == "grinding" then
        def=unified_inventory.find_item_def(craft.recipe)
        def=unified_inventory.find_item_def(craft["items"][1])
        if def then
            inv:set_stack("build", 1, def)
        end
        return 
    end
    -- build (shaped or shapeless)
    if craft.recipe[1] then
        def=unified_inventory.find_item_def(craft.recipe[1])
        if def then
            inv:set_stack("build", 1, def)
        else
            def=unified_inventory.find_item_def(craft.recipe[1][1])
            if def then
                inv:set_stack("build", 1, def)
            end
            def=unified_inventory.find_item_def(craft.recipe[1][2])
            if def then
                inv:set_stack("build", 2, def)
            end
            def=unified_inventory.find_item_def(craft.recipe[1][3])
            if def then
                inv:set_stack("build", 3, def)
            end
    if craft.width==0 then
    local build_table={1,2,3}
    for i=1,3,1 do
        if craft.items[i] then
            def=unified_inventory.find_item_def(craft.items[i])
            if def then inv:set_stack("build", build_table[i], def) end
        end
    end
    if craft.recipe[2] then
        def=unified_inventory.find_item_def(craft.recipe[2])
        if def then
            inv:set_stack("build", 2, def)
        else
            def=unified_inventory.find_item_def(craft.recipe[2][1])
            if def then
                inv:set_stack("build", 4, def)
    end
    if craft.width==1 then
    local build_table={1,4,7}
    for i=1,3,1 do
        if craft.items[i] then
            def=unified_inventory.find_item_def(craft.items[i])
            if def then inv:set_stack("build", build_table[i], def) end
        end
    end
    end
    if craft.width==2 then
    local build_table={1,2,4,5,7,8}
    for i=1,6,1 do
        if craft.items[i] then
            def=unified_inventory.find_item_def(craft.items[i])
            if def then inv:set_stack("build", build_table[i], def) end
        end
    end
    end
    if craft.width==3 then
        for i=1,9,1 do
            if craft.items[i] then
                def=unified_inventory.find_item_def(craft.items[i])
                if def then inv:set_stack("build", i, def) end
            end
            def=unified_inventory.find_item_def(craft.recipe[2][2])
            if def then
                inv:set_stack("build", 5, def)
            end
            def=unified_inventory.find_item_def(craft.recipe[2][3])
            if def then
                inv:set_stack("build", 6, def)
            end
        end
    end
    if craft.recipe[3] then
        def=unified_inventory.find_item_def(craft.recipe[3])
        if def then
            inv:set_stack("build", 3, def)
        else
            def=unified_inventory.find_item_def(craft.recipe[3][1])
            if def then
                inv:set_stack("build", 7, def)
            end
            def=unified_inventory.find_item_def(craft.recipe[3][2])
            if def then
                inv:set_stack("build", 8, def)
            end
            def=unified_inventory.find_item_def(craft.recipe[3][3])
            if def then
                inv:set_stack("build", 9, def)
            end
        end
    end
    if craft.recipe[4] then
        def=unified_inventory.find_item_def(craft.recipe[4])
        if def then
            inv:set_stack("build", 4, def)
        end
    end
    if craft.recipe[5] then
        def=unified_inventory.find_item_def(craft.recipe[5])
        if def then
            inv:set_stack("build", 5, def)
        end
    end
    if craft.recipe[6] then
        def=unified_inventory.find_item_def(craft.recipe[6])
        if def then
            inv:set_stack("build", 6, def)
        end
    end
    if craft.recipe[7] then
        def=unified_inventory.find_item_def(craft.recipe[7])
        if def then
            inv:set_stack("build", 7, def)
        end
    end
    if craft.recipe[8] then
        def=unified_inventory.find_item_def(craft.recipe[8])
        if def then
            inv:set_stack("build", 8, def)
        end
    end
    if craft.recipe[9] then
        def=unified_inventory.find_item_def(craft.recipe[9])
        if def then
            inv:set_stack("build", 9, def)
        end
    end
end
@@ -674,14 +607,39 @@
    if string.find(def1, "group:") then
        def1=string.gsub(def1, "group:", "")
        def1=string.gsub(def1, '\"', "")
        for name,def in pairs(minetest.registered_items) do
                if def.groups[def1] == 1 and def.groups.not_in_creative_inventory ~= 1 then
                    return def
                end
        end
        local items=unified_inventory.items_in_group(def1)
        return items[1]
    else
    return def1
        return def1
    end
end
return nil
end
unified_inventory.items_in_group = function(group)
    local items = {}
    for name, item in pairs(minetest.registered_items) do
        for _, g in ipairs(group:split(',')) do
            if item.groups[g] then
                table.insert(items,name)
            end
        end
    end
    return items
end
-- register_craft
unified_inventory.register_craft = function(options)
    if  options.output == nil then
        return
    end
    local itemstack = ItemStack(options.output)
    if itemstack:is_empty() then
        return
    end
    if unified_inventory.crafts_table[itemstack:get_name()]==nil then
        unified_inventory.crafts_table[itemstack:get_name()] = {}
    end
    table.insert(unified_inventory.crafts_table[itemstack:get_name()],options)
    --crafts_table_count=crafts_table_count+1
end
unified_inventory/depends.txt
@@ -1,2 +1 @@
aaa_recipeshook
creative
unified_inventory/textures/ui_furnace_inventory.png
unified_inventory/textures/ui_main_inventory.png
unified_inventory/textures/ui_wooden_chest_inventory.png