2022-06-12 21:45:35 +02:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
|
|
minetest.register_tool("mcl_spyglass:spyglass",{
|
2022-06-13 12:24:27 +02:00
|
|
|
description = S("Spyglass"),
|
|
|
|
_doc_items_longdesc = S("A spyglass is an item that can be used for zooming in on specific locations."),
|
|
|
|
inventory_image = "mcl_spyglass.png",
|
|
|
|
stack_max = 1,
|
|
|
|
_mcl_toollike_wield = true,
|
2022-06-12 21:45:35 +02:00
|
|
|
})
|
|
|
|
|
2022-06-13 12:25:14 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "mcl_spyglass:spyglass",
|
|
|
|
recipe = {
|
|
|
|
{"mcl_amethyst:amethyst_shard"},
|
|
|
|
{"mcl_copper:copper_ingot"},
|
|
|
|
{"mcl_copper:copper_ingot"},
|
|
|
|
}
|
|
|
|
})
|
2022-06-12 21:45:35 +02:00
|
|
|
|
2023-12-10 00:14:16 +01:00
|
|
|
mcl_fovapi.register_modifier({
|
|
|
|
name = "spyglass",
|
|
|
|
fov_factor = 8,
|
|
|
|
time = 0.1,
|
2023-12-13 00:08:35 +01:00
|
|
|
reset_time = 0,
|
2023-12-10 00:14:16 +01:00
|
|
|
is_multiplier = false,
|
|
|
|
exclusive = true,
|
|
|
|
})
|
2023-12-03 14:29:53 +01:00
|
|
|
|
2022-06-12 21:45:35 +02:00
|
|
|
local spyglass_scope = {}
|
|
|
|
|
|
|
|
local function add_scope(player)
|
2022-06-13 12:24:27 +02:00
|
|
|
local wielditem = player:get_wielded_item()
|
|
|
|
if wielditem:get_name() == "mcl_spyglass:spyglass" then
|
|
|
|
spyglass_scope[player] = player:hud_add({
|
|
|
|
hud_elem_type = "image",
|
|
|
|
position = {x = 0.5, y = 0.5},
|
|
|
|
scale = {x = -100, y = -100},
|
|
|
|
text = "mcl_spyglass_scope.png",
|
|
|
|
})
|
|
|
|
player:hud_set_flags({wielditem = false})
|
2023-12-24 05:48:41 +01:00
|
|
|
if mcl_util.is_it_christmas() then
|
|
|
|
local time = minetest.get_timeofday()
|
|
|
|
if (time < 0.01 or time > 0.99) and player:get_look_vertical() < -1.335 then
|
|
|
|
player:set_moon({texture = "mcl_moon_special.png"})
|
|
|
|
end
|
|
|
|
end
|
2022-06-13 12:24:27 +02:00
|
|
|
end
|
2022-06-12 21:45:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function remove_scope(player)
|
2022-06-13 12:24:27 +02:00
|
|
|
if spyglass_scope[player] then
|
|
|
|
player:hud_remove(spyglass_scope[player])
|
|
|
|
spyglass_scope[player] = nil
|
|
|
|
player:hud_set_flags({wielditem = true})
|
2023-12-03 14:29:53 +01:00
|
|
|
mcl_fovapi.remove_modifier(player, "spyglass") -- use the api to remove the FOV effect.
|
|
|
|
-- old code: player:set_fov(86.1)
|
2022-06-13 12:24:27 +02:00
|
|
|
end
|
2022-06-12 21:45:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
controls.register_on_press(function(player, key)
|
2023-12-25 23:50:06 +01:00
|
|
|
if key ~= "RMB" and key ~= "zoom" then return end
|
|
|
|
if spyglass_scope[player] == nil then
|
|
|
|
add_scope(player)
|
|
|
|
end
|
2022-06-12 21:45:35 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
controls.register_on_release(function(player, key, time)
|
2023-12-25 23:50:06 +01:00
|
|
|
if key ~= "RMB" and key ~= "zoom" then return end
|
|
|
|
local ctrl = player:get_player_control()
|
|
|
|
if key == "RMB" and ctrl.zoom or key == "zoom" and ctrl.place then return end
|
2022-06-13 12:24:27 +02:00
|
|
|
remove_scope(player)
|
2022-06-12 21:45:35 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
controls.register_on_hold(function(player, key, time)
|
2023-12-25 23:50:06 +01:00
|
|
|
if key ~= "RMB" and key ~= "zoom" then return end
|
2022-06-13 12:24:27 +02:00
|
|
|
local wielditem = player:get_wielded_item()
|
|
|
|
if wielditem:get_name() == "mcl_spyglass:spyglass" then
|
2023-12-03 14:29:53 +01:00
|
|
|
mcl_fovapi.apply_modifier(player, "spyglass") -- apply the FOV effect.
|
|
|
|
-- old code: player:set_fov(8, false, 0.1)
|
2022-06-13 12:24:27 +02:00
|
|
|
if spyglass_scope[player] == nil then
|
|
|
|
add_scope(player)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
remove_scope(player)
|
|
|
|
end
|
2022-06-12 21:45:35 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_dieplayer(function(player)
|
2022-06-13 12:24:27 +02:00
|
|
|
remove_scope(player)
|
2022-06-12 21:45:35 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
2022-06-13 12:24:27 +02:00
|
|
|
spyglass_scope[player] = nil
|
2022-06-12 21:45:35 +02:00
|
|
|
end)
|