2021-08-20 13:08:17 -07:00
|
|
|
animalia = {}
|
|
|
|
better_fauna = animalia
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
animalia.pets = {}
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
animalia.pets[name] = {}
|
2020-11-11 23:16:50 -08:00
|
|
|
end)
|
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
animalia.pets[name] = nil
|
|
|
|
end)
|
2020-11-25 00:29:47 -08:00
|
|
|
|
2022-03-31 19:18:56 -07:00
|
|
|
-- Daytime Tracking
|
|
|
|
|
|
|
|
animalia.is_day = true
|
|
|
|
|
|
|
|
local function is_day()
|
|
|
|
local time = (minetest.get_timeofday() or 0) * 24000
|
|
|
|
animalia.is_day = time < 19500 and time > 4500
|
|
|
|
minetest.after(10, is_day)
|
|
|
|
end
|
|
|
|
|
|
|
|
is_day()
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-03-31 19:18:56 -07:00
|
|
|
local path = minetest.get_modpath("animalia")
|
2021-08-20 20:16:29 -07:00
|
|
|
|
2020-11-11 23:16:50 -08:00
|
|
|
dofile(path.."/api/api.lua")
|
2022-02-10 18:00:06 -08:00
|
|
|
dofile(path.."/api/behaviors.lua")
|
|
|
|
dofile(path.."/api/lasso.lua")
|
2020-11-11 23:16:50 -08:00
|
|
|
dofile(path.."/craftitems.lua")
|
2021-08-20 13:08:17 -07:00
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
animalia.animals = {
|
|
|
|
"animalia:bat",
|
|
|
|
"animalia:bird",
|
|
|
|
"animalia:cat",
|
|
|
|
"animalia:chicken",
|
|
|
|
"animalia:cow",
|
|
|
|
"animalia:tropical_fish",
|
|
|
|
"animalia:frog",
|
|
|
|
"animalia:horse",
|
|
|
|
"animalia:pig",
|
|
|
|
"animalia:reindeer",
|
|
|
|
"animalia:sheep",
|
|
|
|
"animalia:turkey",
|
|
|
|
"animalia:wolf",
|
|
|
|
}
|
|
|
|
|
|
|
|
for i = 1, #animalia.animals do
|
|
|
|
local name = string.split(animalia.animals[i], ":")[2]
|
|
|
|
dofile(path.."/mobs/" .. name .. ".lua")
|
|
|
|
end
|
2021-08-20 20:16:29 -07:00
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
if minetest.settings:get_bool("spawn_mobs", true) then
|
|
|
|
dofile(path.."/api/spawning.lua")
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
for name, def in pairs(minetest.registered_entities) do
|
|
|
|
if def.logic
|
|
|
|
or def.brainfunc
|
|
|
|
or def.bh_tree
|
|
|
|
or def._cmi_is_mob then
|
|
|
|
local old_punch = def.on_punch
|
|
|
|
if not old_punch then
|
|
|
|
old_punch = function() end
|
|
|
|
end
|
2022-02-20 11:45:25 -08:00
|
|
|
local on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
|
|
|
old_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
2022-02-10 18:00:06 -08:00
|
|
|
local pos = self.object:get_pos()
|
|
|
|
if not pos then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if puncher:is_player()
|
|
|
|
and animalia.pets[puncher:get_player_name()] then
|
|
|
|
local pets = animalia.pets[puncher:get_player_name()]
|
|
|
|
if #pets < 1 then return end
|
|
|
|
for i = 1, #pets do
|
|
|
|
local ent = pets[i]:get_luaentity()
|
|
|
|
if ent.assist_owner then
|
|
|
|
ent.owner_target = self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def.on_punch = on_punch
|
|
|
|
minetest.register_entity(":" .. name, def)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.log("action", "[MOD] Animalia [0.3] loaded")
|