From 2c4eae353c14abc77bde38c994b2cd14389e17db Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 7 May 2018 20:10:53 +0200 Subject: [PATCH] Use mcl_playerphysics to handle player physics This fixes some issues with speed overrides and gets rid of ugly workarounds. --- mods/ITEMS/mcl_beds/depends.txt | 1 + mods/ITEMS/mcl_beds/functions.lua | 7 ++++--- mods/PLAYER/mcl_playerplus/depends.txt | 1 + mods/PLAYER/mcl_playerplus/init.lua | 28 ++++++++------------------ mods/PLAYER/mcl_sprint/depends.txt | 1 + mods/PLAYER/mcl_sprint/init.lua | 17 +++++++--------- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/mods/ITEMS/mcl_beds/depends.txt b/mods/ITEMS/mcl_beds/depends.txt index 17d201545..ad8c41c02 100644 --- a/mods/ITEMS/mcl_beds/depends.txt +++ b/mods/ITEMS/mcl_beds/depends.txt @@ -1,3 +1,4 @@ +mcl_playerphysics mcl_sounds? mcl_worlds? mcl_wool? diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 483d8c373..702a1d0c2 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -110,7 +110,8 @@ local function lay_down(player, pos, bed_pos, state, skip) player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) player:set_look_horizontal(math.random(1, 180) / 100) mcl_player.player_attached[name] = false - player:set_physics_override(1, 1, 1) + mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping") + mcl_playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping") player:set_attribute("mcl_beds:sleeping", "false") hud_flags.wielditem = true mcl_player.player_set_animation(player, "stand" , 30) @@ -127,9 +128,9 @@ local function lay_down(player, pos, bed_pos, state, skip) player:set_look_horizontal(yaw) local dir = minetest.facedir_to_dir(param2) local p = {x = bed_pos.x + dir.x / 2, y = bed_pos.y, z = bed_pos.z + dir.z / 2} - -- Set player attribute so other mods know they should not touch set_physics_override player:set_attribute("mcl_beds:sleeping", "true") - player:set_physics_override(0, 0, 0) + mcl_playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0) + mcl_playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0) player:setpos(p) mcl_player.player_attached[name] = true hud_flags.wielditem = false diff --git a/mods/PLAYER/mcl_playerplus/depends.txt b/mods/PLAYER/mcl_playerplus/depends.txt index a9cabf054..8ff8b857c 100644 --- a/mods/PLAYER/mcl_playerplus/depends.txt +++ b/mods/PLAYER/mcl_playerplus/depends.txt @@ -4,6 +4,7 @@ mcl_core mcl_particles mcl_hunger mcl_death_messages +mcl_playerphysics mcl_playerinfo 3d_armor? mcl_weather diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 612d6f3e3..a07b63bec 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -89,32 +89,20 @@ minetest.register_globalstep(function(dtime) -- set defaults def.speed = 1 - def.jump = 1 - def.gravity = 1 - -- is 3d_armor mod active? if so make armor physics default - if armor_mod and armor and armor.def then - -- get player physics from armor - def.speed = armor.def[name].speed or 1 - def.jump = armor.def[name].jump or 1 - def.gravity = armor.def[name].gravity or 1 - end - - -- standing on soul sand? if so walk slower + -- Standing on soul sand? If so, walk slower if node_stand == "mcl_nether:soul_sand" then -- TODO: Tweak walk speed -- TODO: Also slow down mobs - -- FIXME: This whole speed thing is a giant hack. We need a proper framefork for cleanly handling player speeds - if node_stand_below == "mcl_core:ice" or node_stand_below == "mcl_core:packed_ice" or node_stand_below == "mcl_core:slimeblock" then - def.speed = def.speed - 0.9 + -- Slow down even more when soul sand is above certain block + if node_stand_below == "mcl_core:ice" or node_stand_below == "mcl_core:packed_ice" or node_stand_below == "mcl_core:slimeblock" or node_stand_below == "mcl_core:water_source" then + mcl_playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1) else - def.speed = def.speed - 0.6 + mcl_playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4) end - end - - -- Set player physics if there's no conflict - if player:get_attribute("mcl_beds:sleeping") ~= "true" then - player:set_physics_override(def.speed, def.jump, def.gravity) + else + -- Reset speed decrease + mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") end -- Is player suffocating inside node? (Only for solid full opaque cube type nodes diff --git a/mods/PLAYER/mcl_sprint/depends.txt b/mods/PLAYER/mcl_sprint/depends.txt index 2fd97244a..3f814ad10 100644 --- a/mods/PLAYER/mcl_sprint/depends.txt +++ b/mods/PLAYER/mcl_sprint/depends.txt @@ -1,2 +1,3 @@ mcl_playerinfo +mcl_playerphysics mcl_hunger diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 79ee234c1..c97ca801c 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -44,15 +44,12 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player local player = minetest.get_player_by_name(playerName) if players[playerName] then players[playerName]["sprinting"] = sprinting - -- Don't overwrite physics when standing on soul sand or sleeping - if mcl_playerinfo[playerName].node_stand ~= "mcl_nether:soul_sand" and player:get_attribute("mcl_beds:sleeping") ~= "true" then - if sprinting == true then - player:set_physics_override({speed=mcl_sprint.SPEED}) - elseif sprinting == false then - player:set_physics_override({speed=1.0}) - end - return true + if sprinting == true then + mcl_playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED) + elseif sprinting == false then + mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint") end + return true end return false end @@ -109,8 +106,8 @@ minetest.register_globalstep(function(dtime) players[playerName].lastPos = playerPos if players[playerName]["shouldSprint"] == true then --Stopped local sprinting - -- Prevent sprinting if standing on soul sand or hungry - if mcl_playerinfo[playerName].node_stand == "mcl_nether:soul_sand" or (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) then + -- Prevent sprinting if hungry or sleeping + if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_attribute("mcl_beds:sleeping") == "true")then sprinting = false else sprinting = true