Rename mcl_playerphysics to playerphysics

This commit is contained in:
Wuzzy 2018-10-23 18:51:19 +02:00
parent e0fe5b2c66
commit b076bafaa7
12 changed files with 34 additions and 34 deletions

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

@ -110,8 +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
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping") playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping")
mcl_playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping") 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)
@ -129,8 +129,8 @@ local function lay_down(player, pos, bed_pos, state, skip)
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}
player:set_attribute("mcl_beds:sleeping", "true") player:set_attribute("mcl_beds:sleeping", "true")
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0) playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0)
mcl_playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0) 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

@ -127,8 +127,8 @@ end
local reset_bow_state = function(player, also_reset_bows) local reset_bow_state = function(player, also_reset_bows)
bow_load[player:get_player_name()] = nil bow_load[player:get_player_name()] = nil
bow_index[player:get_player_name()] = nil bow_index[player:get_player_name()] = nil
if minetest.get_modpath("mcl_playerphysics") then if minetest.get_modpath("playerphysics") then
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_bows:use_bow") playerphysics.remove_physics_factor(player, "speed", "mcl_bows:use_bow")
end end
if also_reset_bows then if also_reset_bows then
reset_bows(player) reset_bows(player)
@ -222,9 +222,9 @@ controls.register_on_hold(function(player, key, time)
if bow_load[name] == nil and wielditem:get_name()=="mcl_bows:bow" and (minetest.settings:get_bool("creative_mode") or inv:contains_item("main", "mcl_bows:arrow")) then if bow_load[name] == nil and wielditem:get_name()=="mcl_bows:bow" and (minetest.settings:get_bool("creative_mode") or inv:contains_item("main", "mcl_bows:arrow")) then
wielditem:set_name("mcl_bows:bow_0") wielditem:set_name("mcl_bows:bow_0")
player:set_wielded_item(wielditem) player:set_wielded_item(wielditem)
if minetest.get_modpath("mcl_playerphysics") then if minetest.get_modpath("playerphysics") then
-- Slow player down when using bow -- Slow player down when using bow
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED) playerphysics.add_physics_factor(player, "speed", "mcl_bows:use_bow", PLAYER_USE_BOW_SPEED)
end end
bow_load[name] = minetest.get_us_time() bow_load[name] = minetest.get_us_time()
bow_index[name] = player:get_wield_index() bow_index[name] = player:get_wield_index()

@ -4,7 +4,7 @@ mcl_achievements?
mcl_hunger? mcl_hunger?
mcl_core? mcl_core?
mcl_mobitems? mcl_mobitems?
mcl_playerphysics? playerphysics?
doc? doc?
doc_identifier? doc_identifier?
mesecons_button? mesecons_button?

@ -1 +0,0 @@
name=mcl_playerphysics

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

@ -96,13 +96,13 @@ minetest.register_globalstep(function(dtime)
-- TODO: Also slow down mobs -- TODO: Also slow down mobs
-- Slow down even more when soul sand is above certain block -- 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 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) playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1)
else else
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4) playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4)
end end
else else
-- Reset speed decrease -- Reset speed decrease
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface")
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,3 +1,3 @@
mcl_playerinfo mcl_playerinfo
mcl_playerphysics playerphysics
mcl_hunger mcl_hunger

@ -45,9 +45,9 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player
if players[playerName] then if players[playerName] then
players[playerName]["sprinting"] = sprinting players[playerName]["sprinting"] = sprinting
if sprinting == true then if sprinting == true then
mcl_playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED) playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
elseif sprinting == false then elseif sprinting == false then
mcl_playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint") playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
end end
return true return true
end end

