Update player model code from Minetest Game 0.4.16

This commit is contained in:
Wuzzy 2017-06-10 23:17:19 +02:00
parent 7f6b1b8aba
commit e7c03fb982
6 changed files with 70 additions and 6621 deletions

View file

@ -1,55 +1,5 @@
-- MineClone 2 mod: mcl_player
-- Minetest 0.4 mod: player
-- 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 = {}
-- Player animation blending
@ -66,7 +16,7 @@ function mcl_player.player_register_model(name, def)
end
-- Default player appearance
mcl_player.player_register_model("character.x", {
mcl_player.player_register_model("character.b3d", {
animation_speed = 30,
textures = {"character.png", },
animations = {
@ -76,7 +26,6 @@ mcl_player.player_register_model("character.x", {
walk = { x=168, y=187, },
mine = { x=189, y=198, },
walk_mine = { x=200, y=219, },
-- Extra animations (not currently used by the game).
sit = { x= 81, y=160, },
},
})
@ -144,12 +93,8 @@ end
-- Update appearance when the player joins
minetest.register_on_joinplayer(function(player)
mcl_player.player_attached[player:get_player_name()] = false
mcl_player.player_set_model(player, "character.x")
-- 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})
mcl_player.player_set_model(player, "character.b3d")
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)
minetest.register_on_leaveplayer(function(player)
@ -161,6 +106,7 @@ end)
-- Localize for better performance.
local player_set_animation = mcl_player.player_set_animation
local player_attached = mcl_player.player_attached
-- Check each player and apply animations
minetest.register_globalstep(function(dtime)
@ -168,7 +114,7 @@ minetest.register_globalstep(function(dtime)
local name = player:get_player_name()
local model_name = player_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 walking = false
local animation_speed_mod = model.animation_speed or 30
@ -201,7 +147,6 @@ minetest.register_globalstep(function(dtime)
else
player_set_animation(player, "stand", animation_speed_mod)
end
end
end
end)