animalia/mobs/pig.lua

176 lines
4 KiB
Lua
Raw Normal View History

2020-11-11 23:16:50 -08:00
---------
-- Pig --
---------
2022-02-10 18:00:06 -08:00
local follows = {}
2020-11-11 23:16:50 -08:00
2022-02-10 18:00:06 -08:00
minetest.register_on_mods_loaded(function()
for name in pairs(minetest.registered_items) do
if name:match(":carrot")
2022-02-10 18:00:06 -08:00
and (minetest.get_item_group(name, "food") > 0
or minetest.get_item_group(name, "food_carrot") > 0) then
table.insert(follows, name)
end
end
2022-02-10 18:00:06 -08:00
end)
2020-11-11 23:16:50 -08:00
2022-02-10 18:00:06 -08:00
local destroyable_crops = {}
minetest.register_on_mods_loaded(function()
for name in pairs(minetest.registered_nodes) do
if name:match("^crops:")
or name:match("^farming:") then
table.insert(destroyable_crops, {name = name, replacement = "air"})
2020-11-11 23:16:50 -08:00
end
end
2022-02-10 18:00:06 -08:00
end)
2020-11-11 23:16:50 -08:00
2022-02-10 18:00:06 -08:00
creatura.register_mob("animalia:pig", {
-- Stats
max_health = 10,
armor_groups = {fleshy = 100},
damage = 0,
speed = 3,
2022-02-10 18:00:06 -08:00
tracking_range = 16,
despawn_after = 1500,
2022-02-10 18:00:06 -08:00
-- Entity Physics
stepheight = 1.1,
turn_rate = 6,
-- Visuals
mesh = "animalia_pig.b3d",
2022-02-10 18:00:06 -08:00
hitbox = {
width = 0.35,
height = 0.7
},
visual_size = {x = 10, y = 10},
female_textures = {
"animalia_pig_1.png",
"animalia_pig_2.png",
"animalia_pig_3.png"
},
male_textures = {
"animalia_pig_1.png^animalia_pig_tusks.png",
"animalia_pig_2.png^animalia_pig_tusks.png",
"animalia_pig_3.png^animalia_pig_tusks.png"
},
child_textures = {
"animalia_pig_1.png",
"animalia_pig_2.png",
"animalia_pig_3.png"
2020-11-11 23:16:50 -08:00
},
animations = {
stand = {range = {x = 30, y = 50}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 1, y = 20}, speed = 30, frame_blend = 0.3, loop = true},
run = {range = {x = 1, y = 20}, speed = 45, frame_blend = 0.3, loop = true},
2020-11-11 23:16:50 -08:00
},
-- Misc
makes_footstep_sound = true,
2022-02-10 18:00:06 -08:00
consumable_nodes = destroyable_crops,
birth_count = 2,
catch_with_net = true,
catch_with_lasso = true,
2022-02-10 18:00:06 -08:00
sounds = {
random = {
name = "animalia_pig_idle",
gain = 1.0,
distance = 8
},
hurt = {
name = "animalia_pig_hurt",
2020-11-11 23:16:50 -08:00
gain = 1.0,
distance = 8
},
death = {
name = "animalia_pig_death",
2022-02-10 18:00:06 -08:00
gain = 1.0,
distance = 8
}
},
drops = {
{name = "animalia:porkchop_raw", min = 1, max = 3, chance = 1}
},
follow = follows,
-- Function
2022-02-10 18:00:06 -08:00
utility_stack = {
[1] = {
utility = "animalia:wander",
2022-08-12 22:17:42 -07:00
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
return 0.1, {self, true}
end
},
[2] = {
utility = "animalia:eat_from_turf",
2022-08-12 22:17:42 -07:00
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
if math.random(25) < 2 then
2022-08-12 22:17:42 -07:00
return 0.2, {self}
2022-02-10 18:00:06 -08:00
end
return 0
end
},
[3] = {
utility = "animalia:swim_to_land",
2022-08-12 22:17:42 -07:00
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
if self.in_liquid then
2022-08-12 22:17:42 -07:00
return 0.3, {self}
2022-02-10 18:00:06 -08:00
end
return 0
end
},
[4] = {
utility = "animalia:follow_player",
get_score = function(self)
2022-08-12 22:17:42 -07:00
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)
2022-02-10 18:00:06 -08:00
if player
and self:follow_wielded_item(player) then
2022-08-12 22:17:42 -07:00
return 0.4, {self, player}
2022-02-10 18:00:06 -08:00
end
return 0
end
},
[5] = {
2022-08-12 22:17:42 -07:00
utility = "animalia:breed",
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
2022-02-22 20:27:38 -08:00
if self.breeding
and animalia.get_nearby_mate(self, self.name) then
2022-08-12 22:17:42 -07:00
return 0.5, {self}
2022-02-10 18:00:06 -08:00
end
return 0
end
}
2020-11-11 23:16:50 -08:00
},
activate_func = function(self)
2022-02-10 18:00:06 -08:00
animalia.initialize_api(self)
animalia.initialize_lasso(self)
end,
step_func = function(self)
2022-02-10 18:00:06 -08:00
animalia.step_timers(self)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.random_sound(self)
end,
death_func = function(self)
2022-02-10 18:00:06 -08:00
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end,
2020-11-11 23:16:50 -08:00
on_rightclick = function(self, clicker)
2022-02-10 18:00:06 -08:00
if animalia.feed(self, clicker, false, true) then
return
end
if animalia.set_nametag(self, clicker) then
return
end
2020-11-11 23:16:50 -08:00
end,
2022-02-10 18:00:06 -08:00
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)
2022-08-12 22:17:42 -07:00
self._target = puncher
2020-11-11 23:16:50 -08:00
end
})
2022-02-10 18:00:06 -08:00
creatura.register_spawn_egg("animalia:pig", "e0b1a7" ,"cc9485")