Externalize common functions and protect inventories
authorShadowNinja <shadowninja@minetest.net>
Wed, 27 Nov 2013 17:28:56 +0000 (12:28 -0500)
committerShadowNinja <shadowninja@minetest.net>
Wed, 27 Nov 2013 17:28:56 +0000 (12:28 -0500)
17 files changed:
technic/locale/es.txt
technic/locale/it.txt
technic/locale/template.txt
technic/machines/HV/nuclear_reactor.lua
technic/machines/LV/cnc.lua
technic/machines/LV/coal_alloy_furnace.lua
technic/machines/LV/compressor.lua
technic/machines/LV/extractor.lua
technic/machines/MV/tool_workshop.lua
technic/machines/other/constructor.lua
technic/machines/other/injector.lua
technic/machines/register/alloy_furnace.lua
technic/machines/register/battery_box.lua
technic/machines/register/common.lua
technic/machines/register/electric_furnace.lua
technic/machines/register/generator.lua
technic/machines/register/grinder.lua

index 6867299911c9c9a45dd87d7f0c292ca37a90ad22..efa5828c2cb68cb9ca59835411f3ed8977b0ff9f 100644 (file)
@@ -33,6 +33,7 @@ Rubber Fiber = Fibra de Hule
 
 ## 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
index f8629d2f6731e16ba096d06233b298c742d12531..94ee4d200422c216324f9b83e01c7cbde7246d51 100644 (file)
@@ -29,6 +29,7 @@ Rubber Fiber = Fibra di gomma
 
 ## 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
index bd24aaed0f7d21d45f197bc13aa51d3d6391cb1b..37d16db1b5ec947832710f7dad853f0ea843d84a 100644 (file)
@@ -32,6 +32,7 @@ Rubber Fiber =
 
 ## 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 =
@@ -159,4 +160,3 @@ Single node. =
 Sonic Screwdriver =
 Tree Tap =
 
-
index 4a77a9789751961d3c9f05190a80b5313a62dfe6..afe0b5af7017e15db5853f7f57b274ec7edf7c6b 100644 (file)
@@ -75,17 +75,10 @@ minetest.register_node("technic:hv_nuclear_reactor_core", {
                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 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
                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)
index 8ade480fd45cea6b5284083b165248178a8ce8ad..146c1a4a1a50fa7d000f83930f7ee366969552b6 100644 (file)
@@ -150,17 +150,10 @@ minetest.register_node("technic:cnc", {
                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 @@ minetest.register_node("technic:cnc_active", {
        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,
 })
 
index e2baeeae3395a6c1bc7c8baf92637cc974914e61..ad3420849affa2c7c5e7e3b7e027f3e9a110f506 100644 (file)
@@ -14,8 +14,9 @@ minetest.register_craft({
 
 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 @@ minetest.register_node("technic:coal_alloy_furnace", {
                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({
index 35a2880a2e16d7072809ad09be19f26cc8400516..dd8c7923340e0354401206f6d898525eaeef14d5 100644 (file)
@@ -68,17 +68,10 @@ minetest.register_node("technic:compressor", {
                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 @@ minetest.register_node("technic:compressor_active", {
        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({
index 0e6f53a57d85c3326888ebda74f34f8247fb4d13..f6df53294348cac2f1402c41e157f1b7707abee4 100644 (file)
@@ -74,17 +74,10 @@ minetest.register_node("technic:extractor", {
                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 @@ minetest.register_node("technic:extractor_active", {
        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({
index 046fef1dc7b2ded2e78d381e961050e8ff5d2d00..7191c0ca8323abf2b120ad9567018cc39fa7d87f 100644 (file)
@@ -33,16 +33,9 @@ minetest.register_node("technic:tool_workshop", {
                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({
index f8c9ac3d4ca71848115b7dafa6c762937c828ce5..87cc59b860a8e4736edb990f7be856b68f4e5580 100644 (file)
@@ -74,17 +74,22 @@ minetest.register_node("technic:constructor_mk1_off", {
                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 @@ minetest.register_node("technic:constructor_mk2_off", {
                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 @@ minetest.register_node("technic:constructor_mk2_on", {
        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 @@ minetest.register_node("technic:constructor_mk3_off", {
        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 @@ minetest.register_node("technic:constructor_mk3_off", {
                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 @@ minetest.register_node("technic:constructor_mk3_on", {
        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,
 })
 
 
index c4937441f53c89560d7ed6505caddc44da5376ef..6897861b0c1261dbeb29253440edcab0affdef04 100644 (file)
@@ -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 @@ minetest.register_node("technic:injector", {
                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 @@ minetest.register_node("technic:injector", {
                                "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
index e2c2ff2d6700fbf6850d279360c05c0b54e12c04..4bb61fd29a1a472ab92787da3ace11fa1b006ae2 100644 (file)
@@ -134,18 +134,10 @@ function technic.register_alloy_furnace(data)
                        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 @@ function technic.register_alloy_furnace(data)
                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({
index 8e3d8e7e4c8aa44f57fa527747f7b3af7a2f8f73..8da6200217108493b69938a1571775684275c444 100644 (file)
@@ -47,17 +47,10 @@ function technic.register_battery_box(data)
                                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
 
index 664f43bbca045cf8f1d0a45e0ea31f0ed9e5feef..054d627720444070568249353de407b9d261042c 100644 (file)
@@ -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 @@ function technic.handle_machine_pipeworks(pos, tube_upgrade)
        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
+
index 1b18da6fc1c47ee04cf60f7c33633fbdd1ca27bf..7420ffe9212ea955997aa7923d3897d3f0bbd3d8 100644 (file)
@@ -69,18 +69,10 @@ function technic.register_electric_furnace(data)
                        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 @@ function technic.register_electric_furnace(data)
                        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({
index 8c9a7cb550f72beb0b5791aaf9e4c65765893dc2..d3abe31d9d05bea742fa80f52725cea61bd4ff88 100644 (file)
@@ -31,18 +31,12 @@ function technic.register_generator(data)
                        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 @@ function technic.register_generator(data)
                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"},
index ec530875db99c06b4deae57704ce8ac56b404841..66f4771e4742fafb3ecb22e52829c17ae7e484ba 100644 (file)
@@ -64,18 +64,10 @@ function technic.register_grinder(data)
                        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 @@ function technic.register_grinder(data)
                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({