Player API: Integrate settable player step height

Split some long lines.
Some nearby code cleanup.
This commit is contained in:
paramat 2017-08-07 04:27:19 +01:00 committed by paramat
parent 3294a2a515
commit 77c9408721
3 changed files with 22 additions and 12 deletions

View File

@ -312,7 +312,8 @@ The player API can register player models and update the player's appearence
* `player_api.set_textures(player, textures)` * `player_api.set_textures(player, textures)`
* Sets player textures * Sets player textures
* `player`: PlayerRef * `player`: PlayerRef
* `textures`: array of textures, If `textures` is nil, the default textures from the model def are used * `textures`: array of textures, If `textures` is nil the default
textures from the model def are used
* `player_api.get_animation(player)` * `player_api.get_animation(player)`
* Returns a table containing fields `model`, `textures` and `animation`. * Returns a table containing fields `model`, `textures` and `animation`.
@ -331,7 +332,8 @@ The player API can register player models and update the player's appearence
bar = {x = 20, y = 39}, bar = {x = 20, y = 39},
-- ... -- ...
}, },
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3}, -- In nodes from centre of feet collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3}, -- In nodes from feet position
stepheight = 0.6, -- In nodes
} }

View File

@ -46,13 +46,15 @@ function player_api.set_model(player, model_name)
visual = "mesh", visual = "mesh",
visual_size = model.visual_size or {x = 1, y = 1}, visual_size = model.visual_size or {x = 1, y = 1},
collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3}, collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3},
stepheight = model.stepheight or 0.6,
}) })
player_api.set_animation(player, "stand") player_api.set_animation(player, "stand")
else else
player:set_properties({ player:set_properties({
textures = { "player.png", "player_back.png", }, textures = {"player.png", "player_back.png"},
visual = "upright_sprite", visual = "upright_sprite",
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3},
stepheight = 0.6,
}) })
end end
player_model[name] = model_name player_model[name] = model_name

View File

@ -6,22 +6,28 @@ player_api.register_model("character.b3d", {
textures = {"character.png", }, textures = {"character.png", },
animations = { animations = {
-- Standard animations. -- Standard animations.
stand = { x= 0, y= 79, }, stand = {x = 0, y = 79},
lay = { x=162, y=166, }, lay = {x = 162, y = 166},
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},
sit = { x= 81, y=160, }, sit = {x = 81, y = 160},
}, },
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.77, 0.3},
stepheight = 0.6,
}) })
-- Update appearance when the player joins -- Update appearance when the player joins
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
player_api.player_attached[player:get_player_name()] = false player_api.player_attached[player:get_player_name()] = false
player_api.set_model(player, "character.b3d") player_api.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) player:set_local_animation(
{x = 0, y = 79},
{x = 168, y = 187},
{x = 189, y = 198},
{x = 200, y = 219},
30
)
player:hud_set_hotbar_image("gui_hotbar.png") player:hud_set_hotbar_image("gui_hotbar.png")
player:hud_set_hotbar_selected_image("gui_hotbar_selected.png") player:hud_set_hotbar_selected_image("gui_hotbar_selected.png")
end) end)