1
0
Fork 0

Use mcl_playerphysics to handle player physics

This fixes some issues with speed overrides and gets rid of ugly workarounds.
This commit is contained in:
Wuzzy 2018-05-07 20:10:53 +02:00
parent da03b6af6a
commit 2c4eae353c
6 changed files with 22 additions and 33 deletions

View File

@ -1,3 +1,4 @@
mcl_playerphysics
mcl_sounds?
mcl_worlds?
mcl_wool?

View File

@ -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

View File

@ -4,6 +4,7 @@ mcl_core
mcl_particles
mcl_hunger
mcl_death_messages
mcl_playerphysics
mcl_playerinfo
3d_armor?
mcl_weather

View File

@ -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

View File

@ -1,2 +1,3 @@
mcl_playerinfo
mcl_playerphysics
mcl_hunger

View File

@ -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