Fix crash, Fix player visual

This commit is contained in:
ElCeejo 2022-08-15 17:30:07 -07:00
parent a79938c09a
commit 8a34dce37c
4 changed files with 38 additions and 35 deletions

View File

@ -298,9 +298,11 @@ function animalia.find_collision(self, dir)
return nil
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
local object = minetest.add_item(ItemStack(item))
local object = minetest.add_item(pos, ItemStack(item))
object:add_velocity({
x = random(-2, 2),
y = 1.5,
@ -520,7 +522,7 @@ function animalia.mount(self, player, params)
}
})
player:set_eye_offset()
if player_api then
if minetest.get_modpath("player_api") then
animate_player(player, "stand", 30)
if player_api.player_attached then
player_api.player_attached[player:get_player_name()] = false
@ -532,23 +534,13 @@ function animalia.mount(self, player, params)
if player_api then
player_api.player_attached[player:get_player_name()] = true
end
minetest.after(0.2, function()
if player
and player:is_player()
and player_api then
animate_player(player, "sit", 30)
end
end)
if minetest.get_modpath("player_api") then
animate_player(player, "sit", 30)
end
self.rider = player
local mob_size = self.object:get_properties().visual_size
local player_size = player:get_properties().visual_size
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})
end

View File

@ -1010,18 +1010,37 @@ creatura.register_utility("animalia:bother_player", function(self, player)
end)
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)
if not creatura.is_alive(player) then
return true
end
local anim = "stand"
local speed_x = 0
local tyaw = player:get_look_horizontal()
local control = player:get_player_control()
local speed_factor = 0
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
speed_factor = 1
speed_x = 1
anim = "walk"
if control.aux1 then
speed_factor = 1.5
speed_x = 1.5
anim = "run"
end
end
if control.jump
@ -1032,26 +1051,18 @@ creatura.register_utility("animalia:mount_horse", function(self, player)
z = 0
})
elseif not _self.touching_ground then
speed_factor = speed_factor * 0.5
speed_x = speed_x * 0.5
end
local total_speed = vector.length(vel)
if total_speed > 0.2 then
anim = "walk"
if control.aux1 then
anim = "run"
end
if not _self.touching_ground
and not _self.in_liquid
and vel.y > 0 then
anim = "rear_constant"
end
if not _self.touching_ground
and not _self.in_liquid
and vel.y > 0 then
anim = "rear"
end
local yaw = self.object:get_yaw()
local tyaw = player:get_look_horizontal()
if abs(yaw - tyaw) > 0.1 then
_self:turn_to(tyaw)
end
_self:set_forward_velocity(_self.speed * speed_factor)
_self:set_forward_velocity(_self.speed * speed_x)
_self:animate(anim)
if control.sneak
or not _self.rider then

View File

@ -172,7 +172,7 @@ creatura.register_mob("animalia:chicken", {
self:animate("fall")
end
if self:timer(60) then
animalia.random_drop_item("animalia:chicken_egg", 3)
animalia.random_drop_item(self, "animalia:chicken_egg", 3)
end
end,
death_func = function(self)

View File

@ -161,7 +161,7 @@ creatura.register_mob("animalia:turkey", {
self:animate("fall")
end
if self:timer(60) then
animalia.random_drop_item("animalia:chicken_egg", 3)
animalia.random_drop_item(self, "animalia:chicken_egg", 3)
end
end,
death_func = function(self)