From 2258adb2a9b2ec223ea3614a39ecbd59d2d6c948 Mon Sep 17 00:00:00 2001
From: veikk0 <email@example.com>
Date: Wed, 30 Mar 2016 21:53:29 +0200
Subject: [PATCH] Replace nuclear reactor alarm sound

---
 technic/tools/mining_lasers.lua |  189 ++++++++++++++--------------------------------
 1 files changed, 58 insertions(+), 131 deletions(-)

diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua
index 03286f4..c09aa92 100644
--- a/technic/tools/mining_lasers.lua
+++ b/technic/tools/mining_lasers.lua
@@ -1,6 +1,3 @@
-
-local r_corr = 0.25 -- Remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
-
 local mining_lasers_list = {
 --	{<num>, <range of the laser shots>, <max_charge>, <charge_per_shot>},
 	{"1", 7, 50000, 1000},
@@ -8,157 +5,85 @@
 	{"3", 21, 650000, 3000},
 }
 
-local f_1 = 0.5 - r_corr
-local f_2 = 0.5 + r_corr
-
 local S = technic.getter
 
 minetest.register_craft({
 	output = 'technic:laser_mk1',
 	recipe = {
-		{'default:diamond', 'default:steel_ingot', 'technic:red_energy_crystal'},
-		{'',                'default:steel_ingot', 'default:steel_ingot'},
-		{'',                '',                    'default:copper_ingot'},
+		{'default:diamond', 'technic:brass_ingot',        'default:obsidian_glass'},
+		{'',                'technic:brass_ingot',        'technic:red_energy_crystal'},
+		{'',                '',                           'default:copper_ingot'},
 	}
 })
 minetest.register_craft({
 	output = 'technic:laser_mk2',
 	recipe = {
-		{'default:diamond', 'default:steel_ingot', 'technic:laser_mk1'},
-		{'',                'default:steel_ingot', 'technic:green_energy_crystal'},
-		{'',                '',                    'default:copper_ingot'},
+		{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk1'},
+		{'',                'technic:carbon_steel_ingot', 'technic:green_energy_crystal'},
+		{'',                '',                           'default:copper_ingot'},
 	}
 })
 minetest.register_craft({
 	output = 'technic:laser_mk3',
 	recipe = {
-		{'default:diamond', 'default:steel_ingot', 'technic:laser_mk2'},
-		{'',                'default:steel_ingot', 'technic:blue_energy_crystal'},
-		{'',                '',                    'default:copper_ingot'},
+		{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk2'},
+		{'',                'technic:carbon_steel_ingot', 'technic:blue_energy_crystal'},
+		{'',                '',                           'default:copper_ingot'},
 	}
 })
 
-
-local function get_used_dir(dir)
-	local abs_dir = {x = math.abs(dir.x),
-			y = math.abs(dir.y),
-			z = math.abs(dir.z)}
-	local dir_max = math.max(abs_dir.x, abs_dir.y, abs_dir.z)
-	if dir_max == abs_dir.x then
-		local tab = {"x", {x = 1, y = dir.y / dir.x, z = dir.z / dir.x}}
-		if dir.x >= 0 then
-			tab[3] = "+"
-		end
-		return tab
-	end
-	if dir_max == abs_dir.y then
-		local tab = {"y", {x = dir.x / dir.y, y = 1, z = dir.z / dir.y}}
-		if dir.y >= 0 then
-			tab[3] = "+"
-		end
-		return tab
-	end
-	local tab = {"z", {x = dir.x / dir.z, y = dir.y / dir.z, z = 1}}
-	if dir.z >= 0 then
-		tab[3] = "+"
-	end
-	return tab
-end
-
-local function node_tab(z, d)
-	local n1 = math.floor(z * d + f_1)
-	local n2 = math.floor(z * d + f_2)
-	if n1 == n2 then
-		return {n1}
-	end
-	return {n1, n2}
-end
-
-local function laser_node(pos, player)
-	local node = minetest.get_node(pos)
-	if node.name == "air"
-	or node.name == "ignore"
-	or node.name == "default:lava_source"
-	or node.name == "default:lava_flowing" then
-		return
-	end
-	if minetest.is_protected(pos, player:get_player_name()) then
-		minetest.record_protection_violation(pos, player:get_player_name())
-		return
-	end
-	if node.name == "default:water_source"
-	or node.name == "default:water_flowing" then
+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,
-				{x=0, y=2, z=0},
-				{x=0, y=-1, z=0},
-				1.5,
-				8,
-				false,
-				"smoke_puff.png")
+		minetest.add_particle({
+			pos = pos,
+			vel = {x=0, y=2, z=0},
+			acc = {x=0, y=-1, z=0},
+			expirationtime = 1.5,
+			size = 6 + math.random() * 2,
+			texture = "smoke_puff.png^[transform" .. math.random(0, 7),
+		})
 		return
 	end
-	if player then
-		minetest.node_dig(pos, node, player)
-	end
+	minetest.node_dig(pos, node, player)
 end
 
-local function laser_nodes(pos, dir, player, range)
-	local t_dir = get_used_dir(dir)
-	local dir_typ = t_dir[1]
-	if t_dir[3] == "+" then
-		f_tab = {1, range}
-	else
-		f_tab = {-range, -1}
-	end
-	local d_ch = t_dir[2]
-	if dir_typ == "x" then
-		for d = f_tab[1],f_tab[2],1 do
-			local x = d
-			local ytab = node_tab(d_ch.y, d)
-			local ztab = node_tab(d_ch.z, d)
-			for _, y in pairs(ytab) do
-				for _, z in pairs(ztab) do
-					laser_node({x = pos.x + x, y = pos.y + y, z = pos.z + z}, player)
-				end
-			end
-		end
-		return
-	end
-	if dir_typ == "y" then
-		for d = f_tab[1], f_tab[2] do
-			local xtab = node_tab(d_ch.x, d)
-			local y = d
-			local ztab = node_tab(d_ch.z, d)
-			for _, x in pairs(xtab) do
-				for _, z in pairs(ztab) do
-					laser_node({x = pos.x + x, y = pos.y + y, z = pos.z + z}, player)
-				end
-			end
-		end
-		return
-	end
-	for d = f_tab[1], f_tab[2] do
-		local xtab = node_tab(d_ch.x, d)
-		local ytab = node_tab(d_ch.y, d)
-		local z = d
-		for _, x in pairs(xtab) do
-			for _, y in pairs(ytab) do
-				laser_node({x = pos.x + x, y = pos.y + y, z = pos.z + z}, player)
-			end
-		end
-	end
-end
-
+local no_destroy = {
+	["air"] = true,
+	["default:lava_source"] = true,
+	["default:lava_flowing"] = true,
+}
 local function laser_shoot(player, range, particle_texture, sound)
-	local playerpos = player:getpos()
+	local player_pos = player:getpos()
+	local player_name = player:get_player_name()
 	local dir = player:get_look_dir()
 
-	local startpos = {x = playerpos.x, y = playerpos.y + 1.6, z = playerpos.z}
-	local mult_dir = vector.multiply(dir, 50)
-	minetest.add_particle(startpos, dir, mult_dir, range / 11, 1, false, particle_texture)
-	laser_nodes(vector.round(startpos), dir, player, range)
-	minetest.sound_play(sound, {pos = playerpos, gain = 1.0, max_hear_distance = range})
+	local start_pos = vector.new(player_pos)
+	-- Adjust to head height
+	start_pos.y = start_pos.y + 1.9
+	minetest.add_particle({
+		pos = startpos,
+		vel = dir,
+		acc = 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 technic.trace_node_ray(start_pos, dir, range) do
+		if minetest.is_protected(pos, player_name) then
+			minetest.record_protection_violation(pos, player_name)
+			break
+		end
+		local node = minetest.get_node_or_nil(pos)
+		if not node then
+			break
+		end
+		if not no_destroy[node.name] then
+			laser_node(pos, node, player)
+		end
+	end
 end
 
 
@@ -178,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