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/register.lua |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/technic/register.lua b/technic/register.lua
index 0dc321d..6a587ea 100644
--- a/technic/register.lua
+++ b/technic/register.lua
@@ -3,14 +3,16 @@
 
 technic.receiver = "RE"
 technic.producer = "PR"
+technic.producer_receiver = "PR_RE"
 technic.battery  = "BA"
 
 technic.machines    = {}
 technic.power_tools = {}
+technic.networks = {}
+
 
 function technic.register_tier(tier, description)
-	technic.machines[tier]    = {}
-	technic.cables[tier]      = {}
+	technic.machines[tier] = {}
 end
 
 function technic.register_machine(tier, nodename, machine_type)
@@ -41,8 +43,19 @@
 end
 
 -- Wear down a tool depending on the remaining charge.
-function technic.set_RE_wear(item_stack, item_load, max_load)
-	local temp = 65536 - math.floor(item_load / max_load * 65535)
-	item_stack.wear = tostring(temp)
-	return item_stack
+function technic.set_RE_wear(itemstack, item_load, max_load)
+	local def = minetest.registered_items[itemstack:get_name()]
+	if (def.wear_represents or "mechanical_wear") ~= "technic_RE_charge" then
+		return itemstack
+	end
+	local temp
+	if item_load == 0 then
+		temp = 0
+	else
+		temp = 65536 - math.floor(item_load / max_load * 65535)
+		if temp > 65535 then temp = 65535 end
+		if temp < 1 then temp = 1 end
+	end
+	itemstack:set_wear(temp)
+	return itemstack
 end

--
Gitblit v1.8.0