mirror of
https://github.com/ElCeejo/animalia.git
synced 2025-03-21 15:21:22 +00:00
Fix crash, Fix player visual
This commit is contained in:
parent
a79938c09a
commit
8a34dce37c
4 changed files with 38 additions and 35 deletions
24
api/api.lua
24
api/api.lua
|
@ -298,9 +298,11 @@ function animalia.find_collision(self, dir)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function animalia.random_drop_item(item, chance)
|
function animalia.random_drop_item(self, item, chance)
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
if not pos then return end
|
||||||
if random(chance) < 2 then
|
if random(chance) < 2 then
|
||||||
local object = minetest.add_item(ItemStack(item))
|
local object = minetest.add_item(pos, ItemStack(item))
|
||||||
object:add_velocity({
|
object:add_velocity({
|
||||||
x = random(-2, 2),
|
x = random(-2, 2),
|
||||||
y = 1.5,
|
y = 1.5,
|
||||||
|
@ -520,7 +522,7 @@ function animalia.mount(self, player, params)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
player:set_eye_offset()
|
player:set_eye_offset()
|
||||||
if player_api then
|
if minetest.get_modpath("player_api") then
|
||||||
animate_player(player, "stand", 30)
|
animate_player(player, "stand", 30)
|
||||||
if player_api.player_attached then
|
if player_api.player_attached then
|
||||||
player_api.player_attached[player:get_player_name()] = false
|
player_api.player_attached[player:get_player_name()] = false
|
||||||
|
@ -532,23 +534,13 @@ function animalia.mount(self, player, params)
|
||||||
if player_api then
|
if player_api then
|
||||||
player_api.player_attached[player:get_player_name()] = true
|
player_api.player_attached[player:get_player_name()] = true
|
||||||
end
|
end
|
||||||
minetest.after(0.2, function()
|
if minetest.get_modpath("player_api") then
|
||||||
if player
|
animate_player(player, "sit", 30)
|
||||||
and player:is_player()
|
end
|
||||||
and player_api then
|
|
||||||
animate_player(player, "sit", 30)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
self.rider = player
|
self.rider = player
|
||||||
local mob_size = self.object:get_properties().visual_size
|
local mob_size = self.object:get_properties().visual_size
|
||||||
local player_size = player:get_properties().visual_size
|
local player_size = player:get_properties().visual_size
|
||||||
player:set_attach(self.object, "Torso", params.pos, params.rot)
|
player:set_attach(self.object, "Torso", params.pos, params.rot)
|
||||||
player:set_properties({
|
|
||||||
visual_size = {
|
|
||||||
x = player_size.x / mob_size.x,
|
|
||||||
y = player_size.y / mob_size.y
|
|
||||||
}
|
|
||||||
})
|
|
||||||
player:set_eye_offset({x = 0, y = 25, z = 0}, {x = 0, y = 15, z = 15})
|
player:set_eye_offset({x = 0, y = 25, z = 0}, {x = 0, y = 15, z = 15})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1010,18 +1010,37 @@ creatura.register_utility("animalia:bother_player", function(self, player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
creatura.register_utility("animalia:mount_horse", function(self, player)
|
creatura.register_utility("animalia:mount_horse", function(self, player)
|
||||||
|
if not player or not player:get_properties() then return end
|
||||||
|
local player_size = player:get_properties().visual_size
|
||||||
|
local mob_size = self.visual_size
|
||||||
|
local adj_size = {
|
||||||
|
x = player_size.x / mob_size.x,
|
||||||
|
y = player_size.y / mob_size.y
|
||||||
|
}
|
||||||
local function func(_self)
|
local function func(_self)
|
||||||
if not creatura.is_alive(player) then
|
if not creatura.is_alive(player) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local anim = "stand"
|
local anim = "stand"
|
||||||
|
local speed_x = 0
|
||||||
|
local tyaw = player:get_look_horizontal()
|
||||||
local control = player:get_player_control()
|
local control = player:get_player_control()
|
||||||
local speed_factor = 0
|
|
||||||
local vel = _self.object:get_velocity()
|
local vel = _self.object:get_velocity()
|
||||||
|
if not tyaw then return end
|
||||||
|
if _self:timer(1) then
|
||||||
|
local player_props = player:get_properties()
|
||||||
|
if player_props.visual_size.x ~= adj_size.x then
|
||||||
|
player:set_properties({
|
||||||
|
visual_size = adj_size
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
if control.up then
|
if control.up then
|
||||||
speed_factor = 1
|
speed_x = 1
|
||||||
|
anim = "walk"
|
||||||
if control.aux1 then
|
if control.aux1 then
|
||||||
speed_factor = 1.5
|
speed_x = 1.5
|
||||||
|
anim = "run"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if control.jump
|
if control.jump
|
||||||
|
@ -1032,26 +1051,18 @@ creatura.register_utility("animalia:mount_horse", function(self, player)
|
||||||
z = 0
|
z = 0
|
||||||
})
|
})
|
||||||
elseif not _self.touching_ground then
|
elseif not _self.touching_ground then
|
||||||
speed_factor = speed_factor * 0.5
|
speed_x = speed_x * 0.5
|
||||||
end
|
end
|
||||||
local total_speed = vector.length(vel)
|
if not _self.touching_ground
|
||||||
if total_speed > 0.2 then
|
and not _self.in_liquid
|
||||||
anim = "walk"
|
and vel.y > 0 then
|
||||||
if control.aux1 then
|
anim = "rear"
|
||||||
anim = "run"
|
|
||||||
end
|
|
||||||
if not _self.touching_ground
|
|
||||||
and not _self.in_liquid
|
|
||||||
and vel.y > 0 then
|
|
||||||
anim = "rear_constant"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
local tyaw = player:get_look_horizontal()
|
|
||||||
if abs(yaw - tyaw) > 0.1 then
|
if abs(yaw - tyaw) > 0.1 then
|
||||||
_self:turn_to(tyaw)
|
_self:turn_to(tyaw)
|
||||||
end
|
end
|
||||||
_self:set_forward_velocity(_self.speed * speed_factor)
|
_self:set_forward_velocity(_self.speed * speed_x)
|
||||||
_self:animate(anim)
|
_self:animate(anim)
|
||||||
if control.sneak
|
if control.sneak
|
||||||
or not _self.rider then
|
or not _self.rider then
|
||||||
|
|
|
@ -172,7 +172,7 @@ creatura.register_mob("animalia:chicken", {
|
||||||
self:animate("fall")
|
self:animate("fall")
|
||||||
end
|
end
|
||||||
if self:timer(60) then
|
if self:timer(60) then
|
||||||
animalia.random_drop_item("animalia:chicken_egg", 3)
|
animalia.random_drop_item(self, "animalia:chicken_egg", 3)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
death_func = function(self)
|
death_func = function(self)
|
||||||
|
|
|
@ -161,7 +161,7 @@ creatura.register_mob("animalia:turkey", {
|
||||||
self:animate("fall")
|
self:animate("fall")
|
||||||
end
|
end
|
||||||
if self:timer(60) then
|
if self:timer(60) then
|
||||||
animalia.random_drop_item("animalia:chicken_egg", 3)
|
animalia.random_drop_item(self, "animalia:chicken_egg", 3)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
death_func = function(self)
|
death_func = function(self)
|
||||||
|
|
Loading…
Add table
Reference in a new issue