mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 15:00:18 +01:00
Add binoculars mod with binoculars item to allow zoom
Uses the new player object property 'can zoom'. In survival mode, use of zoom requires the binoculars item in inventory. Zoom is automatically allowed in creative mode and for players with the 'creative' privilege. The binoculars.update_player_property() function is global so can be redefined by a mod for alternative behaviour.
This commit is contained in:
parent
eb5a5b56e1
commit
cc371ac726
35
mods/binoculars/README.txt
Normal file
35
mods/binoculars/README.txt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Minetest Game mod: binoculars
|
||||||
|
=============================
|
||||||
|
See license.txt for license information.
|
||||||
|
|
||||||
|
Authors of source code
|
||||||
|
----------------------
|
||||||
|
paramat (MIT)
|
||||||
|
|
||||||
|
Authors of media (textures)
|
||||||
|
---------------------------
|
||||||
|
paramat (CC BY-SA 3.0):
|
||||||
|
binoculars_binoculars.png
|
||||||
|
|
||||||
|
Crafting
|
||||||
|
--------
|
||||||
|
binoculars:binoculars
|
||||||
|
|
||||||
|
default:obsidian_glass O
|
||||||
|
default:bronze_ingot B
|
||||||
|
|
||||||
|
O_O
|
||||||
|
BBB
|
||||||
|
O_O
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
In survival mode, use of zoom requires the binoculars item in your inventory.
|
||||||
|
It can take up to 5 seconds for adding to or removal from inventory to have an
|
||||||
|
effect, however to instantly allow the use of zoom 'use' (leftclick) the item.
|
||||||
|
|
||||||
|
Zoom is automatically allowed in creative mode and for any player with the
|
||||||
|
'creative' privilege.
|
||||||
|
|
||||||
|
The 'binoculars.update_player_property()' function is global so can be
|
||||||
|
redefined by a mod for alternative behaviour.
|
2
mods/binoculars/depends.txt
Normal file
2
mods/binoculars/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
default
|
||||||
|
creative?
|
69
mods/binoculars/init.lua
Normal file
69
mods/binoculars/init.lua
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
-- Mod global namespace
|
||||||
|
|
||||||
|
binoculars = {}
|
||||||
|
|
||||||
|
|
||||||
|
-- Cache creative mode setting
|
||||||
|
|
||||||
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||||
|
|
||||||
|
|
||||||
|
-- Update player property
|
||||||
|
-- Global to allow overriding
|
||||||
|
|
||||||
|
function binoculars.update_player_property(player)
|
||||||
|
local creative_enabled =
|
||||||
|
(creative and creative.is_enabled_for(player:get_player_name())) or
|
||||||
|
creative_mode_cache
|
||||||
|
|
||||||
|
if creative_enabled or
|
||||||
|
player:get_inventory():contains_item("main", "binoculars:binoculars") then
|
||||||
|
player:set_properties({can_zoom = true})
|
||||||
|
else
|
||||||
|
player:set_properties({can_zoom = false})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Set player property 'on joinplayer'
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
binoculars.update_player_property(player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
-- Cyclic update of player property
|
||||||
|
|
||||||
|
local function cyclic_update()
|
||||||
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
binoculars.update_player_property(player)
|
||||||
|
end
|
||||||
|
minetest.after(4.7, cyclic_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.after(4.7, cyclic_update)
|
||||||
|
|
||||||
|
|
||||||
|
-- Binoculars item
|
||||||
|
|
||||||
|
minetest.register_craftitem("binoculars:binoculars", {
|
||||||
|
description = "Binoculars",
|
||||||
|
inventory_image = "binoculars_binoculars.png",
|
||||||
|
stack_max = 1,
|
||||||
|
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
binoculars.update_player_property(user)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- Crafting
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "binoculars:binoculars",
|
||||||
|
recipe = {
|
||||||
|
{"default:obsidian_glass", "", "default:obsidian_glass"},
|
||||||
|
{"default:bronze_ingot", "default:bronze_ingot", "default:bronze_ingot"},
|
||||||
|
{"default:obsidian_glass", "", "default:obsidian_glass"},
|
||||||
|
}
|
||||||
|
})
|
59
mods/binoculars/license.txt
Normal file
59
mods/binoculars/license.txt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
License of source code
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (C) 2017 paramat
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more details:
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
|
||||||
|
Licenses of media (textures)
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||||
|
Copyright (C) 2017 paramat
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
Share — copy and redistribute the material in any medium or format.
|
||||||
|
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||||
|
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
|
||||||
|
Attribution — You must give appropriate credit, provide a link to the license, and
|
||||||
|
indicate if changes were made. You may do so in any reasonable manner, but not in any way
|
||||||
|
that suggests the licensor endorses you or your use.
|
||||||
|
|
||||||
|
ShareAlike — If you remix, transform, or build upon the material, you must distribute
|
||||||
|
your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that
|
||||||
|
legally restrict others from doing anything the license permits.
|
||||||
|
|
||||||
|
Notices:
|
||||||
|
|
||||||
|
You do not have to comply with the license for elements of the material in the public
|
||||||
|
domain or where your use is permitted by an applicable exception or limitation.
|
||||||
|
No warranties are given. The license may not give you all of the permissions necessary
|
||||||
|
for your intended use. For example, other rights such as publicity, privacy, or moral
|
||||||
|
rights may limit how you use the material.
|
||||||
|
|
||||||
|
For more details:
|
||||||
|
http://creativecommons.org/licenses/by-sa/3.0/
|
BIN
mods/binoculars/textures/binoculars_binoculars.png
Normal file
BIN
mods/binoculars/textures/binoculars_binoculars.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 219 B |
Loading…
Reference in New Issue
Block a user