forked from VoxeLibre/VoxeLibre
Update player model code from Minetest Game 0.4.16
This commit is contained in:
parent
7f6b1b8aba
commit
e7c03fb982
|
@ -1,9 +1,13 @@
|
||||||
MineClone 2 mod: mcl_player
|
MineClone 2 mod: mcl_player
|
||||||
==========================
|
==========================
|
||||||
|
Adds the 3D player model, taken from Minetest Game 0.4.16.
|
||||||
|
|
||||||
License of source code:
|
Programmers: See `game_api.txt` for the API definition.
|
||||||
-----------------------
|
|
||||||
Copyright (C) 2011-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
Authors of source code
|
||||||
|
----------------------
|
||||||
|
Originally by celeron55, Perttu Ahola <celeron55@gmail.com> (LGPL 2.1)
|
||||||
|
Various Minetest developers and contributors (LGPL 2.1)
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
@ -14,7 +18,7 @@ http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
|
||||||
Authors of media files
|
Authors of media files
|
||||||
-----------------------
|
-----------------------
|
||||||
MirceaKitsune (WTFPL):
|
MirceaKitsune (CC BY-SA 3.0):
|
||||||
character.x
|
character.b3d
|
||||||
|
|
||||||
Textures from Faithful 1.11 resource pack (see main readme file)
|
Textures from Faithful 1.11 resource pack (see main readme file)
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
Player API
|
||||||
|
----------
|
||||||
|
This is the same as the player API from Minetest Game 0.4.16.
|
||||||
|
But `default` has been renamed to `mcl_player`.
|
||||||
|
|
||||||
|
The player API can register player models and update the player's appearence.
|
||||||
|
|
||||||
|
`mcl_player.player_register_model(name, def)`
|
||||||
|
|
||||||
|
* Register a new model to be used by players.
|
||||||
|
* name: model filename such as "character.x", "foo.b3d", etc.
|
||||||
|
* def: See [#Model definition]
|
||||||
|
|
||||||
|
`mcl_player.registered_player_models[name]`
|
||||||
|
|
||||||
|
* Get a model's definition
|
||||||
|
* see [#Model definition]
|
||||||
|
|
||||||
|
`mcl_player.player_set_model(player, model_name)`
|
||||||
|
|
||||||
|
* Change a player's model
|
||||||
|
* `player`: PlayerRef
|
||||||
|
* `model_name`: model registered with player_register_model()
|
||||||
|
|
||||||
|
`mcl_player.player_set_animation(player, anim_name [, speed])`
|
||||||
|
|
||||||
|
* Applies an animation to a player
|
||||||
|
* anim_name: name of the animation.
|
||||||
|
* speed: frames per second. If nil, default from the model is used
|
||||||
|
|
||||||
|
`mcl_player.player_set_textures(player, textures)`
|
||||||
|
|
||||||
|
* Sets player textures
|
||||||
|
* `player`: PlayerRef
|
||||||
|
* `textures`: array of textures, If `textures` is nil, the default textures from the model def are used
|
||||||
|
|
||||||
|
mcl_player.player_get_animation(player)
|
||||||
|
|
||||||
|
* Returns a table containing fields `model`, `textures` and `animation`.
|
||||||
|
* Any of the fields of the returned table may be nil.
|
||||||
|
* player: PlayerRef
|
||||||
|
|
||||||
|
### Model Definition
|
||||||
|
|
||||||
|
{
|
||||||
|
animation_speed = 30, -- Default animation speed, in FPS.
|
||||||
|
textures = {"character.png", }, -- Default array of textures.
|
||||||
|
visual_size = {x = 1, y = 1}, -- Used to scale the model.
|
||||||
|
animations = {
|
||||||
|
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
|
||||||
|
foo = {x = 0, y = 19},
|
||||||
|
bar = {x = 20, y = 39},
|
||||||
|
-- ...
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -1,55 +1,5 @@
|
||||||
-- MineClone 2 mod: mcl_player
|
-- Minetest 0.4 mod: player
|
||||||
-- See README.txt for licensing and other information.
|
-- See README.txt for licensing and other information.
|
||||||
|
|
||||||
--[[
|
|
||||||
|
|
||||||
API
|
|
||||||
---
|
|
||||||
|
|
||||||
mcl_player.player_register_model(name, def)
|
|
||||||
^ Register a new model to be used by players.
|
|
||||||
^ <name> is the model filename such as "character.x", "foo.b3d", etc.
|
|
||||||
^ See Model Definition below for format of <def>.
|
|
||||||
|
|
||||||
mcl_player.registered_player_models[name]
|
|
||||||
^ See Model Definition below for format.
|
|
||||||
|
|
||||||
mcl_player.player_set_model(player, model_name)
|
|
||||||
^ <player> is a PlayerRef.
|
|
||||||
^ <model_name> is a model registered with player_register_model.
|
|
||||||
|
|
||||||
mcl_player.player_set_animation(player, anim_name [, speed])
|
|
||||||
^ <player> is a PlayerRef.
|
|
||||||
^ <anim_name> is the name of the animation.
|
|
||||||
^ <speed> is in frames per second. If nil, default from the model is used
|
|
||||||
|
|
||||||
mcl_player.player_set_textures(player, textures)
|
|
||||||
^ <player> is a PlayerRef.
|
|
||||||
^ <textures> is an array of textures
|
|
||||||
^ If <textures> is nil, the default textures from the model def are used
|
|
||||||
|
|
||||||
mcl_player.player_get_animation(player)
|
|
||||||
^ <player> is a PlayerRef.
|
|
||||||
^ Returns a table containing fields "model", "textures" and "animation".
|
|
||||||
^ Any of the fields of the returned table may be nil.
|
|
||||||
|
|
||||||
Model Definition
|
|
||||||
----------------
|
|
||||||
|
|
||||||
model_def = {
|
|
||||||
animation_speed = 30, -- Default animation speed, in FPS.
|
|
||||||
textures = {"character.png", }, -- Default array of textures.
|
|
||||||
visual_size = {x=1, y=1,}, -- Used to scale the model.
|
|
||||||
animations = {
|
|
||||||
-- <anim_name> = { x=<start_frame>, y=<end_frame>, },
|
|
||||||
foo = { x= 0, y=19, },
|
|
||||||
bar = { x=20, y=39, },
|
|
||||||
-- ...
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
mcl_player = {}
|
mcl_player = {}
|
||||||
|
|
||||||
-- Player animation blending
|
-- Player animation blending
|
||||||
|
@ -66,7 +16,7 @@ function mcl_player.player_register_model(name, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Default player appearance
|
-- Default player appearance
|
||||||
mcl_player.player_register_model("character.x", {
|
mcl_player.player_register_model("character.b3d", {
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
textures = {"character.png", },
|
textures = {"character.png", },
|
||||||
animations = {
|
animations = {
|
||||||
|
@ -76,7 +26,6 @@ mcl_player.player_register_model("character.x", {
|
||||||
walk = { x=168, y=187, },
|
walk = { x=168, y=187, },
|
||||||
mine = { x=189, y=198, },
|
mine = { x=189, y=198, },
|
||||||
walk_mine = { x=200, y=219, },
|
walk_mine = { x=200, y=219, },
|
||||||
-- Extra animations (not currently used by the game).
|
|
||||||
sit = { x= 81, y=160, },
|
sit = { x= 81, y=160, },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -144,12 +93,8 @@ end
|
||||||
-- Update appearance when the player joins
|
-- Update appearance when the player joins
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
mcl_player.player_attached[player:get_player_name()] = false
|
mcl_player.player_attached[player:get_player_name()] = false
|
||||||
mcl_player.player_set_model(player, "character.x")
|
mcl_player.player_set_model(player, "character.b3d")
|
||||||
-- Minecraft has no sneak glitch
|
|
||||||
-- sneak is also disabled because it is buggy in Minetest (can be used to negate fall damage)
|
|
||||||
player:set_physics_override({sneak_glitch=false})
|
|
||||||
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
|
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
|
||||||
-- Note: Minimap is now handled in mcl_maps
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
@ -161,6 +106,7 @@ end)
|
||||||
|
|
||||||
-- Localize for better performance.
|
-- Localize for better performance.
|
||||||
local player_set_animation = mcl_player.player_set_animation
|
local player_set_animation = mcl_player.player_set_animation
|
||||||
|
local player_attached = mcl_player.player_attached
|
||||||
|
|
||||||
-- Check each player and apply animations
|
-- Check each player and apply animations
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
@ -168,7 +114,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local model_name = player_model[name]
|
local model_name = player_model[name]
|
||||||
local model = model_name and models[model_name]
|
local model = model_name and models[model_name]
|
||||||
if model and not mcl_player.player_attached[name] then
|
if model and not player_attached[name] then
|
||||||
local controls = player:get_player_control()
|
local controls = player:get_player_control()
|
||||||
local walking = false
|
local walking = false
|
||||||
local animation_speed_mod = model.animation_speed or 30
|
local animation_speed_mod = model.animation_speed or 30
|
||||||
|
@ -201,7 +147,6 @@ minetest.register_globalstep(function(dtime)
|
||||||
else
|
else
|
||||||
player_set_animation(player, "stand", animation_speed_mod)
|
player_set_animation(player, "stand", animation_speed_mod)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue