technic/technic/tools/mining_lasers.lua

122 lines
3.5 KiB
Lua
Raw Normal View History

2013-10-27 22:01:13 +01:00
local mining_lasers_list = {
-- {<num>, <range of the laser shots>, <max_charge>, <charge_per_shot>},
{"1", 7, 50000, 1000},
{"2", 14, 200000, 2000},
{"3", 21, 650000, 3000},
2013-10-27 22:01:13 +01:00
}
local S = technic.getter
minetest.register_craft({
output = 'technic:laser_mk1',
recipe = {
{'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', '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', 'technic:carbon_steel_ingot', 'technic:laser_mk2'},
{'', 'technic:carbon_steel_ingot', 'technic:blue_energy_crystal'},
{'', '', 'default:copper_ingot'},
}
})
2014-09-16 15:36:13 +02:00
local function table_icontains(t, v)
for i = 1,#t do
if v == t[i] then
return true
2013-10-27 22:01:13 +01:00
end
end
2014-09-16 15:36:13 +02:00
return false
2013-10-27 22:01:13 +01:00
end
local function laser_node(pos, player)
local node = minetest.get_node(pos)
2014-09-16 15:36:13 +02:00
if table_icontains({"air", "ignore", "default:lava_source", "default:lava_flowing"}, node.name) then
2013-10-27 22:01:13 +01:00
return
end
2014-09-16 15:36:13 +02:00
local pname = player:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
2014-09-16 15:36:13 +02:00
if table_icontains({"default:water_flowing", "default:water_source"}, node.name) then
2013-10-27 22:01:13 +01:00
minetest.remove_node(pos)
2014-09-16 15:36:13 +02:00
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),
})
2013-10-27 22:01:13 +01:00
return
end
if player then
minetest.node_dig(pos, node, player)
end
end
2014-09-16 15:36:13 +02:00
if not vector.line then
dofile(technic.modpath.."/tools/vector_line.lua")
2013-10-27 22:01:13 +01:00
end
local function laser_shoot(player, range, particle_texture, sound)
local playerpos = player:getpos()
local dir = player:get_look_dir()
2014-09-16 15:36:13 +02:00
local startpos = {x = playerpos.x, y = playerpos.y + 1.625, z = playerpos.z}
2013-10-27 22:01:13 +01:00
local mult_dir = vector.multiply(dir, 50)
2014-09-16 15:36:13 +02:00
minetest.add_particle({
pos = startpos,
vel = dir,
acc = mult_dir,
expirationtime = range / 11,
size = 1,
texture = particle_texture.."^[transform"..math.random(0,7),
})
for _,pos in ipairs(vector.line(vector.round(startpos), dir, range)) do
laser_node(pos, player)
end
minetest.sound_play(sound, {pos = playerpos, max_hear_distance = range})
2013-10-27 22:01:13 +01:00
end
for _, m in pairs(mining_lasers_list) do
technic.register_power_tool("technic:laser_mk"..m[1], m[3])
minetest.register_tool("technic:laser_mk"..m[1], {
description = S("Mining Laser Mk%d"):format(m[1]),
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
stack_max = 1,
wear_represents = "technic_RE_charge",
on_refill = technic.refill_RE_charge,
2013-10-27 22:01:13 +01:00
on_use = function(itemstack, user)
2013-12-17 19:56:37 +01:00
local meta = minetest.deserialize(itemstack:get_metadata())
2013-10-27 22:01:13 +01:00
if not meta or not meta.charge then
return
end
-- If there's enough charge left, fire the laser
if meta.charge >= m[4] then
meta.charge = meta.charge - m[4]
2013-10-27 22:01:13 +01:00
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])
2013-12-17 19:56:37 +01:00
itemstack:set_metadata(minetest.serialize(meta))
2013-10-27 22:01:13 +01:00
end
return itemstack
end,
})
end