2021-08-20 13:08:17 -07:00
|
|
|
-----------
|
|
|
|
-- Horse --
|
|
|
|
-----------
|
|
|
|
|
|
|
|
local random = math.random
|
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
local follows = {}
|
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(function()
|
2022-08-27 20:15:57 -07:00
|
|
|
for name in pairs(minetest.registered_items) do
|
|
|
|
if (name:match(":wheat")
|
2022-02-10 18:00:06 -08:00
|
|
|
or minetest.get_item_group(name, "food_wheat") > 0)
|
|
|
|
and not name:find("seed") then
|
|
|
|
table.insert(follows, name)
|
2022-08-27 20:15:57 -07:00
|
|
|
end
|
|
|
|
end
|
2022-02-10 18:00:06 -08:00
|
|
|
end)
|
|
|
|
|
2022-08-12 22:17:42 -07:00
|
|
|
local patterns = {
|
|
|
|
"animalia_horse_pattern_1.png",
|
|
|
|
"animalia_horse_pattern_2.png",
|
|
|
|
"animalia_horse_pattern_3.png"
|
|
|
|
}
|
|
|
|
|
|
|
|
local avlbl_colors = {
|
|
|
|
[1] = {
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_3.png",
|
|
|
|
"animalia_horse_6.png"
|
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
"animalia_horse_1.png",
|
|
|
|
"animalia_horse_6.png"
|
|
|
|
},
|
|
|
|
[3] = {
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_1.png"
|
|
|
|
},
|
|
|
|
[4] = {
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_1.png"
|
|
|
|
},
|
|
|
|
[5] = {
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_1.png"
|
|
|
|
},
|
|
|
|
[6] = {
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_1.png"
|
2021-08-20 13:08:17 -07:00
|
|
|
}
|
2022-08-12 22:17:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
local function set_pattern(self)
|
|
|
|
local pattern_no = self:recall("pattern_no")
|
|
|
|
if pattern_no and pattern_no < 1 then return end
|
|
|
|
if not pattern_no then
|
|
|
|
if random(3) < 2 then
|
|
|
|
pattern_no = self:memorize("pattern_no", random(#patterns))
|
|
|
|
else
|
|
|
|
self:memorize("pattern_no", 0)
|
|
|
|
return
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
2022-08-12 22:17:42 -07:00
|
|
|
end
|
|
|
|
local colors = avlbl_colors[self.texture_no]
|
|
|
|
local color_no = self:recall("color_no") or self:memorize("color_no", random(#colors))
|
|
|
|
if not colors[color_no] then return end
|
|
|
|
local pattern = "(" .. patterns[pattern_no] .. "^[mask:" .. colors[color_no] .. ")"
|
2023-03-15 14:27:40 -07:00
|
|
|
local texture = self.textures[self.texture_no]
|
2022-08-12 22:17:42 -07:00
|
|
|
self.object:set_properties({
|
|
|
|
textures = {texture .. "^" .. pattern}
|
|
|
|
})
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
creatura.register_mob("animalia:horse", {
|
2023-03-15 14:27:40 -07:00
|
|
|
-- Engine Props
|
2022-08-27 20:15:57 -07:00
|
|
|
visual_size = {x = 10, y = 10},
|
2023-03-15 14:27:40 -07:00
|
|
|
mesh = "animalia_horse.b3d",
|
2021-08-20 13:08:17 -07:00
|
|
|
textures = {
|
|
|
|
"animalia_horse_1.png",
|
|
|
|
"animalia_horse_2.png",
|
|
|
|
"animalia_horse_3.png",
|
|
|
|
"animalia_horse_4.png",
|
|
|
|
"animalia_horse_5.png",
|
|
|
|
"animalia_horse_6.png"
|
|
|
|
},
|
2022-08-27 20:15:57 -07:00
|
|
|
makes_footstep_sound = true,
|
2023-03-15 14:27:40 -07:00
|
|
|
|
|
|
|
-- Creatura Props
|
|
|
|
max_health = 40,
|
|
|
|
armor_groups = {fleshy = 100},
|
|
|
|
damage = 8,
|
|
|
|
speed = 10,
|
|
|
|
tracking_range = 16,
|
|
|
|
max_boids = 7,
|
|
|
|
despawn_after = 1000,
|
|
|
|
max_fall = 4,
|
|
|
|
stepheight = 1.2,
|
2022-08-27 20:15:57 -07:00
|
|
|
sounds = {
|
|
|
|
alter_child_pitch = true,
|
|
|
|
random = {
|
2022-02-10 18:00:06 -08:00
|
|
|
name = "animalia_horse_idle",
|
|
|
|
gain = 1.0,
|
2022-10-17 17:23:26 -07:00
|
|
|
distance = 8
|
2022-02-10 18:00:06 -08:00
|
|
|
},
|
2022-08-27 20:15:57 -07:00
|
|
|
hurt = {
|
|
|
|
name = "animalia_horse_hurt",
|
|
|
|
gain = 1.0,
|
|
|
|
distance = 8
|
|
|
|
},
|
|
|
|
death = {
|
|
|
|
name = "animalia_horse_death",
|
|
|
|
gain = 1.0,
|
|
|
|
distance = 8
|
|
|
|
}
|
|
|
|
},
|
2023-03-15 14:27:40 -07:00
|
|
|
hitbox = {
|
|
|
|
width = 0.65,
|
|
|
|
height = 1.95
|
|
|
|
},
|
|
|
|
animations = {
|
|
|
|
stand = {range = {x = 1, y = 59}, speed = 10, frame_blend = 0.3, loop = true},
|
|
|
|
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}
|
|
|
|
},
|
|
|
|
follow = follows,
|
2022-08-27 20:15:57 -07:00
|
|
|
drops = {
|
2022-02-10 18:00:06 -08:00
|
|
|
{name = "animalia:leather", min = 1, max = 4, chance = 2}
|
2022-08-27 20:15:57 -07:00
|
|
|
},
|
2023-03-15 14:27:40 -07:00
|
|
|
fancy_collide = false,
|
|
|
|
|
|
|
|
-- Animalia Props
|
2023-03-17 13:19:59 -07:00
|
|
|
group_wander = true,
|
2023-03-15 14:27:40 -07:00
|
|
|
catch_with_net = true,
|
|
|
|
catch_with_lasso = true,
|
2022-02-10 18:00:06 -08:00
|
|
|
consumable_nodes = {
|
2022-08-12 22:17:42 -07:00
|
|
|
["default:dirt_with_grass"] = "default:dirt",
|
|
|
|
["default:dry_dirt_with_dry_grass"] = "default:dry_dirt"
|
2021-08-20 13:08:17 -07:00
|
|
|
},
|
|
|
|
head_data = {
|
|
|
|
bone = "Neck.CTRL",
|
2022-10-17 17:23:26 -07:00
|
|
|
offset = {x = 0, y = 1.05, z = 0.0},
|
|
|
|
pitch_correction = 35,
|
2021-08-20 13:08:17 -07:00
|
|
|
pivot_h = 1,
|
2022-10-17 17:23:26 -07:00
|
|
|
pivot_v = 1.75
|
2021-08-20 13:08:17 -07:00
|
|
|
},
|
2022-02-10 18:00:06 -08:00
|
|
|
utility_stack = {
|
2022-08-12 22:17:42 -07:00
|
|
|
{
|
2023-03-17 13:19:59 -07:00
|
|
|
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)
|
2022-08-12 22:17:42 -07:00
|
|
|
return 0.1, {self}
|
2022-02-10 18:00:06 -08:00
|
|
|
end
|
|
|
|
},
|
2022-08-12 22:17:42 -07:00
|
|
|
{
|
|
|
|
utility = "animalia:eat_turf",
|
|
|
|
step_delay = 0.25,
|
2022-02-10 18:00:06 -08:00
|
|
|
get_score = function(self)
|
2022-08-12 22:17:42 -07:00
|
|
|
if random(64) < 2 then
|
|
|
|
return 0.2, {self}
|
|
|
|
end
|
|
|
|
return 0
|
2022-02-10 18:00:06 -08:00
|
|
|
end
|
|
|
|
},
|
2022-08-12 22:17:42 -07:00
|
|
|
{
|
2022-02-10 18:00:06 -08:00
|
|
|
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
|
|
|
|
},
|
2022-10-17 17:23:26 -07:00
|
|
|
animalia.global_utils.basic_follow,
|
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}
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
utility = "animalia:flee_from_target_defend",
|
|
|
|
get_score = function(self)
|
|
|
|
local puncher = self._puncher
|
|
|
|
if puncher
|
|
|
|
and puncher:get_pos() then
|
|
|
|
return 0.6, {self, puncher}
|
2022-02-10 18:00:06 -08:00
|
|
|
end
|
2022-08-12 22:17:42 -07:00
|
|
|
self._puncher = nil
|
2022-02-10 18:00:06 -08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
},
|
2022-08-12 22:17:42 -07:00
|
|
|
{
|
|
|
|
utility = "animalia:tame_horse",
|
2022-02-10 18:00:06 -08:00
|
|
|
get_score = function(self)
|
2022-08-12 22:17:42 -07:00
|
|
|
local rider = not self.owner and self.rider
|
|
|
|
if rider
|
|
|
|
and rider:get_pos() then
|
|
|
|
return 0.7, {self}
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
utility = "animalia:mount_horse",
|
|
|
|
get_score = function(self)
|
|
|
|
local owner = self.owner and minetest.get_player_by_name(self.owner)
|
|
|
|
local rider = owner == self.rider and self.rider
|
|
|
|
if rider
|
|
|
|
and rider:get_pos() then
|
|
|
|
return 0.8, {self, rider}
|
2022-02-10 18:00:06 -08:00
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
}
|
|
|
|
},
|
2023-03-15 14:27:40 -07:00
|
|
|
|
|
|
|
-- Functions
|
|
|
|
set_saddle = function(self, saddle)
|
|
|
|
if saddle then
|
|
|
|
self.saddled = self:memorize("saddled", true)
|
|
|
|
local texture = self.object:get_properties().textures[1]
|
|
|
|
self.object:set_properties({
|
|
|
|
textures = {texture .. "^animalia_horse_saddle.png"}
|
|
|
|
})
|
|
|
|
self.drops = {
|
|
|
|
{name = "animalia:leather", chance = 2, min = 1, max = 4},
|
|
|
|
{name = "animalia:saddle", chance = 1, min = 1, max = 1}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
local pos = self.object:get_pos()
|
|
|
|
if not pos then return end
|
|
|
|
self.saddled = self:memorize("saddled", false)
|
|
|
|
set_pattern(self)
|
|
|
|
self.drops = {
|
|
|
|
{name = "animalia:leather", chance = 2, min = 1, max = 4}
|
|
|
|
}
|
|
|
|
minetest.add_item(pos, "animalia:saddle")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
add_child = function(self, mate)
|
|
|
|
local pos = self.object:get_pos()
|
|
|
|
if not pos then return end
|
|
|
|
local obj = minetest.add_entity(pos, self.name)
|
|
|
|
local ent = obj and obj:get_luaentity()
|
|
|
|
if not ent then return end
|
|
|
|
ent.growth_scale = 0.7
|
|
|
|
local tex_no = self.texture_no
|
|
|
|
local mate_ent = mate and mate:get_luaentity()
|
|
|
|
if mate_ent
|
|
|
|
or not mate_ent.speed
|
|
|
|
or not mate_ent.jump_power
|
|
|
|
or not mate_ent.max_health then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if random(2) < 2 then
|
|
|
|
tex_no = mate_ent.texture_no
|
|
|
|
end
|
|
|
|
ent:memorize("texture_no", tex_no)
|
|
|
|
ent:memorize("speed", random(mate_ent.speed, self.speed))
|
|
|
|
ent:memorize("jump_power", random(mate_ent.jump_power, self.jump_power))
|
|
|
|
ent:memorize("max_health", random(mate_ent.max_health, self.max_health))
|
|
|
|
ent.speed = ent:recall("speed")
|
|
|
|
ent.jump_power = ent:recall("jump_power")
|
|
|
|
ent.max_health = ent:recall("max_health")
|
|
|
|
animalia.initialize_api(ent)
|
|
|
|
animalia.protect_from_despawn(ent)
|
|
|
|
end,
|
|
|
|
|
2022-08-27 20:15:57 -07:00
|
|
|
activate_func = function(self)
|
2022-02-10 18:00:06 -08:00
|
|
|
animalia.initialize_api(self)
|
|
|
|
animalia.initialize_lasso(self)
|
2021-08-20 13:08:17 -07:00
|
|
|
set_pattern(self)
|
2022-02-10 18:00:06 -08:00
|
|
|
self.owner = self:recall("owner") or nil
|
|
|
|
self.rider = nil
|
|
|
|
self.saddled = self:recall("saddled") or false
|
|
|
|
self.max_health = self:recall("max_health") or random(30, 45)
|
|
|
|
self.speed = self:recall("speed") or random(5, 10)
|
|
|
|
self.jump_power = self:recall("jump_power") or random(2, 5)
|
|
|
|
self:memorize("max_health", self.max_health)
|
|
|
|
self:memorize("speed", self.speed)
|
|
|
|
self:memorize("jump_power", self.jump_power)
|
2021-08-20 13:08:17 -07:00
|
|
|
if self.saddled then
|
2023-03-15 14:27:40 -07:00
|
|
|
self:set_saddle(true)
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
2022-08-27 20:15:57 -07:00
|
|
|
end,
|
2023-03-15 14:27:40 -07:00
|
|
|
|
2022-08-27 20:15:57 -07:00
|
|
|
step_func = function(self)
|
2022-02-10 18:00:06 -08:00
|
|
|
animalia.step_timers(self)
|
|
|
|
animalia.head_tracking(self)
|
|
|
|
animalia.do_growth(self, 60)
|
|
|
|
animalia.update_lasso_effects(self)
|
2022-08-27 20:15:57 -07:00
|
|
|
animalia.random_sound(self)
|
|
|
|
end,
|
2023-03-15 14:27:40 -07:00
|
|
|
|
2022-08-27 20:15:57 -07:00
|
|
|
death_func = function(self)
|
2023-03-15 14:27:40 -07:00
|
|
|
if self.rider then
|
|
|
|
animalia.mount(self, self.rider)
|
|
|
|
end
|
2022-02-10 18:00:06 -08:00
|
|
|
if self:get_utility() ~= "animalia:die" then
|
|
|
|
self:initiate_utility("animalia:die", self)
|
|
|
|
end
|
2022-08-27 20:15:57 -07:00
|
|
|
end,
|
2023-03-15 14:27:40 -07:00
|
|
|
|
2021-08-20 13:08:17 -07:00
|
|
|
on_rightclick = function(self, clicker)
|
2022-02-10 18:00:06 -08:00
|
|
|
if animalia.feed(self, clicker, false, true) then
|
|
|
|
return
|
|
|
|
end
|
2023-03-15 14:27:40 -07:00
|
|
|
local owner = self.owner
|
|
|
|
local name = clicker and clicker:get_player_name()
|
|
|
|
if owner and name ~= owner then return end
|
2022-03-31 19:18:56 -07:00
|
|
|
if animalia.set_nametag(self, clicker) then
|
|
|
|
return
|
|
|
|
end
|
2023-03-15 14:27:40 -07:00
|
|
|
local wielded_name = clicker:get_wielded_item():get_name()
|
|
|
|
if wielded_name == "" then
|
|
|
|
animalia.mount(self, clicker, {rot = {x = -75, y = 180, z = 0}, pos = {x = 0, y = 0.6, z = 0.5}})
|
|
|
|
if self.saddled then
|
2022-02-10 18:00:06 -08:00
|
|
|
self:initiate_utility("animalia:mount", self, clicker)
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
2023-03-15 14:27:40 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if wielded_name == "animalia:saddle" then
|
|
|
|
self:set_saddle(true)
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
|
|
|
end,
|
2023-03-15 14:27:40 -07:00
|
|
|
|
2022-08-12 22:17:42 -07:00
|
|
|
on_punch = function(self, puncher, ...)
|
|
|
|
if self.rider and puncher == self.rider then return end
|
2023-03-15 14:27:40 -07:00
|
|
|
local name = puncher:is_player() and puncher:get_player_name()
|
|
|
|
if name
|
|
|
|
and name == self.owner
|
|
|
|
and puncher:get_player_control().sneak then
|
|
|
|
self:set_saddle(false)
|
|
|
|
return
|
|
|
|
end
|
2022-10-17 17:23:26 -07:00
|
|
|
animalia.punch(self, puncher, ...)
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
creatura.register_spawn_item("animalia:horse", {
|
|
|
|
col1 = "ebdfd8",
|
|
|
|
col2 = "653818"
|
|
|
|
})
|