Skip to content

Commit

Permalink
fix lottarmor.wilditem
Browse files Browse the repository at this point in the history
  • Loading branch information
albel4 committed Apr 2, 2020
1 parent b77d173 commit bc01bbd
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 149 deletions.
8 changes: 4 additions & 4 deletions mods/beds/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- physics, eye_offset, etc
player:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
player:set_look_yaw(math.random(1, 180)/100)
default.player_attached[name] = false
player_api.player_attached[name] = false
player:set_physics_override(1, 1, 1)
hud_flags.wielditem = true
default.player_set_animation(player, "stand" , 30)
player_api.set_animation(player, "stand" , 30)

-- lay down
else
Expand All @@ -84,9 +84,9 @@ local function lay_down(player, pos, bed_pos, state, skip)
local p = {x=bed_pos.x+dir.x/2,y=bed_pos.y,z=bed_pos.z+dir.z/2}
player:set_physics_override(0, 0, 1)
player:setpos(p)
default.player_attached[name] = true
player_api.player_attached[name] = true
hud_flags.wielditem = false
default.player_set_animation(player, "lay" , 0)
player_api.set_animation(player, "lay" , 0)
end

player:hud_set_flags(hud_flags)
Expand Down
22 changes: 11 additions & 11 deletions mods/boats/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ function row_boat.on_rightclick(self, clicker)
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
default.player_attached[name] = false
default.player_set_animation(clicker, "stand" , 30)
player_api.player_attached[name] = false
player_api.set_animation(clicker, "stand" , 30)
elseif not self.driver then
self.driver = clicker
clicker:set_attach(self.object, "", {x=0,y=11,z=0}, {x=0,y=0,z=0})
default.player_attached[name] = true
clicker:set_attach(self.object, "", {x=0,y=3,z=-4}, {x=0,y=0,z=0})
player_api.player_attached[name] = true
minetest.after(0.2, function()
default.player_set_animation(clicker, "sit" , 30)
player_api.set_animation(clicker, "sit" , 30)
end)
self.object:setyaw(clicker:get_look_yaw() - math.pi / 2)
end
Expand All @@ -80,7 +80,7 @@ function row_boat.on_punch(self, puncher, time_from_last_punch, tool_capabilitie
return
end
puncher:set_detach()
default.player_attached[puncher:get_player_name()] = false
player_api.player_attached[puncher:get_player_name()] = false

self.removed = true
-- delay remove to ensure player is detached
Expand Down Expand Up @@ -232,14 +232,14 @@ function sail_boat.on_rightclick(self, clicker)
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
default.player_attached[name] = false
default.player_set_animation(clicker, "stand" , 30)
player_api.player_attached[name] = false
player_api.set_animation(clicker, "stand" , 30)
elseif not self.driver then
self.driver = clicker
clicker:set_attach(self.object, "", {x=0,y=11,z=0}, {x=0,y=0,z=0})
default.player_attached[name] = true
player_api.player_attached[name] = true
minetest.after(0.2, function()
default.player_set_animation(clicker, "sit" , 30)
player_api.set_animation(clicker, "sit" , 30)
end)
self.object:setyaw(clicker:get_look_yaw() - math.pi / 2)
end
Expand All @@ -262,7 +262,7 @@ function sail_boat.on_punch(self, puncher, time_from_last_punch, tool_capabiliti
return
end
puncher:set_detach()
default.player_attached[puncher:get_player_name()] = false
player_api.player_attached[puncher:get_player_name()] = false

self.removed = true
-- delay remove to ensure player is detached
Expand Down
236 changes: 118 additions & 118 deletions mods/default/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,136 +3,136 @@

-- Player animation blending
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
local animation_blend = 0
--local animation_blend = 0

default.registered_player_models = { }
--default.registered_player_models = { }

-- Local for speed.
local models = default.registered_player_models
--local models = default.registered_player_models

function default.player_register_model(name, def)
models[name] = def
end
--function default.player_register_model(name, def)
-- models[name] = def
--end

-- Player stats and animations
local player_model = {}
local player_textures = {}
local player_anim = {}
local player_sneak = {}
default.player_attached = {}

function default.player_get_animation(player)
local name = player:get_player_name()
return {
model = player_model[name],
textures = player_textures[name],
animation = player_anim[name],
}
end
--local player_model = {}
--local player_textures = {}
--local player_anim = {}
--local player_sneak = {}
--default.player_attached = {}

--function default.player_get_animation(player)
-- local name = player:get_player_name()
-- return {
-- model = player_model[name],
-- textures = player_textures[name],
-- animation = player_anim[name],
-- }
--end

-- Called when a player's appearance needs to be updated
function default.player_set_model(player, model_name)
local name = player:get_player_name()
local model = models[model_name]
if model then
if player_model[name] == model_name then
return
end
player:set_properties({
mesh = model_name,
textures = player_textures[name] or model.textures,
visual = "mesh",
visual_size = model.visual_size or {x = 1, y = 1},
collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
stepheight = model.stepheight or 0.6,
eye_height = model.eye_height or 1.47,
})
default.player_set_animation(player, "stand")
else
player:set_properties({
textures = {"player.png", "player_back.png"},
visual = "upright_sprite",
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3},
stepheight = 0.6,
eye_height = 1.625,
})
end
player_model[name] = model_name
end

function default.player_set_textures(player, textures)
local name = player:get_player_name()
local model = models[player_model[name]]
local model_textures = model and model.textures or nil
player_textures[name] = textures or model_textures
player:set_properties({textures = textures or model_textures,})
end

function default.player_set_animation(player, anim_name, speed)
local name = player:get_player_name()
if player_anim[name] == anim_name then
return
end
local model = player_model[name] and models[player_model[name]]
if not (model and model.animations[anim_name]) then
return
end
local anim = model.animations[anim_name]
player_anim[name] = anim_name
player:set_animation(anim, speed or model.animation_speed, animation_blend)
end

minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
player_model[name] = nil
player_anim[name] = nil
player_textures[name] = nil
end)
--function default.player_set_model(player, model_name)
-- local name = player:get_player_name()
-- local model = models[model_name]
-- if model then
-- if player_model[name] == model_name then
-- return
-- end
-- player:set_properties({
-- mesh = model_name,
-- textures = player_textures[name] or model.textures,
-- visual = "mesh",
-- visual_size = model.visual_size or {x = 1, y = 1},
-- collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
-- stepheight = model.stepheight or 0.6,
-- eye_height = model.eye_height or 1.47,
-- })
-- default.player_set_animation(player, "stand")
-- else
-- player:set_properties({
-- textures = {"player.png", "player_back.png"},
-- visual = "upright_sprite",
-- collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3},
-- stepheight = 0.6,
-- eye_height = 1.625,
-- })
-- end
-- player_model[name] = model_name
--end