@ -13,7 +13,7 @@ There is only one precondition to using this mod, but it is important:
Mods *MUST NOT* call `set_physics_override` directly! Instead, to modify player physics, use this API. Mods *MUST NOT* call `set_physics_override` directly! Instead, to modify player physics, use this API.
## Functions ## Functions
### `mcl_playerphysics.add_physics_factor(player, physic, id, value)` ### `playerphysics.add_physics_factor(player, physic, id, value)`
Adds a factor for a player physic and updates the player physics immeiately. Adds a factor for a player physic and updates the player physics immeiately.
#### Parameters #### Parameters
@ -22,7 +22,7 @@ Adds a factor for a player physic and updates the player physics immeiately.
* `id`: Unique identifier for this factor. Identifiers are stored on a per-player per-physics type basis * `id`: Unique identifier for this factor. Identifiers are stored on a per-player per-physics type basis
* `value`: The factor to add to the list of products * `value`: The factor to add to the list of products
### `mcl_playerphysics.remove_physics_factor(player, physic, id)` ### `playerphysics.remove_physics_factor(player, physic, id)`
Removes the physics factor of the given ID and updates the player's physics. Removes the physics factor of the given ID and updates the player's physics.
#### Parameters #### Parameters
@ -37,17 +37,17 @@ Here's what it could look like:
Potions mod: Potions mod:
``` ```
mcl_playerphysics.add_physics_factor(player, "speed", "run_potion", 2) playerphysics.add_physics_factor(player, "speed", "run_potion", 2)
``` ```
Exhaustion mod: Exhaustion mod:
``` ```
mcl_playerphysics.add_physics_factor(player, "jump", "exhausted", 0.75) playerphysics.add_physics_factor(player, "jump", "exhausted", 0.75)
``` ```
Electrocution mod: Electrocution mod:
``` ```
mcl_playerphysics.add_physics_factor(player, "jump", "shocked", 0.9) playerphysics.add_physics_factor(player, "jump", "shocked", 0.9)
``` ```
When the 3 mods have done their change, the real player speed is simply the product of all factors, that is: When the 3 mods have done their change, the real player speed is simply the product of all factors, that is:
@ -62,7 +62,7 @@ Let's take the example above.
Now if the Electrocution mod is done with shocking the player, it just needs to call: Now if the Electrocution mod is done with shocking the player, it just needs to call:
``` ```
mcl_playerphysics.remove_physics_factor(player, "jump", "shocked") playerphysics.remove_physics_factor(player, "jump", "shocked")
``` ```
The effect is now gone, so the new player speed will be: The effect is now gone, so the new player speed will be:
@ -73,8 +73,8 @@ The effect is now gone, so the new player speed will be:
To simulate sleeping by preventing all player movement, this can be done with this easy trick: To simulate sleeping by preventing all player movement, this can be done with this easy trick:
``` ```
mcl_playerphysics.add_physics_factor(player, "speed", "sleeping", 0) playerphysics.add_physics_factor(player, "speed", "sleeping", 0)
mcl_playerphysics.add_physics_factor(player, "jump", "sleeping", 0) playerphysics.add_physics_factor(player, "jump", "sleeping", 0)
``` ```
This works regardless of the other factors because mathematics tell us that the factor 0 forces the product to be 0. This works regardless of the other factors because mathematics tell us that the factor 0 forces the product to be 0.

@ -1,7 +1,7 @@
mcl_playerphysics = {} playerphysics = {}
local function calculate_physic_product(player, physic) local function calculate_physic_product(player, physic)
local a = minetest.deserialize(player:get_attribute("mcl_playerphysics:physics")) local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
local product = 1 local product = 1
if a == nil or a[physic] == nil then if a == nil or a[physic] == nil then
return product return product
@ -15,8 +15,8 @@ local function calculate_physic_product(player, physic)
return product return product
end end
function mcl_playerphysics.add_physics_factor(player, physic, id, value) function playerphysics.add_physics_factor(player, physic, id, value)
local a = minetest.deserialize(player:get_attribute("mcl_playerphysics:physics")) local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
if a == nil then if a == nil then
a = { [physic] = { [id] = value } } a = { [physic] = { [id] = value } }
elseif a[physic] == nil then elseif a[physic] == nil then
@ -24,20 +24,20 @@ function mcl_playerphysics.add_physics_factor(player, physic, id, value)
else else
a[physic][id] = value a[physic][id] = value
end end
player:set_attribute("mcl_playerphysics:physics", minetest.serialize(a)) player:set_attribute("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_physic_product(player, physic) local raw_value = calculate_physic_product(player, physic)
player:set_physics_override({[physic] = raw_value}) player:set_physics_override({[physic] = raw_value})
end end
function mcl_playerphysics.remove_physics_factor(player, physic, id) function playerphysics.remove_physics_factor(player, physic, id)
local a = minetest.deserialize(player:get_attribute("mcl_playerphysics:physics")) local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
if a == nil or a[physic] == nil then if a == nil or a[physic] == nil then
-- Nothing to remove -- Nothing to remove
return return
else else
a[physic][id] = nil a[physic][id] = nil
end end
player:set_attribute("mcl_playerphysics:physics", minetest.serialize(a)) player:set_attribute("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_physic_product(player, physic) local raw_value = calculate_physic_product(player, physic)
player:set_physics_override({[physic] = raw_value}) player:set_physics_override({[physic] = raw_value})
end end

@ -0,0 +1 @@
name = playerphysics