kpoppel
2013-06-19 37d9d94c44cbadc7e6550efc22612c7c605a9040
Added case study of radiated power through inductive coils.
18 files added
1 files modified
906 ■■■■■ changed files
technic/init.lua 4 ●●●● patch | view | raw | blame | history
technic/lighting.lua 594 ●●●●● patch | view | raw | blame | history
technic/power_radiator.lua 308 ●●●●● patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_white_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_white_tb.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thick_white_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thin_white_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_white_tb.png patch | view | raw | blame | history
technic/textures/technic_homedecor_glowlight_yellow_tb.png patch | view | raw | blame | history
technic/init.lua
@@ -40,6 +40,10 @@
dofile(modpath.."/electric_furnace_mv.lua")
dofile(modpath.."/alloy_furnace_mv.lua")
dofile(modpath.."/forcefield.lua")
-- These two are a concept study: Supplying appliances with inductive coupled power:
-- lighting and associated textures is taken directly from VanessaE's homedecor and made electric.
dofile(modpath.."/power_radiator.lua")
dofile(modpath.."/lighting.lua")
--HV machines
dofile(modpath.."/wires_hv.lua")
technic/lighting.lua
New file
@@ -0,0 +1,594 @@
-- NOTE: The code is takes directly from VanessaE's homedecor mod.
-- I just made it the lights into indictive appliances for this mod.
-- This file supplies electric powered glowlights
-- Boilerplate to support localized strings if intllib mod is installed.
local S
if (minetest.get_modpath("intllib")) then
    dofile(minetest.get_modpath("intllib").."/intllib.lua")
    S = intllib.Getter(minetest.get_current_modname())
else
    S = function ( s ) return s end
end
function technic_homedecor_node_is_owned(pos, placer)
        local ownername = false
        if type(IsPlayerNodeOwner) == "function" then                                   -- node_ownership mod
                if HasOwner(pos, placer) then                                           -- returns true if the node is owned
                        if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
                                if type(getLastOwner) == "function" then                -- ...is an old version
                                        ownername = getLastOwner(pos)
                                elseif type(GetNodeOwnerName) == "function" then        -- ...is a recent version
                                        ownername = GetNodeOwnerName(pos)
                                else
                                        ownername = S("someone")
                                end
                        end
                end
        elseif type(isprotect)=="function" then                                         -- glomie's protection mod
                if not isprotect(5, pos, placer) then
                        ownername = S("someone")
                end
        elseif type(protector)=="table" and type(protector.can_dig)=="function" then                                    -- Zeg9's protection mod
                if not protector.can_dig(5, pos, placer) then
                        ownername = S("someone")
                end
        end
        if ownername ~= false then
                minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
                return true
        else
                return false
        end
end
local dirs1 = { 20, 23, 22, 21 }
local dirs2 = { 9, 18, 7, 12 }
function technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
    if not technic_homedecor_node_is_owned(pointed_thing.under, placer)
       and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then
        local node = minetest.env:get_node(pointed_thing.under)
        if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
            local above = pointed_thing.above
            local under = pointed_thing.under
            local pitch = placer:get_look_pitch()
            local pname = minetest.env:get_node(under).name
            local node = minetest.env:get_node(above)
            local fdir = minetest.dir_to_facedir(placer:get_look_dir())
            local wield_name = itemstack:get_name()
            if not minetest.registered_nodes[pname]
                or not minetest.registered_nodes[pname].on_rightclick then
                local iswall = (above.x ~= under.x) or (above.z ~= under.z)
                local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
                local pos1 = above
                if minetest.registered_nodes[pname]["buildable_to"] then
                    pos1 = under
                    iswall = false
                end
                if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end
                if iswall then
                    minetest.env:add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant
                elseif isceiling then
                    minetest.env:add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant
                else
                    minetest.env:add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
                end
                if not homedecor_expect_infinite_stacks then
                    itemstack:take_item()
                    return itemstack
                end
            end
        else
            minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
        end
    end
