From e90b28895cc28daf1a2e4fb772bd191400cf9e62 Mon Sep 17 00:00:00 2001
From: fgrosswig <falk@grosswig.de>
Date: Mon, 06 Jan 2020 21:50:15 +0100
Subject: [PATCH] battery_box.lua: Make "srcstack" local (#525)

---
 technic/machines/register/battery_box.lua |   96 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua
index c04875b..bf4d96a 100644
--- a/technic/machines/register/battery_box.lua
+++ b/technic/machines/register/battery_box.lua
@@ -12,12 +12,59 @@
 technic.register_power_tool("technic:green_energy_crystal", 150000)
 technic.register_power_tool("technic:blue_energy_crystal", 450000)
 
+-- Battery recipes:
+-- Tin-copper recipe:
 minetest.register_craft({
-	output = 'technic:battery',
+	output = "technic:battery",
 	recipe = {
-		{'group:wood', 'default:copper_ingot', 'group:wood'},
-		{'group:wood', 'moreores:tin_ingot',   'group:wood'},
-		{'group:wood', 'default:copper_ingot', 'group:wood'},
+		{"group:wood", "default:copper_ingot", "group:wood"},
+		{"group:wood", "default:tin_ingot",    "group:wood"},
+		{"group:wood", "default:copper_ingot", "group:wood"},
+	}
+})
+-- Sulfur-lead-water recipes:
+-- With sulfur lumps:
+-- With water:
+minetest.register_craft({
+	output = "technic:battery",
+	recipe = {
+		{"group:wood",         "technic:sulfur_lump", "group:wood"},
+		{"technic:lead_ingot", "bucket:bucket_water", "technic:lead_ingot"},
+		{"group:wood",         "technic:sulfur_lump", "group:wood"},
+	},
+	replacements = {
+		{"bucket:bucket_water", "bucket:bucket_empty"}
+	}
+})
+-- With oil extract:
+minetest.register_craft({
+	output = "technic:battery",
+	recipe = {
+		{"group:wood",         "technic:sulfur_lump",   "group:wood"},
+		{"technic:lead_ingot", "homedecor:oil_extract", "technic:lead_ingot"},
+		{"group:wood",         "technic:sulfur_lump",   "group:wood"},
+	}
+})
+-- With sulfur dust:
+-- With water:
+minetest.register_craft({
+	output = "technic:battery",
+	recipe = {
+		{"group:wood",         "technic:sulfur_dust", "group:wood"},
+		{"technic:lead_ingot", "bucket:bucket_water", "technic:lead_ingot"},
+		{"group:wood",         "technic:sulfur_dust", "group:wood"},
+	},
+	replacements = {
+		{"bucket:bucket_water", "bucket:bucket_empty"}
+	}
+})
+-- With oil extract:
+minetest.register_craft({
+	output = "technic:battery",
+	recipe = {
+		{"group:wood",         "technic:sulfur_dust",   "group:wood"},
+		{"technic:lead_ingot", "homedecor:oil_extract", "technic:lead_ingot"},
+		{"group:wood",         "technic:sulfur_dust",   "group:wood"},
 	}
 })
 
@@ -35,26 +82,38 @@
 	}
 })
 
