From 718a5beda197cd0a775fd41aedfb5b1bbd5d1d8b Mon Sep 17 00:00:00 2001
From: ZettaScript <contact@zettascript.org>
Date: Thu, 20 Oct 2022 17:56:10 +0200
Subject: [PATCH] Supply converter: demany only the needed power (#577)

---
 technic/tools/cans.lua |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/technic/tools/cans.lua b/technic/tools/cans.lua
index 369259e..6507f7a 100644
--- a/technic/tools/cans.lua
+++ b/technic/tools/cans.lua
@@ -36,7 +36,10 @@
 			local charge = get_can_level(itemstack)
 			if charge == data.can_capacity then return end
 			if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
-				minetest.log("action", user:get_player_name().." tried to take "..node.name.." at protected position "..minetest.pos_to_string(pointed_thing.under).." with a "..data.can_name)
+				minetest.log("action", user:get_player_name()..
+					" tried to take "..node.name..
+					" at protected position "..minetest.pos_to_string(pointed_thing.under)..
+					" with a "..data.can_name)
 				return
 			end
 			minetest.remove_node(pointed_thing.under)
@@ -48,19 +51,25 @@
 		on_place = function(itemstack, user, pointed_thing)
 			if pointed_thing.type ~= "node" then return end
 			local pos = pointed_thing.under
-			local def = minetest.registered_nodes[minetest.get_node(pos).name] or {}
+			local node_name = minetest.get_node(pos).name
+			local def = minetest.registered_nodes[node_name] or {}
 			if def.on_rightclick and user and not user:get_player_control().sneak then
 				return def.on_rightclick(pos, minetest.get_node(pos), user, itemstack, pointed_thing)
 			end
-			if not def.buildable_to then
+			if not def.buildable_to or node_name == data.liquid_source_name then
 				pos = pointed_thing.above
-				def = minetest.registered_nodes[minetest.get_node(pos).name] or {}
-				if not def.buildable_to then return end
+				node_name = minetest.get_node(pos).name
+				def = minetest.registered_nodes[node_name] or {}
+				-- Try to place node above the pointed source, or abort.
+				if not def.buildable_to or node_name == data.liquid_source_name then return end
 			end
 			local charge = get_can_level(itemstack)
 			if charge == 0 then return end
 			if minetest.is_protected(pos, user:get_player_name()) then
-				minetest.log("action", user:get_player_name().." tried to place "..data.liquid_source_name.." at protected position "..minetest.pos_to_string(pos).." with a "..data.can_name)
+				minetest.log("action", user:get_player_name()..
+					" tried to place "..data.liquid_source_name..
+					" at protected position "..minetest.pos_to_string(pos)..
+					" with a "..data.can_name)
 				return
 			end
 			minetest.set_node(pos, {name=data.liquid_source_name})

--
Gitblit v1.8.0