end
-- Yellow -- Half node
minetest.register_node('technic:homedecor_glowlight_half_yellow', {
    description = S("Yellow Glowlight (thick)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              print("Hello")
              technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
              print("Hello2")
               end,
    on_punch = function(pos, node, puncher)
              print("Punch")
              technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active")
              print("Punch2")
           end
})
minetest.register_node('technic:homedecor_glowlight_half_yellow_active', {
    description = S("Yellow Glowlight (thick)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png',
        'technic_homedecor_glowlight_thick_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_half_yellow",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow")
           end
})
-- Yellow -- Quarter node
minetest.register_node('technic:homedecor_glowlight_quarter_yellow', {
    description = S("Yellow Glowlight (thin)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active")
           end
})
minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', {
    description = S("Yellow Glowlight (thin)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_yellow_tb.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png',
        'technic_homedecor_glowlight_thin_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX-1,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_quarter_yellow",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow")
           end
})
-- White -- half node
minetest.register_node('technic:homedecor_glowlight_half_white', {
    description = S("White Glowlight (thick)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "White Glowlight (thick)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active")
           end
})
minetest.register_node('technic:homedecor_glowlight_half_white_active', {
    description = S("White Glowlight (thick)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png',
        'technic_homedecor_glowlight_thick_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_half_white",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "White Glowlight (thick)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white")
           end
})
-- White -- Quarter node
minetest.register_node('technic:homedecor_glowlight_quarter_white', {
    description = S("White Glowlight (thin)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "White Glowlight (thin)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active")
           end
})
minetest.register_node('technic:homedecor_glowlight_quarter_white_active', {
    description = S("White Glowlight (thin)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_white_tb.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png',
        'technic_homedecor_glowlight_thin_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX-1,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_quarter_white",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 100, "White Glowlight (thin)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white")
           end
})
-- Glowlight "cubes" - yellow
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', {
    description = S("Yellow Glowlight (small cube)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_cube_yellow_tb.png',
        'technic_homedecor_glowlight_cube_yellow_tb.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active")
           end
})
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', {
    description = S("Yellow Glowlight (small cube)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_cube_yellow_tb.png',
        'technic_homedecor_glowlight_cube_yellow_tb.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png',
        'technic_homedecor_glowlight_cube_yellow_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX-1,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_cube_yellow",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow")
           end
})
-- Glowlight "cubes" - white
minetest.register_node('technic:homedecor_glowlight_small_cube_white', {
    description = S("White Glowlight (small cube)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_cube_white_tb.png',
        'technic_homedecor_glowlight_cube_white_tb.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3 },
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active")
           end
})
minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', {
    description = S("White Glowlight (small cube)"),
    drawtype = "nodebox",
    tiles = {
        'technic_homedecor_glowlight_cube_white_tb.png',
        'technic_homedecor_glowlight_cube_white_tb.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png',
        'technic_homedecor_glowlight_cube_white_sides.png'
    },
        selection_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
        node_box = {
                type = "fixed",
                fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
        },
    sunlight_propagates = false,
    paramtype = "light",
    paramtype2 = "facedir",
    walkable = true,
    light_source = LIGHT_MAX-1,
    sounds = default.node_sound_wood_defaults(),
    groups = { snappy = 3, not_in_creative_inventory=1},
    drop="technic:homedecor_glowlight_cube_white",
    on_place = function(itemstack, placer, pointed_thing)
        technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
        return itemstack
         end,
    on_construct = function(pos)
              technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)")
               end,
    on_punch = function(pos, node, puncher)
              technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white")
           end
})
register_inductive_machine("technic:homedecor_glowlight_half_yellow")
register_inductive_machine("technic:homedecor_glowlight_half_white")
register_inductive_machine("technic:homedecor_glowlight_quarter_yellow")
register_inductive_machine("technic:homedecor_glowlight_quarter_white")
register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow")
register_inductive_machine("technic:homedecor_glowlight_small_cube_white")
technic/power_radiator.lua
New file
@@ -0,0 +1,308 @@
-- The power radiator fuctions like an inductive charger
-- only better in the game setting.
-- The purpose is to allow small appliances to receive power
-- without the overhead of the wiring needed for larger machines.
--
-- The power radiator will consume power corresponding to the
-- sum(power rating of the attached appliances)/0.6
-- Using inductive power transfer is very inefficient so this is
-- set to the factor 0.6.
-- API for inductive powered nodes:
-- Use the functions below to set the corresponding callbacks
-- Also two nodes are needed: The inactive and the active one. The active must be called <name>_active .
-- Register a new appliance using this function
technic_inductive_nodes = {}
registered_inductive_count=0
register_inductive_machine = function(name)
                registered_inductive_count=registered_inductive_count+1
                technic_inductive_nodes[registered_inductive_count]=name
                registered_inductive_count=registered_inductive_count+1
                technic_inductive_nodes[registered_inductive_count]=name.."_active"
                 end
-- Appliances:
--  has_supply: pos of supply node if the appliance has a power radiator near with sufficient power for the demand else ""
--  EU_demand: The power demand of the device.
--  EU_charge: Actual use. set to EU_demand if active==1
--  active: set to 1 if the device is on
technic_inductive_on_construct = function(pos, eu_demand, infotext)
                    local meta = minetest.env:get_meta(pos)
                    meta:set_string("infotext", infotext)
                    meta:set_int("technic_inductive_power_machine", 1)
                    meta:set_int("EU_demand",eu_demand)     -- The power demand of this appliance
                    meta:set_int("EU_charge",0)       -- The actual power draw of this appliance
                    meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators.
                    meta:set_int("active", 0)    -- If the appliance can be turned on and off by using it use this.
                 end
technic_inductive_on_punch_off = function(pos, eu_charge, swapnode)
            local meta = minetest.env:get_meta(pos)
            if meta:get_string("has_supply") ~= "" then
               hacky_swap_node(pos, swapnode)
               meta:set_int("active", 1)
               meta:set_int("EU_charge",eu_charge)
               --print("-----------")
               --print("Turn on:")
               --print("EUcha:"..meta:get_int("EU_charge"))
               --print("has_supply:"..meta:get_string("has_supply"))
               --print("<----------->")
            end
         end
technic_inductive_on_punch_on = function(pos, eu_charge, swapnode)
            local meta = minetest.env:get_meta(pos)
            hacky_swap_node(pos, swapnode)
            meta:set_int("active", 0)
            meta:set_int("EU_charge",eu_charge)
            --print("-----------")
            --print("Turn off:")
            --print("EUcha:"..meta:get_int("EU_charge"))
            --print("has_supply:"..meta:get_string("has_supply"))
            --print("<---------->")
         end
--minetest.register_node(
--   "technic:test_induc", {
--      description = "Test radiator node",
--      drawtype = "nodebox",
--      tiles = {
--     'homedecor_glowlight_yellow_tb.png',
--     'homedecor_glowlight_yellow_tb.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png'
--      },
--
----      tiles  = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png",
----        "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png", "technic_hv_down_converter_top.png"},
--      selection_box = {
--     type = "fixed",
--     fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
--      },
--      node_box = {
--     type = "fixed",
--     fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
--      },
--      sunlight_propagates = false,
--      paramtype = "light",
--      paramtype2 = "facedir",
--      walkable = true,
--      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
--      on_place = function(itemstack, placer, pointed_thing)
--            homedecor_rotate_and_place(itemstack, placer, pointed_thing)
--            return itemstack
--         end,
--      on_construct = function(pos)
--            local meta = minetest.env:get_meta(pos)
--            meta:set_string("infotext", "Power Radiator Appliance")
--            meta:set_int("technic_inductive_power_machine", 1)
--            meta:set_int("EU_demand",200)     -- The power demand of this appliance
--            meta:set_int("EU_charge",0)       -- The actual power draw of this appliance
--            meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators.
--            meta:set_int("active", 0)    -- If the appliance can be turned on and off by using it use this.
--             end,
--      on_punch = function(pos,node,puncher)
--            local meta = minetest.env:get_meta(pos)
--            if meta:get_string("has_supply") ~= "" then
--               hacky_swap_node(pos, "technic:test_induc_active")
--               meta:set_int("active", 1)
--               meta:set_int("EU_charge",200)
--               print("-----------")
--               print("Turn on:")
--               print("EUcha:"..meta:get_int("EU_charge"))
--               print("<----------->")
--            end
--         end,
--   })
--
--minetest.register_node(
--   "technic:test_induc_active", {
--      description = "Test radiator node",
--      drawtype = "nodebox",
--      tiles = {
--     'homedecor_glowlight_yellow_tb.png',
--     'homedecor_glowlight_yellow_tb.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png',
--     'homedecor_glowlight_thick_yellow_sides.png'
--      },
--
----      tiles  = {"technic_hv_down_converter_side.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", "technic_hv_down_converter_side.png"},
--      selection_box = {
--     type = "fixed",
--     fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
--      },
--      node_box = {
--     type = "fixed",
--     fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
--      },
--      sunlight_propagates = false,
--      paramtype = "light",
--      paramtype2 = "facedir",
--      walkable = true,
--      light_source=14,
--      groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
--      drop="technic:test_induc",
--      on_place = function(itemstack, placer, pointed_thing)
--            homedecor_rotate_and_place(itemstack, placer, pointed_thing)
--            return itemstack
--         end,
--      on_construct = function(pos)
--            local meta = minetest.env:get_meta(pos)
--            meta:set_string("infotext", "Power Radiator Appliance Active")
--            meta:set_int("technic_inductive_power_machine", 1)
--            meta:set_int("EU_demand",200)     -- The power demand of this appliance
--            meta:set_int("EU_charge",0)       -- The actual power draw of this appliance
--            meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators.
--             end,
--      on_punch = function(pos,node,puncher)
--            local meta = minetest.env:get_meta(pos)
--            hacky_swap_node(pos, "technic:test_induc")
--            meta:set_int("active", 0)
--            meta:set_int("EU_charge",0)
--            print("-----------")
--            print("Turn off:")
--            print("EUcha:"..meta:get_int("EU_charge"))
--            print("<---------->")
--         end,
--   })
local shutdown_inductive_appliances = function(pos)
                     -- The supply radius
                     local rad = 4
                     -- If the radiator is removed. turn off all appliances in region
                     -- If another radiator is near it will turn on the appliances again
                     local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes)
                     for _,pos1 in ipairs(positions) do
                        local meta1 = minetest.env:get_meta(pos1)
                        -- If the appliance is belonging to this node
                        if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
                           local nodename = minetest.env:get_node(pos1).name
                           -- Swap the node and make sure it is off and unpowered
                           if string.sub(nodename, -7) == "_active" then
                          hacky_swap_node(pos1, string.sub(nodename, 1, -8))
                          meta1:set_int("active", 0)
                          meta1:set_int("EU_charge", 0)
                           end
                           meta1:set_string("has_supply", "")
                       end
                    end
                     end