--function default.player_set_textures(player, textures)
-- local name = player:get_player_name()
-- local model = models[player_model[name]]
-- local model_textures = model and model.textures or nil
-- player_textures[name] = textures or model_textures
-- player:set_properties({textures = textures or model_textures,})
--end

--function default.player_set_animation(player, anim_name, speed)
-- local name = player:get_player_name()
-- if player_anim[name] == anim_name then
-- return
-- end
-- local model = player_model[name] and models[player_model[name]]
-- if not (model and model.animations[anim_name]) then
-- return
-- end
-- local anim = model.animations[anim_name]
-- player_anim[name] = anim_name
-- player:set_animation(anim, speed or model.animation_speed, animation_blend)
--end

--minetest.register_on_leaveplayer(function(player)
-- local name = player:get_player_name()
-- player_model[name] = nil
-- player_anim[name] = nil
-- player_textures[name] = nil
--end)

-- Localize for better performance.
local player_set_animation = default.player_set_animation
local player_attached = default.player_attached
--local player_set_animation = player_api.set_animation
--local player_attached = player_api.player_attached

-- Check each player and apply animations
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local model_name = player_model[name]
local model = model_name and models[model_name]
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

-- Determine if the player is walking
if controls.up or controls.down or controls.left or controls.right then
walking = true
end

