ShadowNinja
2013-11-27 0809dd747e3a5eb3d43c9a8d027e3a98c225e16d
Externalize common functions and protect inventories
17 files modified
460 ■■■■■ changed files
technic/locale/es.txt 1 ●●●● patch | view | raw | blame | history
technic/locale/it.txt 1 ●●●● patch | view | raw | blame | history
technic/locale/template.txt 2 ●●● patch | view | raw | blame | history
technic/machines/HV/nuclear_reactor.lua 30 ●●●● patch | view | raw | blame | history
technic/machines/LV/cnc.lua 29 ●●●● patch | view | raw | blame | history
technic/machines/LV/coal_alloy_furnace.lua 35 ●●●●● patch | view | raw | blame | history
technic/machines/LV/compressor.lua 30 ●●●● patch | view | raw | blame | history
technic/machines/LV/extractor.lua 30 ●●●● patch | view | raw | blame | history
technic/machines/MV/tool_workshop.lua 13 ●●●● patch | view | raw | blame | history
technic/machines/other/constructor.lua 29 ●●●● patch | view | raw | blame | history
technic/machines/other/injector.lua 26 ●●●● patch | view | raw | blame | history
technic/machines/register/alloy_furnace.lua 50 ●●●● patch | view | raw | blame | history
technic/machines/register/battery_box.lua 15 ●●●● patch | view | raw | blame | history
technic/machines/register/common.lua 38 ●●●●● patch | view | raw | blame | history
technic/machines/register/electric_furnace.lua 50 ●●●● patch | view | raw | blame | history
technic/machines/register/generator.lua 31 ●●●● patch | view | raw | blame | history
technic/machines/register/grinder.lua 50 ●●●● patch | view | raw | blame | history
technic/locale/es.txt
@@ -33,6 +33,7 @@
## Machine misc
Machine cannot be removed because it is not empty = La maquina no puede removerse porque no esta vacia
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
%s Active = %s Activo
%s Idle = %s Quieto
technic/locale/it.txt
@@ -29,6 +29,7 @@
## Machine misc
Machine cannot be removed because it is not empty = La macchina non può essere rimossa perchè non è vuota
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
%s Active = %s Attivo
%s Disabled = %s Disabilitato
technic/locale/template.txt
@@ -32,6 +32,7 @@
## Machine misc
Machine cannot be removed because it is not empty =
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
%s Active =
%s Disabled =
@@ -158,5 +159,4 @@
Single node. =
Sonic Screwdriver =
Tree Tap =
technic/machines/HV/nuclear_reactor.lua
@@ -75,17 +75,10 @@
        local inv = meta:get_inventory()
        inv:set_size("src", 6)
    end,    
    can_dig = function(pos, player)
        local meta = minetest.get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("src") then
            minetest.chat_send_player(player:get_player_name(),
                S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:hv_nuclear_reactor_core_active", {
@@ -103,17 +96,10 @@
        type = "fixed",
        fixed = nodebox
    },
    can_dig = function(pos, player)
        local meta = minetest.get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("src") then
            minetest.chat_send_player(player:get_player_name(),
                S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
local check_reactor_structure = function(pos)
technic/machines/LV/cnc.lua
@@ -150,17 +150,10 @@
        inv:set_size("src", 1)
        inv:set_size("dst", 4)
    end,
    can_dig = function(pos,player)
        local meta = minetest.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(),
                S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
    on_receive_fields = form_handler,
})
@@ -172,16 +165,10 @@
    paramtype2 = "facedir",
    groups = {cracky=2, not_in_creative_inventory=1},
    legacy_facedir_simple = true,
    can_dig = function(pos,player)
        local meta = minetest.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(),
                S("Machine cannot be removed because it is not empty"))
            return false
        end
        return true
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
    on_receive_fields = form_handler,
})
technic/machines/LV/coal_alloy_furnace.lua
@@ -14,8 +14,9 @@
minetest.register_node("technic:coal_alloy_furnace", {
    description = S("Coal Alloy Furnace"),
    tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
        "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"},
    tiles = {"technic_coal_alloy_furnace_top.png",  "technic_coal_alloy_furnace_bottom.png",
             "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png",
             "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"},
    paramtype2 = "facedir",
    groups = {cracky=2},
    legacy_facedir_simple = true,
@@ -30,35 +31,27 @@
        inv:set_size("src2", 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("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then
            return false
            end
        return true
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:coal_alloy_furnace_active", {
    description = "Alloy Furnace",
    tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
             "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"},
    tiles = {"technic_coal_alloy_furnace_top.png",  "technic_coal_alloy_furnace_bottom.png",
             "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png",
             "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"},
    paramtype2 = "facedir",
    light_source = 8,
    drop = "technic:coal_alloy_furnace",
    groups = {cracky=2, not_in_creative_inventory=1},
    legacy_facedir_simple = true,
    sounds = default.node_sound_stone_defaults(),
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not (inv:is_empty("fuel") or inv:is_empty("dst") or
            inv:is_empty("src") or inv:is_empty("src2")) then
            return false
        end
        return true
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_abm({
technic/machines/LV/compressor.lua
@@ -68,17 +68,10 @@
        inv:set_size("src", 1)
        inv:set_size("dst", 4)
    end,
    can_dig = function(pos,player)
        local meta = minetest.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(),
                    S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:compressor_active", {
@@ -90,17 +83,10 @@
    groups = {cracky=2, not_in_creative_inventory=1},
    legacy_facedir_simple = true,
    sounds = default.node_sound_wood_defaults(),
    can_dig = function(pos,player)
        local meta = minetest.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(),
                    S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_abm({
technic/machines/LV/extractor.lua
@@ -74,17 +74,10 @@
        inv:set_size("src", 1)
        inv:set_size("dst", 4)
    end,
    can_dig = function(pos,player)
        local meta = minetest.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(),
                S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:extractor_active", {
@@ -96,17 +89,10 @@
    groups = {cracky=2, not_in_creative_inventory=1},
    legacy_facedir_simple = true,
    sounds = default.node_sound_wood_defaults(),
    can_dig = function(pos,player)
        local meta = minetest.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(),
                S("Machine cannot be removed because it is not empty"))
            return false
        else
            return true
        end
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_abm({
technic/machines/MV/tool_workshop.lua
@@ -33,16 +33,9 @@
        local inv = meta:get_inventory()
        inv:set_size("src", 1)
    end,    
    can_dig = function(pos,player)
        local meta = minetest.get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("src") then
            minetest.chat_send_player(player:get_player_name(),
                S("Machine cannot be removed because it is not empty"))
            return false
        end
        return true
    end,
    can_dig = technic.machine_can_dig,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
})
minetest.register_abm({
technic/machines/other/constructor.lua
@@ -74,17 +74,22 @@
        local inv = meta:get_inventory()
        return inv:is_empty("slot1")
    end,    
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:constructor_mk1_on", {
    description = "Constructor MK1",
    tile_images = {"technic_constructor_mk1_top_on.png","technic_constructor_mk1_bottom_on.png","technic_constructor_mk1_side2_on.png","technic_constructor_mk1_side1_on.png",
            "technic_constructor_back.png","technic_constructor_front_on.png"},
    is_ground_content = true,
    paramtype2 = "facedir",
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon = 2,not_in_creative_inventory=1},
    mesecons= {effector={action_off=mk1_off}},
    sounds = default.node_sound_stone_defaults(),
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
@@ -147,13 +152,15 @@
        inv:set_size("slot1", 1)
        inv:set_size("slot2", 1)
    end,
    can_dig = function(pos,player)
        local meta = minetest.get_meta(pos)
        local inv = meta:get_inventory()
        if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false then return false end
        return true
    end,
    end,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:constructor_mk2_on", {
@@ -163,8 +170,11 @@
    is_ground_content = true,
    paramtype2 = "facedir",
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2, not_in_creative_inventory=1},
    mesecons= {effector={action_off=mk2_off}},
    mesecons = {effector={action_off=mk2_off}},
    sounds = default.node_sound_stone_defaults(),
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
@@ -224,10 +234,9 @@
    description = "Constructor MK3",
    tile_images = {"technic_constructor_mk3_top_off.png","technic_constructor_mk3_bottom_off.png","technic_constructor_mk3_side2_off.png","technic_constructor_mk3_side1_off.png",
            "technic_constructor_back.png","technic_constructor_front_off.png"},
    is_ground_content = true,
    paramtype2 = "facedir",
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
    mesecons= {effector={action_on=mk3_on}},
    mesecons = {effector={action_on=mk3_on}},
    sounds = default.node_sound_stone_defaults(),
    on_construct = function(pos)
    local meta = minetest.get_meta(pos)
@@ -258,6 +267,9 @@
        if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false or inv:is_empty("slot3")==false or inv:is_empty("slot4")==false then return false end
        return true
    end,    
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_node("technic:constructor_mk3_on", {
@@ -267,8 +279,11 @@
    is_ground_content = true,
    paramtype2 = "facedir",
    groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,not_in_creative_inventory=1},
    mesecons= {effector={action_off=mk3_off}},
    mesecons = {effector={action_off=mk3_off}},
    sounds = default.node_sound_stone_defaults(),
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
technic/machines/other/injector.lua
@@ -1,7 +1,3 @@
minetest.register_craftitem("technic:injector", {
    description = "Injector",
    stack_max = 99,
})
minetest.register_craft({
    output = 'technic:injector 1',
@@ -39,15 +35,17 @@
        return inv:is_empty("main")
    end,
    on_receive_fields = function(pos, formanme, fields, sender)
    local meta = minetest.env:get_meta(pos)
    local mode=meta:get_string("mode")
    if fields.mode then
        if mode=="single items" then mode="whole stacks"
         else mode="single items"
        local meta = minetest.env:get_meta(pos)
        local mode=meta:get_string("mode")
        if fields.mode then
            if mode == "single items" then
                mode = "whole stacks"
            else
                mode = "single items"
            end
            meta:set_string("mode", mode)
        end
    local mode=meta:set_string("mode",mode)
    end
    meta:set_string("formspec",
        meta:set_string("formspec",
                "invsize[8,9;]"..
                "label[0,0;Injector]"..
                "button[0,1;.8,.8;mode;]"..
@@ -55,13 +53,15 @@
                "list[current_name;main;0,2;8,2;]"..
                "list[current_player;main;0,5;8,4;]")
    end,
    allow_metadata_inventory_put = technic.machine_inventory_put,
    allow_metadata_inventory_take = technic.machine_inventory_take,
    allow_metadata_inventory_move = technic.machine_inventory_move,
})
minetest.register_abm({
    nodenames = {"technic:injector"},
    interval = 1,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
    local pos1={}
    pos1.x = pos.x
technic/machines/register/alloy_furnace.lua
@@ -134,18 +134,10 @@
            inv:set_size("upgrade1", 1)
            inv:set_size("upgrade2", 1)
        end,
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_node("technic:"..ltier.."_alloy_furnace_active",{
@@ -163,36 +155,10 @@
        tube = data.tube and tube or nil,
        legacy_facedir_simple = true,
        sounds = default.node_sound_stone_defaults(),
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        -- These three makes sure upgrades are not moved in or out while the furnace is active.
        allow_metadata_inventory_put = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_count()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_take = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_count()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
            return 0
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_abm({
technic/machines/register/battery_box.lua
@@ -47,17 +47,10 @@
                inv:set_size("src", 1)
                inv:set_size("dst", 1)
            end,
            can_dig = function(pos, player)
                local meta = minetest.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(),
                        S("Machine cannot be removed because it is not empty"))
                    return false
                else
                    return true
                end
            end,
            can_dig = technic.machine_can_dig,
            allow_metadata_inventory_put = technic.machine_inventory_put,
            allow_metadata_inventory_take = technic.machine_inventory_take,
            allow_metadata_inventory_move = technic.machine_inventory_move,
        })
    end
technic/machines/register/common.lua
@@ -1,4 +1,6 @@
local S = technic.getter
function technic.handle_machine_upgrades(meta)
    -- Get the names of the upgrades
    local inv = meta:get_inventory()
@@ -109,3 +111,39 @@
    meta:set_int("tube_time", tube_time)
end
function technic.machine_can_dig(pos, player)
    local meta = minetest.get_meta(pos)
    local inv = meta:get_inventory()
    if not inv:is_empty("src") or not inv:is_empty("dst") or
       not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
        minetest.chat_send_player(player:get_player_name(),
            S("Machine cannot be removed because it is not empty"))
        return false
    else
        return true
    end
end
local function inv_change(pos, player, count)
    if minetest.is_protected(pos, player:get_player_name()) then
        minetest.chat_send_player(player:get_player_name(),
            S("Inventory move disallowed due to protection"))
        return 0
    end
    return count
end
function technic.machine_inventory_put(pos, listname, index, stack, player)
    return inv_change(pos, player, stack:get_count())
end
function technic.machine_inventory_take(pos, listname, index, stack, player)
    return inv_change(pos, player, stack:get_count())
end
function technic.machine_inventory_move(pos, from_list, from_index,
        to_list, to_index, count, player)
    return inv_change(pos, player, count)
end
technic/machines/register/electric_furnace.lua
@@ -69,18 +69,10 @@
            inv:set_size("upgrade1", 1)
            inv:set_size("upgrade2", 1)
        end,
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_node("technic:"..ltier.."_electric_furnace_active", {
@@ -110,36 +102,10 @@
            inv:set_size("upgrade1", 1)
            inv:set_size("upgrade2", 1)
        end,
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        -- These three makes sure upgrades are not moved in or out while the furnace is active.
        allow_metadata_inventory_put = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_stack_max()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_take = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_stack_max()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
            return 0
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_abm({
technic/machines/register/generator.lua
@@ -31,18 +31,12 @@
            local inv = meta:get_inventory()
            inv:set_size("src", 1)
        end,
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos)
            local inv = meta:get_inventory()
            if not inv:is_empty("src") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_node("technic:"..ltier.."_generator_active", {
        description = desc,
        tiles = {"technic_"..ltier.."_generator_top.png", "technic_machine_bottom.png",
@@ -54,17 +48,10 @@
        legacy_facedir_simple = true,
        sounds = default.node_sound_wood_defaults(),
        drop = "technic:"..ltier.."_generator",
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos)
            local inv = meta:get_inventory()
            if not inv:is_empty("src") then
                minetest.chat_send_player(player:get_player_name(),
                    S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_abm({
        nodenames = {"technic:"..ltier.."_generator", "technic:"..ltier.."_generator_active"},
technic/machines/register/grinder.lua
@@ -64,18 +64,10 @@
            inv:set_size("upgrade1", 1)
            inv:set_size("upgrade2", 1)
        end,
        can_dig = function(pos,player)
            local meta = minetest.get_meta(pos)
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                        S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_node("technic:"..ltier.."_grinder_active",{
@@ -88,36 +80,10 @@
        legacy_facedir_simple = true,
        sounds = default.node_sound_wood_defaults(),
        tube = data.tube and tube or nil,
        can_dig = function(pos, player)
            local meta = minetest.get_meta(pos)
            local inv = meta:get_inventory()
            if not inv:is_empty("src") or not inv:is_empty("dst") or
               not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
                minetest.chat_send_player(player:get_player_name(),
                        S("Machine cannot be removed because it is not empty"))
                return false
            else
                return true
            end
        end,
        -- These three makes sure upgrades are not moved in or out while the grinder is active.
        allow_metadata_inventory_put = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_stack_max()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_take = function(pos, listname, index, stack, player)
            if listname == "src" or listname == "dst" then
                return stack:get_stack_max()
            else
                return 0 -- Disallow the move
            end
        end,
        allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
            return 0
        end,
        can_dig = technic.machine_can_dig,
        allow_metadata_inventory_put = technic.machine_inventory_put,
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
    })
    minetest.register_abm({