minetest.register_node(
   "technic:power_radiator", {
      description = "Power Radiator",
      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_int("technic_mv_power_machine", 1)  -- MV machine
            meta:set_int("internal_EU_buffer",0)         -- internal buffer value
            meta:set_int("internal_EU_buffer_size",1000) -- Size of buffer
            meta:set_int("connected_EU_demand",0)        -- Potential demand of connected appliances
            meta:set_string("infotext", "Power Radiator")
--            meta:set_int("active", 0)
             end,
      on_dig = function(pos, node, digger)
          shutdown_inductive_appliances(pos)
          return minetest.node_dig(pos, node, digger)
           end,
   })
minetest.register_craft(
   {
      output = 'technic:power_radiator 1',
      recipe = {
     {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
     {'technic:copper_coil',           'technic:mv_transformer',        'technic:copper_coil'},
     {'technic:rubber',                'technic:mv_cable',              'technic:rubber'},
      }
   })
minetest.register_abm(
   {nodenames = {"technic:power_radiator"},
    interval   = 1,
    chance     = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta             = minetest.env:get_meta(pos)
        local my_supply        = meta:get_int("internal_EU_buffer")
        -- The maximum EU sourcing a single radiator can provide.
        local max_charge = 1000 -- == the max EU demand of the radiator
        local connected_EU_demand = meta:get_int("connected_EU_demand")
        --print("--------------------")
        --print("My Supply:"..my_supply)
        --print("Connected Demand:"..connected_EU_demand)
        if my_supply > 0 then
           -- Efficiency factor
           local eff_factor = 0.6
           -- The supply radius
           local rad = 4
           local meta1            = nil
           local pos1             = {}
           local used_charge      = 0
           -- Index all nodes within supply range
           local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic_inductive_nodes)
           for _,pos1 in ipairs(positions) do
              local meta1 = minetest.env:get_meta(pos1)
              -- If not supplied see if this node can handle it.
              if meta1:get_string("has_supply") == "" then
             -- if demand surpasses the capacity of this node, don't bother adding it.
             local eu_demand = meta1:get_int("EU_demand")/eff_factor
             if connected_EU_demand+eu_demand <= max_charge and connected_EU_demand+eu_demand <= my_supply then
                -- We can power the appliance. Register, and spend power if it is on.
                connected_EU_demand = connected_EU_demand+eu_demand
                meta1:set_string("has_supply", pos.x..pos.y..pos.z)
                used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor)
             end
              elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
             -- The appliance has power from this node. Spend power if it is on.
             used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor)
              end
           end
           --If demand surpasses actual supply turn off everything - we are out of power
           if used_charge>my_supply then
              meta:set_string("infotext", "Power Radiator is overloaded ("..math.floor(used_charge/my_supply*100).."% of available power)");
