From 2e2b22dc15d192efe09fe3849f536d4a2c123cf9 Mon Sep 17 00:00:00 2001 From: epCode Date: Fri, 18 Dec 2020 16:43:42 -0800 Subject: [PATCH] Player properties for sneaking --- mods/PLAYER/mcl_playerplus/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index f18e6adfc..97e91ad42 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -3,6 +3,7 @@ local S = minetest.get_translator("mcl_playerplus") -- Internal player state local mcl_playerplus_internal = {} + local def = {} local time = 0 @@ -20,11 +21,22 @@ minetest.register_globalstep(function(dtime) -- Update jump status immediately since we need this info in real time. -- WARNING: This section is HACKY as hell since it is all just based on heuristics. for _,player in pairs(minetest.get_connected_players()) do + local controls = player:get_player_control() name = player:get_player_name() -- controls head bone pitch = degrees(player:get_look_vertical()) * -1 - player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0)) + if controls.sneak then + player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0)) + if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.40,0.35} then + player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.35,0.35}, eye_height = 1.35}) + end + else + player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0)) + if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.8,0.35} then + player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.65}) + end + end if mcl_playerplus_internal[name].jump_cooldown > 0 then mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime