mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-10 20:40:27 +01:00
mining lasers: add an option to allow using the mining laser if its charge is smaller than the laser shot charge by reducing the range and cleanup code a bit
This commit is contained in:
parent
ebe2ac4585
commit
d2029806ef
|
@ -4,31 +4,32 @@ local mining_lasers_list = {
|
||||||
{"2", 14, 200000, 2000},
|
{"2", 14, 200000, 2000},
|
||||||
{"3", 21, 650000, 3000},
|
{"3", 21, 650000, 3000},
|
||||||
}
|
}
|
||||||
|
local allow_entire_discharging = true
|
||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:laser_mk1',
|
output = "technic:laser_mk1",
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:diamond', 'technic:brass_ingot', 'default:obsidian_glass'},
|
{"default:diamond", "technic:brass_ingot", "default:obsidian_glass"},
|
||||||
{'', 'technic:brass_ingot', 'technic:red_energy_crystal'},
|
{"", "technic:brass_ingot", "technic:red_energy_crystal"},
|
||||||
{'', '', 'default:copper_ingot'},
|
{"", "", "default:copper_ingot"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:laser_mk2',
|
output = "technic:laser_mk2",
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk1'},
|
{"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk1"},
|
||||||
{'', 'technic:carbon_steel_ingot', 'technic:green_energy_crystal'},
|
{"", "technic:carbon_steel_ingot", "technic:green_energy_crystal"},
|
||||||
{'', '', 'default:copper_ingot'},
|
{"", "", "default:copper_ingot"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'technic:laser_mk3',
|
output = "technic:laser_mk3",
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk2'},
|
{"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk2"},
|
||||||
{'', 'technic:carbon_steel_ingot', 'technic:blue_energy_crystal'},
|
{"", "technic:carbon_steel_ingot", "technic:blue_energy_crystal"},
|
||||||
{'', '', 'default:copper_ingot'},
|
{"", "", "default:copper_ingot"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -143,7 +144,6 @@ local function laser_shoot(player, range, particle_texture, sound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
for _, m in pairs(mining_lasers_list) do
|
for _, m in pairs(mining_lasers_list) do
|
||||||
technic.register_power_tool("technic:laser_mk"..m[1], m[3])
|
technic.register_power_tool("technic:laser_mk"..m[1], m[3])
|
||||||
minetest.register_tool("technic:laser_mk"..m[1], {
|
minetest.register_tool("technic:laser_mk"..m[1], {
|
||||||
|
@ -154,21 +154,27 @@ for _, m in pairs(mining_lasers_list) do
|
||||||
on_refill = technic.refill_RE_charge,
|
on_refill = technic.refill_RE_charge,
|
||||||
on_use = function(itemstack, user)
|
on_use = function(itemstack, user)
|
||||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||||
if not meta or not meta.charge then
|
if not meta
|
||||||
|
or not meta.charge
|
||||||
|
or meta.charge == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If there's enough charge left, fire the laser
|
local range = m[2]
|
||||||
if meta.charge >= m[4] then
|
if meta.charge < m[4] then
|
||||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
if not allow_entire_discharging then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- If charge is too low, give the laser a shorter range
|
||||||
|
range = range * meta.charge / m[4]
|
||||||
|
end
|
||||||
|
laser_shoot(user, range, "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
||||||
if not technic.creative_mode then
|
if not technic.creative_mode then
|
||||||
meta.charge = meta.charge - m[4]
|
meta.charge = math.max(meta.charge - m[4], 0)
|
||||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
itemstack:set_metadata(minetest.serialize(meta))
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user