--              meta:set_int("active",1) -- used for setting textures someday maybe
              shutdown_inductive_appliances(pos)
              connected_EU_demand = 0
           else
              meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/my_supply*100).."% of available power)");
              meta:set_int("internal_EU_buffer",my_supply-used_charge)
--              meta:set_int("active",1) -- used for setting textures someday maybe
           end
        else
           meta:set_string("infotext", "Power Radiator is unpowered");
--           meta:set_int("active",0) -- used for setting textures someday maybe
        end
        -- Save state
        meta:set_int("connected_EU_demand",connected_EU_demand)
        return
         end,
 })
register_MV_machine ("technic:power_radiator","RE")
technic/textures/technic_homedecor_glowlight_cube_white_sides.png
technic/textures/technic_homedecor_glowlight_cube_white_sides_ceiling.png
technic/textures/technic_homedecor_glowlight_cube_white_tb.png
technic/textures/technic_homedecor_glowlight_cube_yellow_sides.png
technic/textures/technic_homedecor_glowlight_cube_yellow_sides_ceiling.png
technic/textures/technic_homedecor_glowlight_cube_yellow_tb.png
technic/textures/technic_homedecor_glowlight_thick_white_sides.png
technic/textures/technic_homedecor_glowlight_thick_white_wall_sides.png
technic/textures/technic_homedecor_glowlight_thick_yellow_sides.png
technic/textures/technic_homedecor_glowlight_thick_yellow_wall_sides.png
technic/textures/technic_homedecor_glowlight_thin_white_sides.png
technic/textures/technic_homedecor_glowlight_thin_white_wall_sides.png
technic/textures/technic_homedecor_glowlight_thin_yellow_sides.png
technic/textures/technic_homedecor_glowlight_thin_yellow_wall_sides.png
technic/textures/technic_homedecor_glowlight_white_tb.png
technic/textures/technic_homedecor_glowlight_yellow_tb.png