From bb05ff8fd210fc9fac0b521f15e755380e6916d3 Mon Sep 17 00:00:00 2001
From: coil <51716565+coil0@users.noreply.github.com>
Date: Sun, 21 Jul 2019 12:40:57 +0200
Subject: [PATCH] Reject constructor in constructor slot inventories (#505)

---
 technic/machines/HV/forcefield.lua |   98 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 64 insertions(+), 34 deletions(-)

diff --git a/technic/machines/HV/forcefield.lua b/technic/machines/HV/forcefield.lua
index 3bb8d03..29c023d 100644
--- a/technic/machines/HV/forcefield.lua
+++ b/technic/machines/HV/forcefield.lua
@@ -17,9 +17,9 @@
 minetest.register_craft({
 	output = "technic:forcefield_emitter_off",
 	recipe = {
-			{"default:mese",         "technic:motor",          "default:mese"        },
-			{"technic:deployer_off", "technic:machine_casing", "technic:deployer_off"},
-			{"default:mese",         "technic:hv_cable",       "default:mese"        },
+		{"default:mese",         "basic_materials:motor",          "default:mese"        },
+		{"technic:deployer_off", "technic:machine_casing", "technic:deployer_off"},
+		{"default:mese",         "technic:hv_cable",       "default:mese"        },
 	}
 })
 
@@ -42,7 +42,7 @@
 --  |          |
 --   \___/\___/
 
-local function update_forcefield(pos, meta, active, first)
+local function update_forcefield(pos, meta, active)
 	local shape = meta:get_int("shape")
 	local range = meta:get_int("range")
 	local vm = VoxelManip()
@@ -86,11 +86,6 @@
 	vm:set_data(data)
 	vm:update_liquids()
 	vm:write_to_map()
-	-- update_map is very slow, but if we don't call it we'll
-	-- get phantom blocks on the client.
-	if not active or first then
-		vm:update_map()
-	end
 end
 
 local function set_forcefield_formspec(meta)
@@ -126,6 +121,12 @@
 end
 
 local forcefield_receive_fields = function(pos, formname, fields, sender)
+	local player_name = sender:get_player_name()
+	if minetest.is_protected(pos, player_name) then
+		minetest.chat_send_player(player_name, "You are not allowed to edit this!")
+		minetest.record_protection_violation(pos, player_name)
+		return
+	end
 	local meta = minetest.get_meta(pos)
 	local range = nil
 	if fields.range then
@@ -170,44 +171,68 @@
 			if channel ~= meta:get_string("channel") then
 				return
 			end
-			msg = msg:lower()
-			if msg == "get" then
+			local msgt = type(msg)
+			if msgt == "string" then
+				local smsg = msg:lower()
+				msg = {}
+				if smsg == "get" then
+					msg.command = "get"
+				elseif smsg == "off" then
+					msg.command = "off"
+				elseif smsg == "on" then
+					msg.command = "on"
+				elseif smsg == "toggle" then
+					msg.command = "toggle"
+				elseif smsg:sub(1, 5) == "range" then
+					msg.command = "range"
+					msg.value = tonumber(smsg:sub(7))
+				elseif smsg:sub(1, 5) == "shape" then
+					msg.command = "shape"
+					msg.value = smsg:sub(7):lower()
+					msg.value = tonumber(msg.value) or msg.value
+				end
+			elseif msgt ~= "table" then
+				return
+			end
+			if msg.command == "get" then
 				digilines.receptor_send(pos, digilines.rules.default, channel, {
 					enabled = meta:get_int("enabled"),
 					range   = meta:get_int("range"),
 					shape   = meta:get_int("shape")
 				})
 				return
-			elseif msg == "off" then
+			elseif msg.command == "off" then
 				meta:set_int("enabled", 0)
-			elseif msg == "on" then
+			elseif msg.command == "on" then
 				meta:set_int("enabled", 1)
-			elseif msg == "toggle" then
+			elseif msg.command == "toggle" then
 				local onn = meta:get_int("enabled")
 				onn = 1-onn -- Mirror onn with pivot 0.5, so switch between 1 and 0.
 				meta:set_int("enabled", onn)
-			elseif msg:sub(1, 5) == "range" then
-				local range = tonumber(msg:sub(7))
-				if not range then
+			elseif msg.command == "range" then
+				if type(msg.value) ~= "number" then
 					return
 				end
-				range = math.max(range, 5)
-				range = math.min(range, 20)
+				msg.value = math.max(msg.value, 5)
+				msg.value = math.min(msg.value, 20)
 				update_forcefield(pos, meta, false)
-				meta:set_int("range", range)
-			elseif msg:sub(1, 5) == "shape" then
-				local shape = msg:sub(7):lower()
-				if shape == "sphere" then
-					shape = 0
-				elseif shape == "cube" then
-					shape = 1
+				meta:set_int("range", msg.value)
+			elseif msg.command == "shape" then
+				local valuet = type(msg.value)
+				if valuet == "string" then
+					if msg.value == "sphere" then
+						msg.value = 0
+					elseif msg.value == "cube" then
+						msg.value = 1
+					end
+				elseif valuet ~= "number" then
+					return
 				end
-				shape = tonumber(shape)
-				if not shape then
+				if not msg.value then
 					return
 				end
 				update_forcefield(pos, meta, false)
-				meta:set_int("shape", shape)
+				meta:set_int("shape", msg.value)
 			else
 				return
 			end
@@ -219,7 +244,8 @@
 local function run(pos, node)
 	local meta = minetest.get_meta(pos)
 	local eu_input   = meta:get_int("HV_EU_input")
-	local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
+	local enabled = meta:get_int("enabled") ~= 0 and
+		(meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
 	local machine_name = S("%s Forcefield Emitter"):format("HV")
 
 	local range = meta:get_int("range")
@@ -248,13 +274,11 @@
 			technic.swap_node(pos, "technic:forcefield_emitter_off")
 		end
 	elseif eu_input >= power_requirement then
-		local first = false
 		if node.name == "technic:forcefield_emitter_off" then
-			first = true
 			technic.swap_node(pos, "technic:forcefield_emitter_on")
 			meta:set_string("infotext", S("%s Active"):format(machine_name))
 		end
-		update_forcefield(pos, meta, true, first)
+		update_forcefield(pos, meta, true)
 	end
 end
 
@@ -315,6 +339,10 @@
 		update_forcefield(pos, meta, false)
 		technic.swap_node(pos, "technic:forcefield_emitter_off")
 	end,
+	on_blast = function(pos, intensity)
+		minetest.dig_node(pos)
+		return {"technic:forcefield_emitter_off"}
+	end,
 })
 
 minetest.register_node("technic:forcefield", {
@@ -323,7 +351,7 @@
 	drawtype = "glasslike",
 	groups = {not_in_creative_inventory=1},
 	paramtype = "light",
-        light_source = 15,
+	light_source = default.LIGHT_MAX,
 	diggable = false,
 	drop = '',
 	tiles = {{
@@ -335,6 +363,8 @@
 			length = 1.0,
 		},
 	}},
+	on_blast = function(pos, intensity)
+	end,
 })
 
 

--
Gitblit v1.8.0