Vanessa Dannenberg
2018-10-31 44cb8df048e09b64214f59db73a3fd23cfe12e77
commit | author | age
f90915 1 local mining_lasers_list = {
a6dae8 2 --    {<num>, <range of the laser shots>, <max_charge>, <charge_per_shot>},
BM 3     {"1", 7, 50000, 1000},
4     {"2", 14, 200000, 2000},
5     {"3", 21, 650000, 3000},
f90915 6 }
f013d2 7 local allow_entire_discharging = true
f90915 8
H 9 local S = technic.getter
10
2d7c1d 11 minetest.register_craft({
f013d2 12     output = "technic:laser_mk1",
2d7c1d 13     recipe = {
44cb8d 14         {"default:diamond", "basic_materials:brass_ingot",        "default:obsidian_glass"},
VD 15         {"",                "basic_materials:brass_ingot",        "technic:red_energy_crystal"},
f013d2 16         {"",                "",                           "default:copper_ingot"},
49052d 17     }
BM 18 })
19 minetest.register_craft({
f013d2 20     output = "technic:laser_mk2",
49052d 21     recipe = {
f013d2 22         {"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk1"},
H 23         {"",                "technic:carbon_steel_ingot", "technic:green_energy_crystal"},
24         {"",                "",                           "default:copper_ingot"},
49052d 25     }
BM 26 })
27 minetest.register_craft({
f013d2 28     output = "technic:laser_mk3",
49052d 29     recipe = {
f013d2 30         {"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk2"},
H 31         {"",                "technic:carbon_steel_ingot", "technic:blue_energy_crystal"},
32         {"",                "",                           "default:copper_ingot"},
2d7c1d 33     }
S 34 })
35
42d008 36 local function laser_node(pos, node, player)
S 37     local def = minetest.registered_nodes[node.name]
f013d2 38     if def.liquidtype ~= "none" and def.buildable_to then
f90915 39         minetest.remove_node(pos)
4d1f97 40         minetest.add_particle({
H 41             pos = pos,
f013d2 42             velocity = {x = 0, y = 1.5 + math.random(), z = 0},
H 43             acceleration = {x = 0, y = -1, z = 0},
42d008 44             size = 6 + math.random() * 2,
S 45             texture = "smoke_puff.png^[transform" .. math.random(0, 7),
4d1f97 46         })
f90915 47         return
H 48     end
42d008 49     minetest.node_dig(pos, node, player)
f90915 50 end
H 51
f013d2 52 local keep_node = {air = true}
H 53 local function can_keep_node(name)
54     if keep_node[name] ~= nil then
55         return keep_node[name]
56     end
57     keep_node[name] = minetest.get_item_group(name, "hot") ~= 0
58     return keep_node[name]
59 end
60
f90915 61 local function laser_shoot(player, range, particle_texture, sound)
42d008 62     local player_pos = player:getpos()
S 63     local player_name = player:get_player_name()
f90915 64     local dir = player:get_look_dir()
H 65
42d008 66     local start_pos = vector.new(player_pos)
S 67     -- Adjust to head height
f013d2 68     start_pos.y = start_pos.y + (player:get_properties().eye_height or 1.625)
4d1f97 69     minetest.add_particle({
f013d2 70         pos = start_pos,
cfd4cb 71         velocity = dir,
S 72         acceleration = vector.multiply(dir, 50),
f013d2 73         expirationtime = (math.sqrt(1 + 100 * (range + 0.4)) - 1) / 50,
4d1f97 74         size = 1,
42d008 75         texture = particle_texture .. "^[transform" .. math.random(0, 7),
4d1f97 76     })
42d008 77     minetest.sound_play(sound, {pos = player_pos, max_hear_distance = range})
1475ee 78     for pos in technic.trace_node_ray_fat(start_pos, dir, range) do
42d008 79         if minetest.is_protected(pos, player_name) then
S 80             minetest.record_protection_violation(pos, player_name)
81             break
82         end
f013d2 83         local node = minetest.get_node(pos)
H 84         if node.name == "ignore"
85                 or not minetest.registered_nodes[node.name] then
42d008 86             break
S 87         end
f013d2 88         if not can_keep_node(node.name) then
42d008 89             laser_node(pos, node, player)
S 90         end
4d1f97 91     end
f90915 92 end
H 93
94 for _, m in pairs(mining_lasers_list) do
95     technic.register_power_tool("technic:laser_mk"..m[1], m[3])
96     minetest.register_tool("technic:laser_mk"..m[1], {
97         description = S("Mining Laser Mk%d"):format(m[1]),
98         inventory_image = "technic_mining_laser_mk"..m[1]..".png",
f013d2 99         range = 0,
f90915 100         stack_max = 1,
99fd5d 101         wear_represents = "technic_RE_charge",
00d7c9 102         on_refill = technic.refill_RE_charge,
f90915 103         on_use = function(itemstack, user)
5cf765 104             local meta = minetest.deserialize(itemstack:get_metadata())
f013d2 105             if not meta or not meta.charge or meta.charge == 0 then
f90915 106                 return
H 107             end
a6dae8 108
f013d2 109             local range = m[2]
H 110             if meta.charge < m[4] then
111                 if not allow_entire_discharging then
112                     return
b8c902 113                 end
f013d2 114                 -- If charge is too low, give the laser a shorter range
H 115                 range = range * meta.charge / m[4]
116             end
117             laser_shoot(user, range, "technic_laser_beam_mk" .. m[1] .. ".png",
118                 "technic_laser_mk" .. m[1])
119             if not technic.creative_mode then
120                 meta.charge = math.max(meta.charge - m[4], 0)
121                 technic.set_RE_wear(itemstack, meta.charge, m[3])
122                 itemstack:set_metadata(minetest.serialize(meta))
f90915 123             end
H 124             return itemstack
125         end,
126     })
127 end