+-- x+2 + (z+2)*2
+local dirtab = {
+	[4] = 2,
+	[5] = 3,
+	[7] = 1,
+	[8] = 0
+}
+
 local tube = {
 	insert_object = function(pos, node, stack, direction)
-		if direction.y == 0 then
+		print(minetest.pos_to_string(direction), dirtab[direction.x+2+(direction.z+2)*2], node.param2)
+		if direction.y == 1
+			or (direction.y == 0 and dirtab[direction.x+2+(direction.z+2)*2] == node.param2) then
 			return stack
 		end
 		local meta = minetest.get_meta(pos)
 		local inv = meta:get_inventory()
-		if direction.y > 0 then
+		if direction.y == 0 then
 			return inv:add_item("src", stack)
 		else
 			return inv:add_item("dst", stack)
 		end
 	end,
 	can_insert = function(pos, node, stack, direction)
-		if direction.y == 0 then
+		print(minetest.pos_to_string(direction), dirtab[direction.x+2+(direction.z+2)*2], node.param2)
+		if direction.y == 1
+			or (direction.y == 0 and dirtab[direction.x+2+(direction.z+2)*2] == node.param2) then
 			return false
 		end
 		local meta = minetest.get_meta(pos)
 		local inv = meta:get_inventory()
-		if direction.y > 0 then
+		if direction.y == 0 then
 			if meta:get_int("split_src_stacks") == 1 then
 				stack = stack:peek_item(1)
 			end
@@ -66,15 +125,15 @@
 			return inv:room_for_item("dst", stack)
 		end
 	end,
-	connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
+	connect_sides = {left=1, right=1, back=1, top=1},
 }
 
 local function add_on_off_buttons(meta, ltier, charge_percent)
-	local formspec = ""
-	if ltier == "mv" or ltier == "hv" then
-		formspec = "image[1,1;1,2;technic_power_meter_bg.png"
+	local formspec = "image[1,1;1,2;technic_power_meter_bg.png"
 			.."^[lowpart:"..charge_percent
-			..":technic_power_meter_fg.png]"..
+			..":technic_power_meter_fg.png]"
+	if ltier == "mv" or ltier == "hv" then
+		formspec = formspec..
 			fs_helpers.cycling_button(
 				meta,
 				"image_button[3,2.0;1,0.6",
@@ -196,8 +255,9 @@
 
 		local charge_percent = math.floor(current_charge / max_charge * 100)
 		meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, charge_percent))
-		local infotext = S("@1 Battery Box: @2/@3", tier,
-				technic.pretty_num(current_charge), technic.pretty_num(max_charge))
+		local infotext = S("@1 Battery Box: @2 / @3", tier,
+				technic.EU_string(current_charge),
+				technic.EU_string(max_charge))
 		if eu_input == 0 then
 			infotext = S("%s Idle"):format(infotext)
 		end
@@ -219,13 +279,12 @@
 		local top_tex = "technic_"..ltier.."_battery_box_top.png"..tube_entry
 		local front_tex = "technic_"..ltier.."_battery_box_front.png^technic_power_meter"..i..".png"
 		local side_tex = "technic_"..ltier.."_battery_box_side.png"..tube_entry
-		local bottom_tex = "technic_"..ltier.."_battery_box_bottom.png"..tube_entry
+		local bottom_tex = "technic_"..ltier.."_battery_box_bottom.png"..cable_entry
 
 		if ltier == "lv" then
 			top_tex = "technic_"..ltier.."_battery_box_top.png"
 			front_tex = "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"
 			side_tex = "technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"
-			bottom_tex = "technic_"..ltier.."_battery_box_bottom.png"..cable_entry
 		end
 
 		minetest.register_node("technic:"..ltier.."_battery_box"..i, {
@@ -271,6 +330,7 @@
 			allow_metadata_inventory_take = technic.machine_inventory_take,
 			allow_metadata_inventory_move = technic.machine_inventory_move,
 			technic_run = run,
+			on_rotate = screwdriver.rotate_simple,
 			after_place_node = data.tube and pipeworks.after_place,
 			after_dig_node = technic.machine_after_dig_node,
 			on_receive_fields = function(pos, formname, fields, sender)
@@ -392,7 +452,7 @@
 	if inv:is_empty("dst") then
 		return batt_charge, false
 	end
-	srcstack = inv:get_stack("dst", 1)
+	local srcstack = inv:get_stack("dst", 1)
 	local toolname = srcstack:get_name()
 	if technic.power_tools[toolname] == nil then
 		return batt_charge, false

--
Gitblit v1.8.0