Initial commit.
commit
d8fd8533cf
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "deps/utils"]
|
||||||
|
path = deps/utils
|
||||||
|
url = https://github.com/RobertZenz/minetest-australopithecus-utils.git
|
|
@ -0,0 +1,23 @@
|
||||||
|
minetest-australopithecus-sneak-cam
|
||||||
|
===================================
|
||||||
|
|
||||||
|
A simple system that lowers the viewpoint of the players when they are sneaking.
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
The systems activates itself, you just need to add the mod to the subgame.
|
||||||
|
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
The system can be configured by adding settings to `minetest.conf` file.
|
||||||
|
|
||||||
|
# If the system should be active or not, defaults to true.
|
||||||
|
sneakcam_activate = true
|
||||||
|
|
||||||
|
# The offset by which the viewpoing is lowered, defaults to 1.65.
|
||||||
|
sneakcam_offset = 1.65
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit fed191891f263d353cd7d8484e1692fa3c14325f
|
|
@ -0,0 +1 @@
|
||||||
|
utils
|
|
@ -0,0 +1,35 @@
|
||||||
|
--[[
|
||||||
|
Copyright (c) 2015, Robert 'Bobby' Zenz
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
--]]
|
||||||
|
|
||||||
|
|
||||||
|
-- Load all files
|
||||||
|
local base_path = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
|
dofile(base_path .. "/sneakcam.lua")
|
||||||
|
|
||||||
|
|
||||||
|
sneakcam.activate()
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
--[[
|
||||||
|
Copyright (c) 2015, Robert 'Bobby' Zenz
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
--]]
|
||||||
|
|
||||||
|
|
||||||
|
--- The main object for the sneak cam mod.
|
||||||
|
sneakcam = {
|
||||||
|
--- The offset by which the camera is lowered if the player is sneaking.
|
||||||
|
offset = settings.get_number("sneakcam_offset", 1.65),
|
||||||
|
|
||||||
|
--- The state of all players the last time the system has seen them.
|
||||||
|
sneak_state = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
--- Activates the sneakcam system. But checks if it is has been disabled via
|
||||||
|
-- the configuration.
|
||||||
|
function sneakcam.activate()
|
||||||
|
if settings.get_bool("sneakcam_activate", true) then
|
||||||
|
minetest.register_globalstep(sneakcam.update_player_cams)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Updates the camera of the given player.
|
||||||
|
--
|
||||||
|
-- @param player The Player object.
|
||||||
|
function sneakcam.update_player_cam(player)
|
||||||
|
local controls = player:get_player_control()
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
|
if sneakcam.sneak_state[player_name] == nil then
|
||||||
|
sneakcam.sneak_state[player_name] = controls.sneak
|
||||||
|
elseif controls.sneak ~= sneakcam.sneak_state[player_name] then
|
||||||
|
local eye_offset_first, eye_offset_third = player:get_eye_offset()
|
||||||
|
|
||||||
|
if controls.sneak then
|
||||||
|
eye_offset_first.y = eye_offset_first.y - sneakcam.offset
|
||||||
|
else
|
||||||
|
eye_offset_first.y = eye_offset_first.y + sneakcam.offset
|
||||||
|
end
|
||||||
|
|
||||||
|
player:set_eye_offset(eye_offset_first, eye_offset_third)
|
||||||
|
sneakcam.sneak_state[player_name] = controls.sneak
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Updates the cameras of players.
|
||||||
|
function sneakcam.update_player_cams()
|
||||||
|
for index, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
sneakcam.update_player_cam(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../deps/utils/utils
|
Loading…
Reference in New Issue