From 0f7810e53895f5742ab577559584539e6533a0dc Mon Sep 17 00:00:00 2001
From: auouymous <5005204+auouymous@users.noreply.github.com>
Date: Sat, 06 Feb 2021 12:41:09 +0100
Subject: [PATCH] Public/private mode for self-contained injector (#567)

---
 technic/machines/other/constructor.lua |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/technic/machines/other/constructor.lua b/technic/machines/other/constructor.lua
index e7b1f67..9117224 100644
--- a/technic/machines/other/constructor.lua
+++ b/technic/machines/other/constructor.lua
@@ -88,6 +88,7 @@
 local function make_on(mark, length)
 	return function(pos, node)
 		local meta = minetest.get_meta(pos)
+		local owner = meta:get_string("owner")
 		local inv = meta:get_inventory()
 		local dir = vector.new()
 		if node.param2 == 3 then dir.x = 1 end
@@ -102,6 +103,9 @@
 			minetest.check_for_falling(pos)
 			for i = 1, length do
 				place_pos = vector.add(place_pos, dir)
+				if owner ~= "" and minetest.is_protected(place_pos, owner) then
+					return
+				end
 				local place_node = minetest.get_node(place_pos)
 				deploy_node(inv, "slot"..i, place_pos, place_node, node)
 			end
@@ -156,6 +160,11 @@
 			for i = 1, length do
 				inv:set_size("slot"..i, 1)
 			end
+			meta:set_string("owner", "?")
+		end,
+		after_place_node = function(pos, placer)
+			local meta = minetest.get_meta(pos)
+			meta:set_string("owner", (placer and placer:get_player_name() or "?"))
 		end,
 		can_dig = function(pos, player)
 			local meta = minetest.get_meta(pos)

--
Gitblit v1.8.0