Fix multiple crashes, Improve multiple behaviors, Re-animate Horses

This commit is contained in:
ElCeejo 2022-02-20 11:45:25 -08:00
parent d9b868b926
commit 31c0232697
24 changed files with 923 additions and 184 deletions

View file

@ -96,6 +96,7 @@ creatura.register_mob("animalia:bat", {
},
},
catch_with_net = true,
catch_with_lasso = false,
follow = {
"butterflies:butterfly_red",
"butterflies:butterfly_white",
@ -120,6 +121,7 @@ creatura.register_mob("animalia:bat", {
local pos = self.object:get_pos()
local player = creatura.get_nearby_player(self)
if player
and player:get_pos()
and not player:get_player_control().sneak then
local dist = vector.distance(pos, player:get_pos())
self._nearby_player = player
@ -149,7 +151,8 @@ creatura.register_mob("animalia:bat", {
get_score = function(self)
if not self.home_position then return 0 end
local player = self._nearby_player
if player then
if player
and player:get_pos() then
local pos = self.object:get_pos()
local dist = vector.distance(pos, player:get_pos())
if dist < 9 then

View file

@ -2,6 +2,17 @@
-- Song Bird --
---------------
local follows = {}
minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_items) do
if name:match(":seed_")
or name:match("_seed") then
table.insert(follows, name)
end
end
end)
local random = math.random
local function clamp(val, min, max)
@ -45,6 +56,7 @@ creatura.register_mob("animalia:bird", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = false,
sounds = {
cardinal = {
name = "animalia_cardinal",
@ -87,7 +99,8 @@ creatura.register_mob("animalia:bird", {
return 0.15, {self, 1}
end
local player = creatura.get_nearby_player(self)
if player then
if player
and player:get_pos() then
local dist = vector.distance(pos, player:get_pos())
self.is_landed = false
return (16 - dist) * 0.1, {self, 1}
@ -112,7 +125,7 @@ creatura.register_mob("animalia:bird", {
animalia.initialize_api(self)
animalia.initialize_lasso(self)
self.trust = self:recall("trust") or {}
self.is_landed = self:recall("is_landed") or true
self.is_landed = self:recall("is_landed") or false
self.stamina = self:recall("stamina") or 0.1
self._path = {}
end,

View file

@ -45,6 +45,7 @@ creatura.register_mob("animalia:cat", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_cat_idle",
@ -93,9 +94,9 @@ creatura.register_mob("animalia:cat", {
end,
utility_stack = {
[1] = {
utility = "animalia:wander",
utility = "animalia:skittish_wander",
get_score = function(self)
return 0.1, {self, true}
return 0.1, {self}
end
},
[2] = {
@ -117,7 +118,8 @@ creatura.register_mob("animalia:cat", {
utility = "animalia:walk_ahead_of_player",
get_score = function(self)
local player = creatura.get_nearby_player(self)
if player then
if player
and player:get_player_name() then
local trust = 0
if not self.trust[player:get_player_name()] then
self.trust[player:get_player_name()] = 0
@ -136,29 +138,6 @@ creatura.register_mob("animalia:cat", {
end
},
[5] = {
utility = "animalia:flee_from_player",
get_score = function(self)
local player = self._nearby_player
if player then
local trust = self.trust[player:get_player_name()] or 0
if trust < 1 then
if self.owner
and minetest.get_player_by_name(self.owner) then
local pos = self.object:get_pos()
local owner = minetest.get_player_by_name(self.owner)
local owner_pos = owner:get_pos()
if owner ~= player
and vector.distance(pos, owner_pos) < vector.distance(pos, player:get_pos()) then
return 0
end
end
return 0.5, {self, player}
end
end
return 0
end
},
[6] = {
utility = "animalia:sit",
get_score = function(self)
if self.order == "sit"
@ -168,7 +147,7 @@ creatura.register_mob("animalia:cat", {
return 0
end
},
[7] = {
[6] = {
utility = "animalia:follow_player",
get_score = function(self)
if self.order == "follow"
@ -178,7 +157,8 @@ creatura.register_mob("animalia:cat", {
end
local trust = 0
local player = self._nearby_player
if player then
if player
and player:get_player_name() then
if not self.trust[player:get_player_name()] then
self.trust[player:get_player_name()] = 0
self:memorize("trust", self.trust)
@ -199,7 +179,7 @@ creatura.register_mob("animalia:cat", {
return 0
end
},
[8] = {
[7] = {
utility = "animalia:mammal_breed",
get_score = function(self)
if self.breeding then

View file

@ -51,6 +51,7 @@ creatura.register_mob("animalia:chicken", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_chicken_idle",

View file

@ -57,6 +57,7 @@ creatura.register_mob("animalia:cow", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_cow_random",

View file

@ -42,6 +42,7 @@ creatura.register_mob("animalia:frog", {
-- Misc
makes_footstep_sound = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_frog",
@ -116,7 +117,8 @@ creatura.register_mob("animalia:frog", {
get_score = function(self)
if self.in_liquid then return 0 end
local player = creatura.get_nearby_player(self)
if player then
if player
and player:get_player_name() then
local trust = self.trust[player:get_player_name()] or 0
self._nearby_player = player -- stored to memory to avoid calling get_nearby_player again
return (10 - (vec_dist(self.object:get_pos(), player:get_pos()) + trust)) * 0.1, {self, player}
@ -132,7 +134,8 @@ creatura.register_mob("animalia:frog", {
local water = minetest.find_nodes_in_area(vector.subtract(pos, 1.5), vector.add(pos, 1.5), {"default:water_source"})
if not water[1] then return 0 end
local player = self._nearby_player
if player then
if player
and player:get_player_name() then
local trust = self.trust[player:get_player_name()] or 0
return (10 - (vec_dist(self.object:get_pos(), player:get_pos()) + trust)) * 0.1, {self, player}
end

View file

@ -83,13 +83,15 @@ creatura.register_mob("animalia:horse", {
},
animations = {
stand = {range = {x = 1, y = 60}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 70, y = 110}, speed = 25, frame_blend = 0.3, loop = true},
run = {range = {x = 70, y = 110}, speed = 45, frame_blend = 0.3, loop = true},
rear = {range = {x = 120, y = 150}, speed = 27, frame_blend = 0.2, loop = false},
rear_constant = {range = {x = 130, y = 140}, speed = 20, frame_blend = 0.3, loop = true}
walk = {range = {x = 70, y = 110}, speed = 30, frame_blend = 0.3, loop = true},
run = {range = {x = 120, y = 140}, speed = 30, frame_blend = 0.3, loop = true},
rear = {range = {x = 150, y = 180}, speed = 27, frame_blend = 0.2, loop = false},
rear_constant = {range = {x = 160, y = 170}, speed = 20, frame_blend = 0.3, loop = true},
eat = {range = {x = 190, y = 220}, speed = 20, frame_blend = 0.3, loop = false}
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
alter_child_pitch = true,
random = {
@ -125,8 +127,8 @@ creatura.register_mob("animalia:horse", {
},
head_data = {
bone = "Neck.CTRL",
offset = {x = 0, y = 2, z = 0},
pitch_correction = 35,
offset = {x = 0, y = 1.2, z = 0.15},
pitch_correction = 45,
pivot_h = 1,
pivot_v = 1.5
},
@ -237,7 +239,7 @@ creatura.register_mob("animalia:horse", {
else
self.breaking_progress = self.breaking_progress - 1
end
self:initiate_utility("animalia:sporadic_flee", self, puncher, true)
self:initiate_utility("animalia:horse_breaking", self)
if self.breaking_progress < -5
or minetest.get_player_by_name(self.breaker):get_player_control().sneak then
animalia.mount(self, minetest.get_player_by_name(self.breaker))
@ -256,7 +258,6 @@ creatura.register_mob("animalia:horse", {
local minppos = vector.add(prt_pos, 1)
local maxppos = vector.subtract(prt_pos, 1)
animalia.particle_spawner(prt_pos, "creatura_particle_green.png", "float", minppos, maxppos)
self:clear_behavior()
end
end
end

View file

@ -67,6 +67,7 @@ creatura.register_mob("animalia:pig", {
consumable_nodes = destroyable_crops,
birth_count = 2,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_pig_idle",

View file

@ -27,6 +27,7 @@ creatura.register_mob("animalia:reindeer", {
despawn_after = 1500,
-- Entity Physics
stepheight = 1.1,
turn_rate = 4,
-- Visuals
mesh = "animalia_reindeer.b3d",
hitbox = {
@ -43,6 +44,7 @@ creatura.register_mob("animalia:reindeer", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
drops = {
{name = "animalia:venison_raw", min = 1, max = 3, chance = 1},
{name = "animalia:leather", min = 1, max = 3, chance = 2}

View file

@ -71,6 +71,7 @@ creatura.register_mob("animalia:sheep", {
use_texture_alpha = true,
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_sheep_idle",

View file

@ -34,6 +34,7 @@ creatura.register_mob("animalia:tropical_fish", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = false,
makes_footstep_sound = false,
-- Function
utility_stack = {

View file

@ -42,6 +42,7 @@ creatura.register_mob("animalia:turkey", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_turkey_idle",

View file

@ -36,7 +36,7 @@ creatura.register_mob("animalia:wolf", {
armor_groups = {fleshy = 100},
damage = 4,
speed = 5,
tracking_range = 32,
tracking_range = 24,
despawn_after = 2000,
-- Entity Physics
stepheight = 1.1,
@ -57,6 +57,7 @@ creatura.register_mob("animalia:wolf", {
},
-- Misc
catch_with_net = true,
catch_with_lasso = true,
assist_owner = true,
follow = follow,
head_data = {
@ -68,7 +69,7 @@ creatura.register_mob("animalia:wolf", {
-- Function
utility_stack = {
[1] = {
utility = "animalia:wander",
utility = "animalia:skittish_boid_wander",
get_score = function(self)
return 0.1, {self, true}
end
@ -88,7 +89,8 @@ creatura.register_mob("animalia:wolf", {
local target = creatura.get_nearby_entity(self, "animalia:sheep")
local player = self._nearby_player
local is_attacking = self:get_utility() == "animalia:attack"
if player then
if player
and player:get_player_name() then
if is_value_in_table(self.enemies, player:get_player_name()) then
local nearby_players = creatura.get_nearby_players(self)
local nearby_allies = creatura.get_nearby_entities(self, self.name)
@ -111,7 +113,8 @@ creatura.register_mob("animalia:wolf", {
utility = "animalia:flee_from_player",
get_score = function(self)
local player = self._nearby_player
if player then
if player
and player:get_player_name() then
if is_value_in_table(self.enemies, player:get_player_name()) then
local nearby_players = creatura.get_nearby_players(self)
local nearby_allies = creatura.get_nearby_entities(self, self.name)