Zefram
2014-07-07 5e4a87b92599aa0fc9a56081209c930d08a2c3bd
technic/tools/mining_lasers.lua
@@ -1,18 +1,43 @@
local r_corr = 0.25 -- Remove a bit more nodes (if shooting diagonal) to let it look like a hole (sth like antialiasing)
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},
--   {<num>, <range of the laser shots>, <max_charge>, <charge_per_shot>},
   {"1", 7, 50000, 1000},
   {"2", 14, 200000, 2000},
   {"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', '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'},
   }
})
local function get_used_dir(dir)
   local abs_dir = {x = math.abs(dir.x),
@@ -57,6 +82,10 @@
   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
      minetest.remove_node(pos)
@@ -78,9 +107,9 @@
   local t_dir = get_used_dir(dir)
   local dir_typ = t_dir[1]
   if t_dir[3] == "+" then
      f_tab = {0, range}
      f_tab = {1, range}
   else
      f_tab = {-range,0}
      f_tab = {-range, -1}
   end
   local d_ch = t_dir[2]
   if dir_typ == "x" then
@@ -139,16 +168,20 @@
      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,
      on_use = function(itemstack, user)
         local meta = get_item_meta(itemstack:get_metadata())
         local meta = minetest.deserialize(itemstack:get_metadata())
         if not meta or not meta.charge then
            return
         end
         if meta.charge - 400 > 0 then
         -- 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])
            meta.charge = meta.charge - 400
            technic.set_RE_wear(itemstack, meta.charge, m[3])
            itemstack:set_metadata(set_item_meta(meta))
            itemstack:set_metadata(minetest.serialize(meta))
         end
         return itemstack
      end,