From 0809dd747e3a5eb3d43c9a8d027e3a98c225e16d Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 27 Nov 2013 12:28:56 -0500 Subject: [PATCH] Externalize common functions and protect inventories --- technic/locale/es.txt | 1 + technic/locale/it.txt | 1 + technic/locale/template.txt | 2 +- technic/machines/HV/nuclear_reactor.lua | 30 +++-------- technic/machines/LV/cnc.lua | 29 +++-------- technic/machines/LV/coal_alloy_furnace.lua | 35 ++++++------- technic/machines/LV/compressor.lua | 30 +++-------- technic/machines/LV/extractor.lua | 30 +++-------- technic/machines/MV/tool_workshop.lua | 13 ++--- technic/machines/other/constructor.lua | 29 ++++++++--- technic/machines/other/injector.lua | 26 +++++----- technic/machines/register/alloy_furnace.lua | 50 +++---------------- technic/machines/register/battery_box.lua | 15 ++---- technic/machines/register/common.lua | 38 ++++++++++++++ .../machines/register/electric_furnace.lua | 50 +++---------------- technic/machines/register/generator.lua | 31 ++++-------- technic/machines/register/grinder.lua | 50 +++---------------- 17 files changed, 162 insertions(+), 298 deletions(-) diff --git a/technic/locale/es.txt b/technic/locale/es.txt index 6867299..efa5828 100644 --- a/technic/locale/es.txt +++ b/technic/locale/es.txt @@ -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 diff --git a/technic/locale/it.txt b/technic/locale/it.txt index f8629d2..94ee4d2 100644 --- a/technic/locale/it.txt +++ b/technic/locale/it.txt @@ -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 diff --git a/technic/locale/template.txt b/technic/locale/template.txt index bd24aae..37d16db 100644 --- a/technic/locale/template.txt +++ b/technic/locale/template.txt @@ -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 = - diff --git a/technic/machines/HV/nuclear_reactor.lua b/technic/machines/HV/nuclear_reactor.lua index 4a77a97..afe0b5a 100644 --- a/technic/machines/HV/nuclear_reactor.lua +++ b/technic/machines/HV/nuclear_reactor.lua @@ -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) diff --git a/technic/machines/LV/cnc.lua b/technic/machines/LV/cnc.lua index 8ade480..146c1a4 100644 --- a/technic/machines/LV/cnc.lua +++ b/technic/machines/LV/cnc.lua @@ -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, }) diff --git a/technic/machines/LV/coal_alloy_furnace.lua b/technic/machines/LV/coal_alloy_furnace.lua index e2baeea..ad34208 100644 --- a/technic/machines/LV/coal_alloy_furnace.lua +++ b/technic/machines/LV/coal_alloy_furnace.lua @@ -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({ diff --git a/technic/machines/LV/compressor.lua b/technic/machines/LV/compressor.lua index 35a2880..dd8c792 100644 --- a/technic/machines/LV/compressor.lua +++ b/technic/machines/LV/compressor.lua @@ -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({ diff --git a/technic/machines/LV/extractor.lua b/technic/machines/LV/extractor.lua index 0e6f53a..f6df532 100644 --- a/technic/machines/LV/extractor.lua +++ b/technic/machines/LV/extractor.lua @@ -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({ diff --git a/technic/machines/MV/tool_workshop.lua b/technic/machines/MV/tool_workshop.lua index 046fef1..7191c0c 100644 --- a/technic/machines/MV/tool_workshop.lua +++ b/technic/machines/MV/tool_workshop.lua @@ -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({ diff --git a/technic/machines/other/constructor.lua b/technic/machines/other/constructor.lua index f8c9ac3..87cc59b 100644 --- a/technic/machines/other/constructor.lua +++ b/technic/machines/other/constructor.lua @@ -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, }) diff --git a/technic/machines/other/injector.lua b/technic/machines/other/injector.lua index c493744..6897861 100644 --- a/technic/machines/other/injector.lua +++ b/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 @@ 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 diff --git a/technic/machines/register/alloy_furnace.lua b/technic/machines/register/alloy_furnace.lua index e2c2ff2..4bb61fd 100644 --- a/technic/machines/register/alloy_furnace.lua +++ b/technic/machines/register/alloy_furnace.lua @@ -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({ diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua index 8e3d8e7..8da6200 100644 --- a/technic/machines/register/battery_box.lua +++ b/technic/machines/register/battery_box.lua @@ -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 diff --git a/technic/machines/register/common.lua b/technic/machines/register/common.lua index 664f43b..054d627 100644 --- a/technic/machines/register/common.lua +++ b/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 @@ 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 + diff --git a/technic/machines/register/electric_furnace.lua b/technic/machines/register/electric_furnace.lua index 1b18da6..7420ffe 100644 --- a/technic/machines/register/electric_furnace.lua +++ b/technic/machines/register/electric_furnace.lua @@ -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({ diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua index 8c9a7cb..d3abe31 100644 --- a/technic/machines/register/generator.lua +++ b/technic/machines/register/generator.lua @@ -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"}, diff --git a/technic/machines/register/grinder.lua b/technic/machines/register/grinder.lua index ec53087..66f4771 100644 --- a/technic/machines/register/grinder.lua +++ b/technic/machines/register/grinder.lua @@ -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({