summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2015-02-06 07:54:29 +0100
committerTim <t4im@users.noreply.github.com>2015-02-06 07:54:29 +0100
commita13e7b7ed1ab8948f3edc014e894c78ff4c8c653 (patch)
tree4058f9cad3dd79a08b471f9f0183504aba938c91
parent91e12c41fdb91e00dbd1cde88c18c45791aa213f (diff)
add the option for publicly shared machines via an upgrade item "default:chest
the upgrade slots remain protected this replaces the need for a few forks and also resolves #131 in the process, which is obsolete now
-rw-r--r--technic/machines/register/common.lua37
1 files changed, 29 insertions, 8 deletions
diff --git a/technic/machines/register/common.lua b/technic/machines/register/common.lua
index 51747d8..6d4c066 100644
--- a/technic/machines/register/common.lua
+++ b/technic/machines/register/common.lua
@@ -34,12 +34,28 @@ end
-- handles the machine upgrades when set or removed
local function on_machine_upgrade(meta, stack)
- local stack_name = stack and stack:get_name()
- if stack_name ~= "technic:control_logic_unit"
- and stack_name ~= "technic:battery" then
+ local stack_name = stack:get_name()
+ if stack_name == "default:chest" then
+ meta:set_int("public", 1)
+ return 1
+ elseif stack_name ~= "technic:control_logic_unit"
+ and stack_name ~= "technic:battery" then
return 0
end
+ return 1
+end
+
+-- something is about to be removed
+local function on_machine_downgrade(meta, stack, list)
+ if stack:get_name() == "default:chest" then
+ local inv = meta:get_inventory()
+ local upg1, upg2 = inv:get_stack("upgrade1", 1), inv:get_stack("upgrade2", 1)
+ -- only set 0 if theres not a nother chest in the other list too
+ if (not upg1 or not upg2 or upg1:get_name() ~= upg2:get_name()) then
+ meta:set_int("public", 0)
+ end
+ end
return 1
end
@@ -140,20 +156,25 @@ end
local function inv_change(pos, player, count, from_list, to_list, stack)
local playername = player:get_player_name()
- if minetest.is_protected(pos, playername) then
+ local meta = minetest.get_meta(pos);
+ local public = (meta:get_int("public") == 1)
+ local to_upgrade = to_list == "upgrade1" or to_list == "upgrade2"
+ local from_upgrade = from_list == "upgrade1" or from_list == "upgrade2"
+
+ if (not public or to_upgrade or from_upgrade) and minetest.is_protected(pos, playername) then
minetest.chat_send_player(playername, S("Inventory move disallowed due to protection"))
return 0
end
- if to_list == "upgrade1" or to_list == "upgrade2" then
+ if to_upgrade then
-- only place a single item into it, if it's empty
- local meta = minetest.get_meta(pos);
local empty = meta:get_inventory():is_empty(to_list)
if empty then
return on_machine_upgrade(meta, stack)
end
return 0
- elseif from_list == "upgrade1" or from_list == "upgrade2" then
- on_machine_upgrade(meta, nil)
+ elseif from_upgrade then
+ -- only called on take (not move)
+ on_machine_downgrade(meta, stack, from_list)
end
return count
end