Harvest Update

This commit is contained in:
ElCeejo 2022-10-17 17:23:26 -07:00
parent d1453b9501
commit 4642fb63fd
56 changed files with 1689 additions and 972 deletions

View file

@ -2,119 +2,76 @@
-- Bat --
---------
local guano_accumulation = minetest.settings:get_bool("guano_accumulation")
-- Math --
local function clamp(val, min, max)
if val < min then
val = min
elseif max < val then
val = max
end
return val
end
local random = math.random
local floor = math.floor
-- Vector Math --
local vec_dist = vector.distance
local vec_add = vector.add
local function vec_raise(v, n)
return {x = v.x, y = v.y + n, z = v.z}
end
---------------
-- Utilities --
---------------
local function get_roost(pos, range)
local walkable = minetest.find_nodes_in_area(
{x = pos.x + range, y = pos.y + range, z = pos.z + range},
{x = pos.x - range, y = pos.y, z = pos.z - range},
animalia.walkable_nodes
local function get_home_pos(self)
local pos = self.object:get_pos()
if not pos then return end
local nodes = minetest.find_nodes_in_area(
vector.subtract(pos, 16),
vector.add(pos, 16),
{"group:leaves", "group:stone"}
)
if #walkable < 1 then return end
local roosts = {}
for i = 1, #walkable do
local i_pos = walkable[i]
local n_pos = {
x = i_pos.x,
y = i_pos.y - 1,
z = i_pos.z
}
if creatura.get_node_def(n_pos).name == "air"
and minetest.line_of_sight(pos, n_pos) then
table.insert(roosts, n_pos)
local home_dist
local new_home
for _, n_pos in ipairs(nodes or {}) do
local dist = vec_dist(pos, n_pos)
if not home_dist
or dist < home_dist then
n_pos.y = n_pos.y - 1
if creatura.get_node_def(n_pos).name == "air" then
home_dist = dist
new_home = n_pos
end
end
end
return roosts[random(#roosts)]
end
local function is_node_walkable(name)
local def = minetest.registered_nodes[name]
return def and def.walkable
if new_home then
self.home_position = self:memorize("home_position", new_home)
end
end
creatura.register_mob("animalia:bat", {
-- Stats
max_health = 5,
armor_groups = {fleshy = 200},
damage = 0,
speed = 4,
tracking_range = 16,
despawn_after = 2500,
-- Entity Physics
stepheight = 1.1,
max_fall = 0,
turn_rate = 12,
-- Visuals
-- Engine Props
visual = "mesh",
visual_size = {x = 10, y = 10},
mesh = "animalia_bat.b3d",
textures = {
"animalia_bat_1.png",
"animalia_bat_2.png",
"animalia_bat_3.png",
},
makes_footstep_sound = false,
stepheight = 1.1,
-- Creatura Props
max_health = 5,
armor_groups = {fleshy = 100},
damage = 0,
speed = 6,
tracking_range = 8,
max_boids = 2,
despawn_after = 500,
max_fall = 0,
hitbox = {
width = 0.15,
height = 0.3
},
visual_size = {x = 7, y = 7},
textures = {
"animalia_bat_1.png",
"animalia_bat_2.png",
"animalia_bat_3.png"
},
animations = {
stand = {range = {x = 1, y = 40}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 50, y = 90}, speed = 30, frame_blend = 0.3, loop = true},
fly = {range = {x = 100, y = 140}, speed = 80, frame_blend = 0.3, loop = true},
cling = {range = {x = 150, y = 150}, speed = 1, frame_blend = 0, loop = false}
walk = {range = {x = 51, y = 69}, speed = 30, frame_blend = 0.3, loop = true},
fly = {range = {x = 81, y = 99}, speed = 80, frame_blend = 0.3, loop = true},
cling = {range = {x = 110, y = 110}, speed = 1, frame_blend = 0, loop = false}
},
-- Misc
sounds = {
random = {
name = "animalia_bat",
gain = 0.5,
distance = 16,
variations = 2
},
},
catch_with_net = true,
catch_with_lasso = false,
follow = {
"butterflies:butterfly_red",
"butterflies:butterfly_white",
"butterflies:butterfly_violet"
},
-- Function
fancy_collide = false,
bouyancy_multiplier = 1,
hydrodynamics_multiplier = 1,
roost_action = animalia.action_cling,
utility_stack = {
{
utility = "animalia:wander",
step_delay = 0.25,
get_score = function(self)
return 0.1, {self}
end
},
{
utility = "animalia:aerial_wander",
step_delay = 0.25,
@ -128,119 +85,101 @@ creatura.register_mob("animalia:bat", {
local dist = vec_dist(pos, plyr_pos)
self._target = player
self.is_landed = false
return (12 - (dist + trust)) * 0.1, {self}
return (self.tracking_range - dist) / self.tracking_range, {self}
end
if self.in_liquid
or not self.is_landed then
return 0.2, {self}
end
return 0
return 0.1, {self}
end
},
{
utility = "animalia:fly_to_land",
utility = "animalia:swim_to_land",
step_delay = 0.25,
get_score = function(self)
if self.is_landed
and not self.touching_ground
and not self.in_liquid
and creatura.sensor_floor(self, 3, true) > 2 then
if self.in_liquid then
return 0.3, {self}
end
return 0
end
},
[4] = {
{
utility = "animalia:fly_to_roost",
get_score = function(self)
local pos = self.object:get_pos()
if not pos then return end
local home = animalia.is_day and self.home_position
if home
if (home
and home.x
and vec_dist(pos, home) < 8 then
and vec_dist(pos, home) < 8)
or self.is_landed then
return 0.6, {self}
end
return 0
end
}
},
-- Animalia Props
catch_with_net = true,
catch_with_lasso = false,
-- Functions
is_home = function(pos, home_pos)
local dist = vec_dist(pos, home_pos)
if dist < 4 then
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
if creatura.get_node_def(above).walkable
or dist < 1 then
return true
end
end
return false
end,
activate_func = function(self)
animalia.initialize_api(self)
animalia.initialize_lasso(self)
self.home_position = self:recall("home_position") or nil
local home_pos = self.home_position
self.is_landed = self:recall("is_landed") or false
self.trust = self:recall("trust") or {}
if not self.home_position then
local roost = get_roost(self.object:get_pos(), 8)
if roost then
self.home_position = self:memorize("home_position", roost)
end
if not home_pos
or not creatura.get_node_def(home_pos).walkable then
get_home_pos(self)
end
end,
step_func = function(self)
animalia.step_timers(self)
--animalia.head_tracking(self, 0.75, 0.75)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.rotate_to_pitch(self)
local pos = self.object:get_pos()
if not pos then return end
if self:timer(random(10,15)) then
if random(4) < 2 then
self.is_landed = not self.is_landed
end
if not self.home_position
or creatura.get_node_def(self.home_position).walkable then
local roost = get_roost(pos, 8)
if roost then
self.home_position = self:memorize("home_position", roost)
end
end
animalia.random_sound(self)
if not self.is_landed
or not self.touching_ground then
self.speed = 4
else
self.speed = 1
end
if self._anim == "fly" then
local vel_y = vector.normalize(self.object:get_velocity()).y
local rot = self.object:get_rotation()
local n_rot = rot.x + (vel_y - rot.x) * 0.2
self.object:set_rotation({
x = clamp(n_rot, -0.75, 0.75),
y = rot.y,
z = rot.z
})
end
if self:timer(random(3, 4)) then
self:play_sound("random")
if guano_accumulation
and random(16) < 2
and self:get_utility() == "animalia:fly_to_roost" then
pos = {
x = floor(pos.x + 0.5),
y = floor(pos.y + 0.5),
z = floor(pos.z + 0.5)
}
if not is_node_walkable(minetest.get_node(vec_raise(pos, 1)).name) then
return
end
local fail_safe = 1
while not is_node_walkable(minetest.get_node(pos).name)
and fail_safe < 16 do
pos.y = pos.y - 1
end
if is_node_walkable(minetest.get_node(pos).name) then
if minetest.get_node(vec_raise(pos, 1)).name ~= "animalia:guano" then
minetest.set_node(vec_raise(pos, 1), {name = "animalia:guano"})
else
local nodes = minetest.find_nodes_in_area_under_air(
vector.subtract(pos, 3),
vec_add(pos, 3),
animalia.walkable_nodes
)
if #nodes > 0 then
pos = nodes[random(#nodes)]
if minetest.get_node(vec_raise(pos, 1)).name ~= "animalia:guano" then
minetest.set_node(vec_raise(pos, 1), {name = "animalia:guano"})
end
if self:timer(10)
and math.random(10) < 2 then
local anim = self._anim or ""
if anim == "cling" then
local colony = creatura.get_nearby_objects(self, self.name)
local pos = self.object:get_pos()
if not pos then return end
local center = pos
if #colony > 0 then
local pos_sum = center
local pos_ttl = 1
for _, object in ipairs(colony) do
local obj_pos = object and object:get_pos()
if obj_pos then
pos_sum = vector.add(pos_sum, obj_pos)
pos_ttl = pos_ttl + 1
end
end
center = vector.divide(pos_sum, pos_ttl)
end
center = creatura.get_ground_level(center, 8)
if center.y < pos.y then
local under = {x = center.x, y = center.y - 1, z = center.z}
if creatura.get_node_def(under).walkable
and not minetest.is_protected(center, "") then
minetest.set_node(center, {name = "animalia:guano"})
end
end
end
end
@ -259,9 +198,7 @@ creatura.register_mob("animalia:bat", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:bat", "392517", "321b0b")

View file

@ -24,7 +24,7 @@ creatura.register_mob("animalia:bird", {
damage = 0,
speed = 4,
tracking_range = 16,
despawn_after = 100,
despawn_after = 750,
-- Entity Physics
stepheight = 1.1,
max_fall = 0,
@ -48,6 +48,7 @@ creatura.register_mob("animalia:bird", {
fly = {range = {x = 120, y = 140}, speed = 80, frame_blend = 0.3, loop = true}
},
-- Misc
max_boids = 12,
makes_footstep_sound = true,
catch_with_net = true,
catch_with_lasso = false,
@ -73,7 +74,7 @@ creatura.register_mob("animalia:bird", {
},
follow = follows,
-- Function
wander_action = animalia.action_move_flock,
wander_action = animalia.action_move_boid,
utility_stack = {
{
utility = "animalia:wander_group",
@ -155,7 +156,7 @@ creatura.register_mob("animalia:bird", {
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.rotate_to_pitch(self)
if self:timer(random(10,15)) then
if self:timer(random(6,12)) then
if animalia.is_day then
if self.texture_no == 1 then
self:play_sound("cardinal")
@ -213,9 +214,7 @@ creatura.register_mob("animalia:bird", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:bird", "ae2f2f", "f3ac1c")

View file

@ -34,7 +34,7 @@ creatura.register_mob("animalia:cat", {
width = 0.2,
height = 0.4
},
visual_size = {x = 6, y = 6},
visual_size = {x = 10, y = 10},
textures = {
"animalia_cat_1.png",
"animalia_cat_2.png",
@ -58,6 +58,7 @@ creatura.register_mob("animalia:cat", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -179,7 +180,8 @@ creatura.register_mob("animalia:cat", {
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local lasso_tgt = self._lassod_to
local lasso = type(lasso_tgt) == "string" and minetest.get_player_by_name(lasso_tgt)
local trust = (self.owner and self.trust[self.owner]) or 0
local owner = self.owner and self.order == "follow" and trust > 4 and minetest.get_player_by_name(self.owner)
local force = (lasso and lasso ~= false) or (owner and owner ~= false)
@ -191,13 +193,25 @@ creatura.register_mob("animalia:cat", {
return 0
end
},
{
utility = "animalia:attack_target",
get_score = function(self)
local target = self._target or creatura.get_nearby_object(self, "animalia:rat")
local tgt_pos = target and target:get_pos()
if tgt_pos
and self:is_pos_safe(tgt_pos) then
return 0.7, {self, target}
end
return 0
end
},
{
utility = "animalia:breed",
step_delay = 0.25,
get_score = function(self)
if self.breeding
and animalia.get_nearby_mate(self, self.name) then
return 0.7, {self}
return 0.8, {self}
end
return 0
end

View file

@ -52,6 +52,7 @@ creatura.register_mob("animalia:chicken", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -124,19 +125,7 @@ creatura.register_mob("animalia:chicken", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.3, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
@ -148,18 +137,7 @@ creatura.register_mob("animalia:chicken", {
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local puncher = self._target
if puncher
and puncher:get_pos() then
return 0.6, {self, puncher}
end
self._target = nil
return 0
end
}
animalia.global_utils.basic_flee
},
activate_func = function(self)
animalia.initialize_api(self)
@ -194,10 +172,7 @@ creatura.register_mob("animalia:chicken", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:chicken", "c6c6c6", "d22222")

View file

@ -59,7 +59,7 @@ creatura.register_mob("animalia:cow", {
run = {range = {x = 61, y = 79}, speed = 30, frame_blend = 0.3, loop = true},
},
-- Misc
step_delay = 0.25,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -123,19 +123,7 @@ creatura.register_mob("animalia:cow", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.4, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
@ -147,18 +135,7 @@ creatura.register_mob("animalia:cow", {
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local puncher = self._target
if puncher
and puncher:get_pos() then
return 0.6, {self, puncher}
end
self._target = nil
return 0
end
}
animalia.global_utils.basic_flee
},
activate_func = function(self)
animalia.initialize_api(self)
@ -215,10 +192,7 @@ creatura.register_mob("animalia:cow", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:cow", "cac3a1" ,"464438")

169
mobs/fox.lua Normal file
View file

@ -0,0 +1,169 @@
----------
-- Wolf --
----------
creatura.register_mob("animalia:fox", {
-- Stats
max_health = 15,
armor_groups = {fleshy = 100},
damage = 4,
speed = 5,
tracking_range = 24,
despawn_after = 2000,
-- Entity Physics
stepheight = 1.1,
max_fall = 3,
-- Visuals
mesh = "animalia_fox.b3d",
hitbox = {
width = 0.35,
height = 0.7
},
visual_size = {x = 10, y = 10},
textures = {
"animalia_fox_1.png",
},
animations = {
stand = {range = {x = 1, y = 39}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 41, y = 59}, speed = 30, frame_blend = 0.3, loop = true},
run = {range = {x = 41, y = 59}, speed = 45, frame_blend = 0.3, loop = true},
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
follow = {
"animalia:rat_raw",
"animalia:mutton_raw",
"animalia:beef_raw",
"animalia:porkchop_raw",
"animalia:poultry_raw"
},
head_data = {
offset = {x = 0, y = 0.18, z = 0},
pitch_correction = -67,
pivot_h = 0.65,
pivot_v = 0.65
},
-- Function
on_eat_drop = function(self)
animalia.protect_from_despawn(self)
end,
utility_stack = {
{
utility = "animalia:wander_skittish",
step_delay = 0.25,
get_score = function(self)
return 0.1, {self}
end
},
{
utility = "animalia:swim_to_land",
step_delay = 0.25,
get_score = function(self)
if self.in_liquid then
return 0.3, {self}
end
return 0
end
},
{
utility = "animalia:attack_target",
get_score = function(self)
local target = self._target or creatura.get_nearby_object(self, {"animalia:rat", "animalia:chicken"})
local tgt_pos = target and target:get_pos()
if tgt_pos
and self:is_pos_safe(tgt_pos) then
return 0.4, {self, target}
end
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local target = self._puncher or creatura.get_nearby_player(self)
local pos, tgt_pos = self.object:get_pos(), target and target:get_pos()
if not pos then return end
if not tgt_pos then self._puncher = nil return 0 end
local sneaking = target:get_player_control().sneak
if not sneaking then
local dist = vector.distance(pos, tgt_pos)
local score = (self.tracking_range - dist) / self.tracking_range
self._puncher = target
return score / 2, {self, target}
end
self._puncher = nil
return 0
end
},
{
utility = "animalia:walk_to_food",
get_score = function(self)
local cooldown = self.eat_cooldown or 0
if cooldown > 0 then
self.eat_cooldown = cooldown - 1
return 0
end
local food_item = animalia.get_dropped_food(self)
if food_item then
return 0.7, {self, food_item}
end
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso_tgt = self._lassod_to
local lasso = type(lasso_tgt) == "string" and minetest.get_player_by_name(lasso_tgt)
if lasso
and lasso:get_pos() then
return 0.6, {self, lasso, true}
end
return 0
end
},
{
utility = "animalia:breed",
step_delay = 0.25,
get_score = function(self)
if self.breeding
and animalia.get_nearby_mate(self, self.name) then
return 0.7, {self}
end
return 0
end
}
},
activate_func = function(self)
animalia.initialize_api(self)
animalia.initialize_lasso(self)
end,
step_func = function(self)
animalia.step_timers(self)
animalia.head_tracking(self, 0.5, 0.75)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
end,
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end,
on_rightclick = function(self, clicker)
if not clicker:is_player() then return end
local name = clicker:get_player_name()
local passive = true
if animalia.feed(self, clicker, passive, passive) then
return
end
if animalia.set_nametag(self, clicker) then
return
end
end,
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:fox", "d0602d" ,"c9c9c9")

View file

@ -45,6 +45,7 @@ creatura.register_mob("animalia:frog", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -128,7 +129,7 @@ creatura.register_mob("animalia:frog", {
if self.in_liquid then return 0 end
local pos = self.object:get_pos()
if not pos then return end
local target = self._target or creatura.get_nearby_player(self)
local target = self._puncher or self._target or creatura.get_nearby_player(self)
local tgt_pos = target and target:get_pos()
local plyr_name = (target and target:is_player() and target:get_player_name()) or ""
if tgt_pos then

View file

@ -100,15 +100,15 @@ creatura.register_mob("animalia:horse", {
},
animations = {
stand = {range = {x = 1, y = 59}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 61, y = 79}, speed = 20, frame_blend = 0.3, loop = true},
run = {range = {x = 81, y = 99}, speed = 30, frame_blend = 0.3, loop = true},
punch_aoe = {range = {x = 101, y = 119}, speed = 30, frame_blend = 0.2, loop = false},
rear = {range = {x = 121, y = 140}, speed = 20, frame_blend = 0.2, loop = false},
rear_constant = {range = {x = 121, y = 140}, speed = 20, frame_blend = 0.3, loop = false},
eat = {range = {x = 141, y = 160}, speed = 20, frame_blend = 0.3, loop = false}
walk = {range = {x = 71, y = 89}, speed = 25, frame_blend = 0.3, loop = true},
run = {range = {x = 101, y = 119}, speed = 40, frame_blend = 0.3, loop = true},
punch_aoe = {range = {x = 161, y = 180}, speed = 30, frame_blend = 0.2, loop = false},
rear = {range = {x = 131, y = 150}, speed = 20, frame_blend = 0.2, loop = false},
eat = {range = {x = 191, y = 220}, speed = 30, frame_blend = 0.3, loop = false}
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -116,8 +116,7 @@ creatura.register_mob("animalia:horse", {
random = {
name = "animalia_horse_idle",
gain = 1.0,
distance = 8,
variations = 3,
distance = 8
},
hurt = {
name = "animalia_horse_hurt",
@ -140,10 +139,10 @@ creatura.register_mob("animalia:horse", {
},
head_data = {
bone = "Neck.CTRL",
offset = {x = 0, y = 1.45, z = 0.0},
pitch_correction = 25,
offset = {x = 0, y = 1.05, z = 0.0},
pitch_correction = 35,
pivot_h = 1,
pivot_v = 1.5
pivot_v = 1.75
},
-- Function
add_child = function(self, mate)
@ -198,19 +197,7 @@ creatura.register_mob("animalia:horse", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.4, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
@ -263,10 +250,6 @@ creatura.register_mob("animalia:horse", {
animalia.initialize_lasso(self)
set_pattern(self)
self.owner = self:recall("owner") or nil
if self.owner then
self._despawn = nil
self.despawn_after = nil
end
self.rider = nil
self.saddled = self:recall("saddled") or false
self.max_health = self:recall("max_health") or random(30, 45)
@ -333,9 +316,7 @@ creatura.register_mob("animalia:horse", {
end,
on_punch = function(self, puncher, ...)
if self.rider and puncher == self.rider then return end
creatura.basic_punch_func(self, puncher, ...)
if self.hp < 0 then return end
self._puncher = puncher
animalia.punch(self, puncher, ...)
end
})

217
mobs/owl.lua Normal file
View file

@ -0,0 +1,217 @@
---------
-- Owl --
---------
local follows = {}
minetest.register_on_mods_loaded(function()
for name 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 vec_dist = vector.distance
local function get_home_pos(self)
local pos = self.object:get_pos()
if not pos then return end
local leaves = minetest.find_nodes_in_area_under_air(
vector.subtract(pos, 16),
vector.add(pos, 16),
"group:leaves"
)
local home_dist
local new_home
for _, leaf_pos in ipairs(leaves or {}) do
local dist = vec_dist(pos, leaf_pos)
if not home_dist
or dist < home_dist then
home_dist = dist
new_home = leaf_pos
end
end
if new_home then
new_home.y = new_home.y + 1
self.home_position = self:memorize("home_position", new_home)
end
end
creatura.register_mob("animalia:owl", {
-- Stats
max_health = 10,
armor_groups = {fleshy = 100},
damage = 2,
speed = 5,
tracking_range = 32,
despawn_after = 1000,
-- Entity Physics
stepheight = 1.1,
max_fall = 0,
turn_rate = 4,
-- Visuals
mesh = "animalia_owl.b3d",
hitbox = {
width = 0.15,
height = 0.3
},
visual_size = {x = 10, y = 10},
textures = {
"animalia_owl.png"
},
animations = {
stand = {range = {x = 1, y = 60}, speed = 20, frame_blend = 0.3, loop = true},
fly = {range = {x = 71, y = 89}, speed = 30, frame_blend = 0.3, loop = true},
glide = {range = {x = 101, y = 119}, speed = 20, frame_blend = 0.2, loop = true},
fly_punch = {range = {x = 131, y = 149}, speed = 20, frame_blend = 0.1, loop = false},
eat = {range = {x = 161, y = 179}, speed = 20, frame_blend = 0.1, loop = false}
},
-- Misc
makes_footstep_sound = true,
catch_with_net = true,
catch_with_lasso = false,
--sounds = {},
follow = {"animalia:rat_raw"},
-- Function
on_eat_drop = function(self)
animalia.protect_from_despawn(self)
get_home_pos(self)
end,
is_home = function(pos, home_pos)
if abs(pos.x - home_pos.x) < 0.5
and abs(pos.z - home_pos.z) < 0.5 then
if abs(pos.y - home_pos.y) < 0.75 then
return true
else
local under = {x = home_pos.x, y = home_pos.y, z = home_pos.z}
local name = minetest.get_node(under).name
if minetest.get_node_group(name, "leaves") > 0 then
return true
end
end
end
return false
end,
wander_action = creatura.action_move,
utility_stack = {
{
utility = "animalia:aerial_wander",
step_delay = 0.25,
get_score = function(self)
if not self.is_landed
or self.in_liquid then
return 0.1, {self}
end
return 0
end
},
{
utility = "animalia:fly_to_roost",
get_score = function(self)
local pos = self.object:get_pos()
if not pos then return end
local player = creatura.get_nearby_player(self)
local plyr_pos = player and player:get_pos()
if plyr_pos then
local dist = vector.distance(pos, plyr_pos)
if dist < 3 then
return 0
end
end
local home = animalia.is_day and self.home_position
if home
and vec_dist(pos, home) < 8 then
return 0.6, {self}
end
return 0
end
},
{
utility = "animalia:fly_to_food",
get_score = function(self)
local cooldown = self.eat_cooldown or 0
if cooldown > 0 then
self.eat_cooldown = cooldown - 1
return 0
end
local food_item = animalia.get_dropped_food(self, "animalia:rat_raw")
if food_item then
return 0.7, {self, food_item}
end
return 0
end
},
{
utility = "animalia:glide_attack_target",
get_score = function(self)
local target = self._target or creatura.get_nearby_object(self, {"animalia:rat", "animalia:bird"})
local tgt_pos = target and target:get_pos()
if tgt_pos then
return 0.4, {self, target}
end
return 0
end
},
},
activate_func = function(self)
animalia.initialize_api(self)
animalia.initialize_lasso(self)
self._tp2home = self:recall("_tp2home") or nil
self.home_position = self:recall("home_position") or nil
local home_pos = self.home_position
if self._tp2home
and home_pos then
self.object:set_pos(home_pos)
end
self.is_landed = self:recall("is_landed") or false
if not home_pos
or creatura.get_node_def(home_pos).walkable then
get_home_pos(self)
end
end,
step_func = function(self)
animalia.step_timers(self)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.rotate_to_pitch(self)
if not self.is_landed
or not self.touching_ground then
self.speed = 5
else
self.speed = 1
end
end,
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end,
deactivate_func = function(self)
if self:get_utility()
and self:get_utility() == "animalia:fly_to_roost" then
local pos = self.home_position
local node = minetest.get_node_or_nil(pos)
if node
and not creatura.get_node_def(node.name).walkable
and minetest.get_natural_light(pos) > 0 then
self:memorize("_tp2home", true)
end
end
end,
on_rightclick = function(self, clicker)
if animalia.feed(self, clicker, false, false) then
return
end
if animalia.set_nametag(self, clicker) then
return
end
end,
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:owl", "412918", "735b46")

View file

@ -67,11 +67,12 @@ creatura.register_mob("animalia:pig", {
makes_footstep_sound = true,
consumable_nodes = destroyable_crops,
birth_count = 2,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
random = {
name = "animalia_pig_idle",
name = "animalia_pig_random",
gain = 1.0,
distance = 8
},
@ -92,14 +93,14 @@ creatura.register_mob("animalia:pig", {
follow = follows,
-- Function
utility_stack = {
[1] = {
{
utility = "animalia:wander",
step_delay = 0.25,
get_score = function(self)
return 0.1, {self, true}
end
},
[2] = {
{
utility = "animalia:eat_from_turf",
step_delay = 0.25,
get_score = function(self)
@ -109,7 +110,7 @@ creatura.register_mob("animalia:pig", {
return 0
end
},
[3] = {
{
utility = "animalia:swim_to_land",
step_delay = 0.25,
get_score = function(self)
@ -119,20 +120,8 @@ creatura.register_mob("animalia:pig", {
return 0
end
},
[4] = {
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.4, {self, player}
end
return 0
end
},
[5] = {
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
get_score = function(self)
@ -142,7 +131,8 @@ creatura.register_mob("animalia:pig", {
end
return 0
end
}
},
animalia.global_utils.basic_flee
},
activate_func = function(self)
animalia.initialize_api(self)
@ -167,10 +157,7 @@ creatura.register_mob("animalia:pig", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:pig", "e0b1a7" ,"cc9485")

120
mobs/rat.lua Normal file
View file

@ -0,0 +1,120 @@
----------
-- Mice --
----------
creatura.register_mob("animalia:rat", {
-- Stats
max_health = 5,
armor_groups = {fleshy = 100},
damage = 0,
speed = 3,
tracking_range = 12,
despawn_after = 2500,
-- Entity Physics
stepheight = 1.1,
max_fall = 0,
turn_rate = 12,
bouyancy_multiplier = 0.5,
-- Visuals
mesh = "animalia_rat.b3d",
hitbox = {
width = 0.15,
height = 0.3
},
visual_size = {x = 10, y = 10},
textures = {
"animalia_rat_1.png",
"animalia_rat_2.png",
"animalia_rat_3.png"
},
animations = {
stand = {range = {x = 1, y = 39}, speed = 20, frame_blend = 0.3, loop = true},
walk = {range = {x = 51, y = 69}, speed = 20, frame_blend = 0.3, loop = true},
run = {range = {x = 81, y = 99}, speed = 45, frame_blend = 0.3, loop = true},
eat = {range = {x = 111, y = 119}, speed = 20, frame_blend = 0.1, loop = false}
},
-- Misc
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = false,
makes_footstep_sound = false,
drops = {
{name = "animalia:rat_raw", min = 1, max = 1, chance = 1}
},
-- Function
utility_stack = {
{
utility = "animalia:wander",
step_delay = 0.25,
get_score = function(self)
return 0.1, {self}
end
},
{
utility = "animalia:swim_to_land",
step_delay = 0.25,
get_score = function(self)
if self.in_liquid then
return 0.3, {self}
end
return 0
end
},
{
utility = "animalia:eat_crop",
get_score = function(self)
if math.random(6) < 2
or self:get_utility() == "animalia:eat_crop" then
return 0.2, {self}
end
return 0
end
},
{
utility = "animalia:steal_from_chest",
get_score = function(self)
if math.random(12) < 2
or self:get_utility() == "animalia:steal_from_chest" then
return 0.2, {self}
end
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local target = creatura.get_nearby_object(self, {"animalia:fox", "animalia:cat"})
if not target then
target = creatura.get_nearby_player(self)
end
if target
and target:get_pos() then
return 0.6, {self, target}
end
return 0
end
}
},
activate_func = function(self)
animalia.initialize_api(self)
animalia.initialize_lasso(self)
end,
step_func = function(self)
animalia.step_timers(self)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
end,
death_func = function(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end,
on_rightclick = function(self, clicker)
if animalia.set_nametag(self, clicker) then
return
end
end,
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:rat", "605a55", "ff936f")

View file

@ -44,6 +44,7 @@ creatura.register_mob("animalia:reindeer", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
drops = {
@ -98,19 +99,7 @@ creatura.register_mob("animalia:reindeer", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.4, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
@ -122,18 +111,7 @@ creatura.register_mob("animalia:reindeer", {
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local puncher = self._target
if puncher
and puncher:get_pos() then
return 0.6, {self, puncher}
end
self._target = nil
return 0
end
}
animalia.global_utils.basic_flee
},
activate_func = function(self)
animalia.initialize_api(self)
@ -158,10 +136,7 @@ creatura.register_mob("animalia:reindeer", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:reindeer", "cac3a1" ,"464438")
creatura.register_spawn_egg("animalia:reindeer", "413022" ,"d5c0a3")

View file

@ -72,6 +72,7 @@ creatura.register_mob("animalia:sheep", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -135,21 +136,7 @@ creatura.register_mob("animalia:sheep", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
if self.lasso_origin
and type(self.lasso_origin) == "userdata" then
return 0.4, {self, self.lasso_origin, true}
end
local player = creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.4, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
step_delay = 0.25,
@ -161,18 +148,7 @@ creatura.register_mob("animalia:sheep", {
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local puncher = self._target
if puncher
and puncher:get_pos() then
return 0.6, {self, puncher}
end
self._target = nil
return 0
end
}
animalia.global_utils.basic_flee
},
activate_func = function(self)
self.collected = self:recall("collected") or false
@ -267,10 +243,7 @@ creatura.register_mob("animalia:sheep", {
end
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:sheep", "f4e6cf", "e1ca9b")

View file

@ -5,6 +5,7 @@
creatura.register_mob("animalia:tropical_fish", {
-- Stats
max_health = 5,
max_breath = 0,
armor_groups = {fleshy = 150},
damage = 0,
speed = 2,
@ -33,7 +34,6 @@ creatura.register_mob("animalia:tropical_fish", {
flop = {range = {x = 30, y = 40}, speed = 20, frame_blend = 0.3, loop = true},
},
-- Misc
step_delay = 0.25,
catch_with_net = true,
catch_with_lasso = false,
makes_footstep_sound = false,
@ -82,9 +82,7 @@ creatura.register_mob("animalia:tropical_fish", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:tropical_fish", "e28821", "f6e5d2")

View file

@ -42,6 +42,7 @@ creatura.register_mob("animalia:turkey", {
},
-- Misc
makes_footstep_sound = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
sounds = {
@ -113,19 +114,7 @@ creatura.register_mob("animalia:turkey", {
return 0
end
},
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local force = lasso and lasso ~= false
local player = (force and lasso) or creatura.get_nearby_player(self)
if player
and self:follow_wielded_item(player) then
return 0.3, {self, player}
end
return 0
end
},
animalia.global_utils.basic_follow,
{
utility = "animalia:breed",
get_score = function(self)
@ -136,18 +125,7 @@ creatura.register_mob("animalia:turkey", {
return 0
end
},
{
utility = "animalia:flee_from_target",
get_score = function(self)
local puncher = self._target
if puncher
and puncher:get_pos() then
return 0.6, {self, puncher}
end
self._target = nil
return 0
end
}
animalia.global_utils.basic_flee
},
activate_func = function(self)
animalia.initialize_api(self)
@ -182,10 +160,7 @@ creatura.register_mob("animalia:turkey", {
return
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
self._target = puncher
end
on_punch = animalia.punch
})
creatura.register_spawn_egg("animalia:turkey", "352b22", "2f2721")

View file

@ -45,7 +45,7 @@ end
creatura.register_mob("animalia:wolf", {
-- Stats
max_health = 15,
max_health = 25,
armor_groups = {fleshy = 100},
damage = 4,
speed = 5,
@ -60,7 +60,7 @@ creatura.register_mob("animalia:wolf", {
width = 0.35,
height = 0.7
},
visual_size = {x = 9, y = 9},
visual_size = {x = 10, y = 10},
textures = {
"animalia_wolf_1.png",
"animalia_wolf_2.png",
@ -131,7 +131,8 @@ creatura.register_mob("animalia:wolf", {
{
utility = "animalia:follow_player",
get_score = function(self)
local lasso = type(self.lasso_origin or {}) == "userdata" and self.lasso_origin
local lasso_tgt = self._lassod_to
local lasso = type(lasso_tgt) == "string" and minetest.get_player_by_name(lasso_tgt)
local owner = self.owner and self.order == "follow" and minetest.get_player_by_name(self.owner)
local force = (lasso and lasso ~= false) or owner
local player = (force and (owner or lasso)) or creatura.get_nearby_player(self)