-- Determine if the player is sneaking, and reduce animation speed if so
if controls.sneak then
animation_speed_mod = animation_speed_mod / 2
end
--minetest.register_globalstep(function(dtime)
-- for _, player in pairs(minetest.get_connected_players()) do
-- local name = player:get_player_name()
-- local model_name = player_model[name]
-- local model = model_name and models[model_name]
-- 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
---
-- -- Determine if the player is walking
-- if controls.up or controls.down or controls.left or controls.right then
-- walking = true
-- end
--
-- -- Determine if the player is sneaking, and reduce animation speed if so
-- if controls.sneak then
-- animation_speed_mod = animation_speed_mod / 2
-- end

-- Apply animations based on what the player is doing
if player:get_hp() == 0 then
player_set_animation(player, "lay")
elseif walking then
if player_sneak[name] ~= controls.sneak then
player_anim[name] = nil
player_sneak[name] = controls.sneak
end
if controls.LMB then
player_set_animation(player, "walk_mine", animation_speed_mod)
else
player_set_animation(player, "walk", animation_speed_mod)
end
elseif controls.LMB then
player_set_animation(player, "mine")
else
player_set_animation(player, "stand", animation_speed_mod)
end
end
end
end)
-- if player:get_hp() == 0 then
-- player_set_animation(player, "lay")
-- elseif walking then
-- if player_sneak[name] ~= controls.sneak then
-- player_anim[name] = nil
-- player_sneak[name] = controls.sneak
-- end
-- if controls.LMB then
-- player_set_animation(player, "walk_mine", animation_speed_mod)
-- else
-- player_set_animation(player, "walk", animation_speed_mod)
-- end
-- elseif controls.LMB then
-- player_set_animation(player, "mine")
-- else
-- player_set_animation(player, "stand", animation_speed_mod)
-- end
-- end
-- end
--end)

10 changes: 5 additions & 5 deletions mods/lord_homedecor/handlers/sit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ function lord_homedecor.sit(pos, node, clicker)
local meta = minetest.get_meta(pos)
local param2 = node.param2
local name = clicker:get_player_name()

print("Вызов функции lord_homedecor.sit")
if name == meta:get_string("is_sit") then
meta:set_string("is_sit", "")
pos.y = pos.y-0.5
clicker:setpos(pos)
clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
clicker:set_physics_override(1, 1, 1)
default.player_attached[name] = false
default.player_set_animation(clicker, "stand", 30)
player_api.player_attached[name] = false
player_api.set_animation(clicker, "stand", 30)
else
meta:set_string("is_sit", clicker:get_player_name())
clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0})
clicker:set_physics_override(0, 0, 0)
clicker:setpos(pos)
default.player_attached[name] = true
default.player_set_animation(clicker, "sit", 30)
player_api.player_attached[name] = true
player_api.set_animation(clicker, "sit", 30)
if param2 == 0 then
clicker:set_look_yaw(3.15)
elseif param2 == 1 then
Expand Down
6 changes: 3 additions & 3 deletions mods/lottarmor/multiskin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ elseif minetest.get_modpath("wardrobe") then
end

function multiskin:init(player)
default.player_set_model(player, "lottarmor_character.b3d")
player_api.set_model(player, "lottarmor_character.b3d")
local name = player:get_player_name()
multiskin[name] = {
skin = MULTISKIN_DEFAULT_SKIN,
Expand Down Expand Up @@ -60,7 +60,7 @@ function multiskin:update_player_visuals(player)
end
local name = player:get_player_name()
if multiskin[name] then
default.player_set_textures(player, {
player_api.set_textures(player, {
multiskin[name].skin,
multiskin[name].armor,
multiskin[name].wielditem,
Expand Down Expand Up @@ -102,7 +102,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end)

default.player_register_model("lottarmor_character.b3d", {
player_api.register_model("lottarmor_character.b3d", {
animation_speed = 30,
textures = {
MULTISKIN_DEFAULT_SKIN,
Expand Down
Loading

0 comments on commit bc01bbd

Please sign in to comment.