From 10307f23a78b33af50dc4a5f3d1baafb4ee4b0d9 Mon Sep 17 00:00:00 2001
From: Maciej 'agaran' Pijanka <agaran@pld-linux.org>
Date: Thu, 16 Mar 2017 00:00:22 +0100
Subject: [PATCH] Do not run converters twice.

---
 technic/tools/mining_lasers.lua |   81 +++++-----------------------------------
 1 files changed, 11 insertions(+), 70 deletions(-)

diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua
index 872271c..ef1eecb 100644
--- a/technic/tools/mining_lasers.lua
+++ b/technic/tools/mining_lasers.lua
@@ -32,75 +32,14 @@
 	}
 })
 
--- Based on code by Uberi: https://gist.github.com/Uberi/3125280
-local function rayIter(pos, dir, range)
-	local p = vector.round(pos)
-	local x_step,      y_step,      z_step      = 0, 0, 0
-	local x_component, y_component, z_component = 0, 0, 0
-	local x_intersect, y_intersect, z_intersect = 0, 0, 0
-
-	if dir.x == 0 then
-		x_intersect = math.huge
-	elseif dir.x > 0 then
-		x_step = 1
-		x_component = 1 / dir.x
-		x_intersect = x_component
-	else
-		x_step = -1
-		x_component = 1 / -dir.x
-	end
-	if dir.y == 0 then
-		y_intersect = math.huge
-	elseif dir.y > 0 then
-		y_step = 1
-		y_component = 1 / dir.y
-		y_intersect = y_component
-	else
-		y_step = -1
-		y_component = 1 / -dir.y
-	end
-	if dir.z == 0 then
-		z_intersect = math.huge
-	elseif dir.z > 0 then
-		z_step = 1
-		z_component = 1 / dir.z
-		z_intersect = z_component
-	else
-		z_step = -1
-		z_component = 1 / -dir.z
-	end
-
-	return function()
-		if x_intersect < y_intersect then
-			if x_intersect < z_intersect then
-				p.x = p.x + x_step
-				x_intersect = x_intersect + x_component
-			else
-				p.z = p.z + z_step
-				z_intersect = z_intersect + z_component
-			end
-		elseif y_intersect < z_intersect then
-			p.y = p.y + y_step
-			y_intersect = y_intersect + y_component
-		else
-			p.z = p.z + z_step
-			z_intersect = z_intersect + z_component
-		end
-		if vector.distance(pos, p) > range then
-			return nil
-		end
-		return p
-	end
-end
-
 local function laser_node(pos, node, player)
 	local def = minetest.registered_nodes[node.name]
 	if def and def.liquidtype ~= "none" then
 		minetest.remove_node(pos)
 		minetest.add_particle({
 			pos = pos,
-			vel = {x=0, y=2, z=0},
-			acc = {x=0, y=-1, z=0},
+			velocity = {x=0, y=2, z=0},
+			acceleration = {x=0, y=-1, z=0},
 			expirationtime = 1.5,
 			size = 6 + math.random() * 2,
 			texture = "smoke_puff.png^[transform" .. math.random(0, 7),
@@ -122,17 +61,17 @@
 
 	local start_pos = vector.new(player_pos)
 	-- Adjust to head height
-	start_pos.y = start_pos.y + 1.9
+	start_pos.y = start_pos.y + 1.6
 	minetest.add_particle({
 		pos = startpos,
-		vel = dir,
-		acc = vector.multiply(dir, 50),
+		velocity = dir,
+		acceleration = vector.multiply(dir, 50),
 		expirationtime = range / 11,
 		size = 1,
 		texture = particle_texture .. "^[transform" .. math.random(0, 7),
 	})
 	minetest.sound_play(sound, {pos = player_pos, max_hear_distance = range})
-	for pos in rayIter(start_pos, dir, range) do
+	for pos in technic.trace_node_ray_fat(start_pos, dir, range) do
 		if minetest.is_protected(pos, player_name) then
 			minetest.record_protection_violation(pos, player_name)
 			break
@@ -164,10 +103,12 @@
 
 			-- If there's enough charge left, fire the laser
 			if meta.charge >= m[4] then
-				meta.charge = meta.charge - m[4]
 				laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
-				technic.set_RE_wear(itemstack, meta.charge, m[3])
-				itemstack:set_metadata(minetest.serialize(meta))
+				if not technic.creative_mode then
+					meta.charge = meta.charge - m[4]
+					technic.set_RE_wear(itemstack, meta.charge, m[3])
+					itemstack:set_metadata(minetest.serialize(meta))
+				end
 			end
 			return itemstack
 		end,

--
Gitblit v1.8.0