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:
parent
da03b6af6a
commit
2c4eae353c
|
@ -1,3 +1,4 @@
|
||||||
|
mcl_playerphysics
|
||||||
mcl_sounds?
|
mcl_sounds?
|
||||||
mcl_worlds?
|
mcl_worlds?
|
||||||
mcl_wool?
|
mcl_wool?
|
||||||
|
|
|
@ -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_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
player:set_look_horizontal(math.random(1, 180) / 100)
|
player:set_look_horizontal(math.random(1, 180) / 100)
|
||||||
mcl_player.player_attached[name] = false
|
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")
|
player:set_attribute("mcl_beds:sleeping", "false")
|
||||||
hud_flags.wielditem = true
|
hud_flags.wielditem = true
|
||||||
mcl_player.player_set_animation(player, "stand" , 30)
|
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)
|
player:set_look_horizontal(yaw)
|
||||||
local dir = minetest.facedir_to_dir(param2)
|
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}
|
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_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)
|
player:setpos(p)
|
||||||
mcl_player.player_attached[name] = true
|
mcl_player.player_attached[name] = true
|
||||||
hud_flags.wielditem = false
|
hud_flags.wielditem = false
|
||||||
|
|
|
@ -4,6 +4,7 @@ mcl_core
|
||||||
mcl_particles
|
mcl_particles
|
||||||
mcl_hunger
|
mcl_hunger
|
||||||
mcl_death_messages
|
mcl_death_messages
|
||||||
|
mcl_playerphysics
|
||||||
mcl_playerinfo
|
mcl_playerinfo
|
||||||
3d_armor?
|
3d_armor?
|
||||||
mcl_weather
|
mcl_weather
|
||||||
|
|
|
@ -89,32 +89,20 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
-- set defaults
|
-- set defaults
|
||||||
def.speed = 1
|
def.speed = 1
|
||||||
def.jump = 1
|
|
||||||
def.gravity = 1
|
|
||||||
|
|
||||||
-- is 3d_armor mod active? if so make armor physics default
|
-- Standing on soul sand? If so, walk slower
|
||||||
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
|
|
||||||
if node_stand == "mcl_nether:soul_sand" then
|
if node_stand == "mcl_nether:soul_sand" then
|
||||||
-- TODO: Tweak walk speed
|
-- TODO: Tweak walk speed
|
||||||
-- TODO: Also slow down mobs
|
-- TODO: Also slow down mobs
|
||||||
-- FIXME: This whole speed thing is a giant hack. We need a proper framefork for cleanly handling player speeds
|
-- 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" then
|
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
|
||||||
def.speed = def.speed - 0.9
|
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1)
|
||||||
else
|
else
|
||||||
def.speed = def.speed - 0.6
|
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4)
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
-- Reset speed decrease
|
||||||
-- Set player physics if there's no conflict
|
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface")
|
||||||
if player:get_attribute("mcl_beds:sleeping") ~= "true" then
|
|
||||||
player:set_physics_override(def.speed, def.jump, def.gravity)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Is player suffocating inside node? (Only for solid full opaque cube type nodes
|
-- Is player suffocating inside node? (Only for solid full opaque cube type nodes
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
mcl_playerinfo
|
mcl_playerinfo
|
||||||
|
mcl_playerphysics
|
||||||
mcl_hunger
|
mcl_hunger
|
||||||
|
|
|
@ -44,16 +44,13 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player
|
||||||
local player = minetest.get_player_by_name(playerName)
|
local player = minetest.get_player_by_name(playerName)
|
||||||
if players[playerName] then
|
if players[playerName] then
|
||||||
players[playerName]["sprinting"] = sprinting
|
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
|
if sprinting == true then
|
||||||
player:set_physics_override({speed=mcl_sprint.SPEED})
|
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
|
||||||
elseif sprinting == false then
|
elseif sprinting == false then
|
||||||
player:set_physics_override({speed=1.0})
|
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
@ -109,8 +106,8 @@ minetest.register_globalstep(function(dtime)
|
||||||
players[playerName].lastPos = playerPos
|
players[playerName].lastPos = playerPos
|
||||||
if players[playerName]["shouldSprint"] == true then --Stopped
|
if players[playerName]["shouldSprint"] == true then --Stopped
|
||||||
local sprinting
|
local sprinting
|
||||||
-- Prevent sprinting if standing on soul sand or hungry
|
-- Prevent sprinting if hungry or sleeping
|
||||||
if mcl_playerinfo[playerName].node_stand == "mcl_nether:soul_sand" or (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) then
|
if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_attribute("mcl_beds:sleeping") == "true")then
|
||||||
sprinting = false
|
sprinting = false
|
||||||
else
|
else
|
||||||
sprinting = true
|
sprinting = true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user