mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 23:10:17 +01:00
player_api: Prevent knockback when player is set as attached
This is not directly related to player models but fits well as a convenience feature in player_api.
This commit is contained in:
parent
b9dc758fef
commit
fbbc7fc996
@ -20,5 +20,8 @@ read_globals = {
|
|||||||
-- Overwrites minetest.handle_node_drops
|
-- Overwrites minetest.handle_node_drops
|
||||||
files["mods/creative/init.lua"].globals = { "minetest" }
|
files["mods/creative/init.lua"].globals = { "minetest" }
|
||||||
|
|
||||||
|
-- Overwrites minetest.calculate_knockback
|
||||||
|
files["mods/player_api/api.lua"].globals = { "minetest" }
|
||||||
|
|
||||||
-- Don't report on legacy definitions of globals.
|
-- Don't report on legacy definitions of globals.
|
||||||
files["mods/default/legacy.lua"].global = false
|
files["mods/default/legacy.lua"].global = false
|
||||||
|
@ -424,7 +424,7 @@ Give Initial Stuff API
|
|||||||
Players API
|
Players API
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
The player API can register player models and update the player's appearence
|
The player API can register player models and update the player's appearance.
|
||||||
|
|
||||||
* `player_api.register_model(name, def)`
|
* `player_api.register_model(name, def)`
|
||||||
* Register a new model to be used by players
|
* Register a new model to be used by players
|
||||||
@ -457,6 +457,12 @@ The player API can register player models and update the player's appearence
|
|||||||
* Any of the fields of the returned table may be nil.
|
* Any of the fields of the returned table may be nil.
|
||||||
* player: PlayerRef
|
* player: PlayerRef
|
||||||
|
|
||||||
|
* `player_api.player_attached`
|
||||||
|
* A table that maps a player name to a boolean.
|
||||||
|
* If the value for a given player is set to true, the default player
|
||||||
|
animations (walking, digging, ...) will no longer be updated.
|
||||||
|
Knockback from damage is also prevented for that player.
|
||||||
|
|
||||||
### Model Definition
|
### Model Definition
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -96,6 +96,15 @@ end)
|
|||||||
local player_set_animation = player_api.set_animation
|
local player_set_animation = player_api.set_animation
|
||||||
local player_attached = player_api.player_attached
|
local player_attached = player_api.player_attached
|
||||||
|
|
||||||
|
-- Prevent knockback for attached players
|
||||||
|
local old_calculate_knockback = minetest.calculate_knockback
|
||||||
|
function minetest.calculate_knockback(player, ...)
|
||||||
|
if player_attached[player:get_player_name()] then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return old_calculate_knockback(player, ...)
|
||||||
|
end
|
||||||
|
|
||||||
-- Check each player and apply animations
|
-- Check each player and apply animations
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
Loading…
Reference in New Issue
Block a user