update
@ -1,12 +1,14 @@
|
||||
--license LGPLv2+, for the changes: WTFPL
|
||||
--license LGPLv2+
|
||||
|
||||
local r_corr = 0.25 --remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
|
||||
local laser_mk2_range = 11 --range of the laser shots
|
||||
local laser_mk3_range = 30
|
||||
--local laser_mk2_max_charge = 40000*4
|
||||
--local laser_mk3_max_charge = laser_mk2_max_charge*4
|
||||
--technic.register_power_tool("technic:laser_mk2", laser_mk2_max_charge)
|
||||
--technic.register_power_tool("technic:laser_mk3", laser_mk3_max_charge)
|
||||
local mk1_charge = 40000
|
||||
|
||||
local mining_lasers_list = {
|
||||
-- {<num>, <range of the laser shots>, <max_charge>},
|
||||
{"1", 7, mk1_charge},
|
||||
{"2", 11, mk1_charge*4},
|
||||
{"3", 30, mk1_charge*16},
|
||||
}
|
||||
|
||||
local f_1 = 0.5-r_corr
|
||||
local f_2 = 0.5+r_corr
|
||||
@ -44,96 +46,7 @@ local function node_tab(z, d)
|
||||
return {n1, n2}
|
||||
end
|
||||
|
||||
local function lazer_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 = {0, range}
|
||||
else
|
||||
f_tab = {-range,0}
|
||||
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 ipairs(ytab) do
|
||||
for _,z in ipairs(ztab) do
|
||||
lazer_it({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],1 do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local y = d
|
||||
local ztab = node_tab(d_ch.z, d)
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,z in ipairs(ztab) do
|
||||
lazer_it({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],1 do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local ytab = node_tab(d_ch.y, d)
|
||||
local z = d
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,y in ipairs(ytab) do
|
||||
lazer_it({x=pos.x+x, y=pos.y+y, z=pos.z+z}, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function laser_shoot(player, range, particle_texture, sound)
|
||||
local t1 = os.clock()
|
||||
|
||||
local playerpos=player:getpos()
|
||||
local dir=player:get_look_dir()
|
||||
|
||||
local startpos = {x=playerpos.x, y=playerpos.y+1.6, z=playerpos.z}
|
||||
local a = {x=dir.x*50, y=dir.y*50, z=dir.z*50}
|
||||
minetest.add_particle(startpos, dir, a, range/11, 1, false, particle_texture)
|
||||
lazer_nodes(vector.round(startpos), dir, player, range)
|
||||
minetest.sound_play(sound, {pos = playerpos, gain = 1.0, max_hear_distance = range})
|
||||
|
||||
print("[extrablocks] <mining_laser> my shot was calculated after "..tostring(os.clock()-t1).."s")
|
||||
return true --?
|
||||
end
|
||||
|
||||
|
||||
|
||||
for _,m in ipairs({
|
||||
{"2", laser_mk2_range, laser_mk2_max_charge},
|
||||
{"3", laser_mk3_range, laser_mk3_max_charge},
|
||||
}) do
|
||||
minetest.register_tool("extrablocks:laser_mk"..m[1], {
|
||||
description = "Mining Laser MK"..m[1],
|
||||
inventory_image = "extrablocks_mining_laser_mk"..m[1]..".png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user)
|
||||
--[[local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - 400 > 0 then]]
|
||||
laser_shoot(user, m[2], "extrablocks_laser_beam_mk"..m[1]..".png", "extrablocks_laser_mk"..m[1])
|
||||
--[[meta.charge = meta.charge - 400
|
||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
end
|
||||
return itemstack]]
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function lazer_it(pos, player)
|
||||
local function laser_node(pos, player)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "air"
|
||||
or node.name == "ignore"
|
||||
@ -150,6 +63,92 @@ function lazer_it(pos, player)
|
||||
return
|
||||
end
|
||||
if player then
|
||||
minetest.node_dig(pos,node,player)
|
||||
minetest.node_dig(pos, node, player)
|
||||
end
|
||||
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 = {0, range}
|
||||
else
|
||||
f_tab = {-range,0}
|
||||
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 ipairs(ytab) do
|
||||
for _,z in ipairs(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],1 do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local y = d
|
||||
local ztab = node_tab(d_ch.z, d)
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,z in ipairs(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],1 do
|
||||
local xtab = node_tab(d_ch.x, d)
|
||||
local ytab = node_tab(d_ch.y, d)
|
||||
local z = d
|
||||
for _,x in ipairs(xtab) do
|
||||
for _,y in ipairs(ytab) do
|
||||
laser_node({x=pos.x+x, y=pos.y+y, z=pos.z+z}, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function laser_shoot(player, range, particle_texture, sound)
|
||||
local t1 = os.clock()
|
||||
|
||||
local playerpos=player:getpos()
|
||||
local dir=player:get_look_dir()
|
||||
|
||||
local startpos = {x=playerpos.x, y=playerpos.y+1.6, z=playerpos.z}
|
||||
local a = {x=dir.x*50, y=dir.y*50, z=dir.z*50}
|
||||
minetest.add_particle(startpos, dir, a, 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})
|
||||
|
||||
print("[technic] <mining_laser> my shot was calculated after "..tostring(os.clock()-t1).."s")
|
||||
return true --Why?
|
||||
end
|
||||
|
||||
|
||||
for _,m in ipairs(mining_lasers_list) do
|
||||
-- technic.register_power_tool("technic:laser_mk"..m[1], m[3])
|
||||
minetest.register_tool("extrablocks:laser_mk"..m[1], {
|
||||
description = "Mining Laser MK"..m[1],
|
||||
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user)
|
||||
--[[local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - 400 > 0 then]]
|
||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
||||
--[[meta.charge = meta.charge - 400
|
||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
end
|
||||
return itemstack]]
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
BIN
sounds/technic_laser_mk1.0.ogg
Normal file
BIN
sounds/technic_laser_mk1.1.ogg
Normal file
Before Width: | Height: | Size: 458 B |
BIN
textures/technic_laser_beam_mk1.png
Normal file
After Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 638 B After Width: | Height: | Size: 638 B |
Before Width: | Height: | Size: 547 B After Width: | Height: | Size: 547 B |
BIN
textures/technic_mining_laser_mk1.png
Normal file
After Width: | Height: | Size: 216 B |
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B |
BIN
textures/technic_mining_laser_mk3.png
Normal file
After Width: | Height: | Size: 312 B |