2021-08-20 13:08:17 -07:00
|
|
|
animalia = {}
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-08-27 20:15:57 -07:00
|
|
|
local path = minetest.get_modpath("animalia")
|
|
|
|
|
|
|
|
local storage = dofile(path .. "/api/storage.lua")
|
|
|
|
|
|
|
|
animalia.spawn_points = storage.spawn_points
|
|
|
|
animalia.libri_font_size = storage.libri_font_size
|
|
|
|
|
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)
|
2022-08-12 22:17:42 -07:00
|
|
|
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)
|
2022-08-12 22:17:42 -07:00
|
|
|
local name = player:get_player_name()
|
|
|
|
animalia.pets[name] = nil
|
2022-02-10 18:00:06 -08:00
|
|
|
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()
|
2022-08-12 22:17:42 -07:00
|
|
|
local time = (minetest.get_timeofday() or 0) * 24000
|
|
|
|
animalia.is_day = time < 19500 and time > 4500
|
|
|
|
minetest.after(10, is_day)
|
2022-03-31 19:18:56 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
is_day()
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
-- Player Effects
|
|
|
|
|
|
|
|
animalia.player_effects = {}
|
|
|
|
|
|
|
|
local function player_effect_step()
|
|
|
|
for player, data in pairs(animalia.player_effects) do
|
|
|
|
if player then
|
|
|
|
local timer = data.timer - 1
|
|
|
|
animalia.player_effects[player].timer = timer
|
|
|
|
local func = data.func
|
|
|
|
func(minetest.get_player_by_name(player))
|
|
|
|
if timer <= 0 then
|
|
|
|
animalia.player_effects[player] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.after(1, player_effect_step)
|
|
|
|
end
|
|
|
|
|
|
|
|
player_effect_step()
|
|
|
|
|
|
|
|
function animalia.set_player_effect(player_name, effect, timer)
|
|
|
|
animalia.player_effects[player_name] = {
|
|
|
|
func = effect,
|
|
|
|
timer = timer or 5
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create lists of items for reuse
|
|
|
|
|
|
|
|
animalia.food_wheat = {}
|
|
|
|
animalia.food_seeds = {}
|
|
|
|
animalia.food_crops = {}
|
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
if minetest.get_modpath("farming")
|
|
|
|
and farming.registered_plants then
|
|
|
|
for _, def in pairs(farming.registered_plants) do
|
|
|
|
if def.crop then
|
|
|
|
table.insert(animalia.food_crops, def.crop)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for name in pairs(minetest.registered_items) do
|
|
|
|
if (name:match(":wheat")
|
|
|
|
or minetest.get_item_group(name, "food_wheat") > 0)
|
|
|
|
and not name:find("seed") then
|
|
|
|
table.insert(animalia.food_wheat, name)
|
|
|
|
end
|
|
|
|
if name:match(":seed_")
|
|
|
|
or name:match("_seed") then
|
|
|
|
table.insert(animalia.food_seeds, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Load Files
|
|
|
|
|
2024-01-04 11:15:02 -08:00
|
|
|
local function load_file(filepath, filename)
|
|
|
|
if io.open(filepath .. "/" .. filename, "r") then
|
|
|
|
dofile(filepath .. "/" .. filename)
|
|
|
|
else
|
|
|
|
minetest.log("action", "[Creatura] The file " .. filename .. " could not be loaded.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-11 23:16:50 -08:00
|
|
|
dofile(path.."/api/api.lua")
|
2024-01-04 11:15:02 -08:00
|
|
|
dofile(path.."/api/mob_ai.lua")
|
2022-02-10 18:00:06 -08:00
|
|
|
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 = {
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:bat",
|
2023-03-15 14:27:40 -07:00
|
|
|
"animalia:song_bird",
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:cat",
|
|
|
|
"animalia:chicken",
|
|
|
|
"animalia:cow",
|
2022-10-17 17:23:26 -07:00
|
|
|
"animalia:fox",
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:frog",
|
|
|
|
"animalia:horse",
|
2023-12-28 21:28:05 -08:00
|
|
|
"animalia:opossum",
|
2022-10-17 17:23:26 -07:00
|
|
|
"animalia:owl",
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:pig",
|
2022-10-17 17:23:26 -07:00
|
|
|
"animalia:rat",
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:reindeer",
|
|
|
|
"animalia:sheep",
|
|
|
|
"animalia:turkey",
|
2022-10-17 17:23:26 -07:00
|
|
|
"animalia:tropical_fish",
|
2022-08-12 22:17:42 -07:00
|
|
|
"animalia:wolf",
|
2022-02-10 18:00:06 -08:00
|
|
|
}
|
|
|
|
|
2024-01-04 11:15:02 -08:00
|
|
|
dofile(path.."/api/api.lua")
|
|
|
|
|
|
|
|
load_file(path .. "/mobs", "bat.lua")
|
|
|
|
load_file(path .. "/mobs", "cat.lua")
|
|
|
|
load_file(path .. "/mobs", "chicken.lua")
|
|
|
|
load_file(path .. "/mobs", "cow.lua")
|
|
|
|
load_file(path .. "/mobs", "fox.lua")
|
|
|
|
load_file(path .. "/mobs", "frog.lua")
|
|
|
|
load_file(path .. "/mobs", "horse.lua")
|
|
|
|
load_file(path .. "/mobs", "opossum.lua")
|
|
|
|
load_file(path .. "/mobs", "owl.lua")
|
|
|
|
load_file(path .. "/mobs", "pig.lua")
|
|
|
|
load_file(path .. "/mobs", "rat.lua")
|
|
|
|
load_file(path .. "/mobs", "reindeer.lua")
|
|
|
|
load_file(path .. "/mobs", "sheep.lua")
|
|
|
|
load_file(path .. "/mobs", "song_bird.lua")
|
|
|
|
load_file(path .. "/mobs", "turkey.lua")
|
|
|
|
load_file(path .. "/mobs", "tropical_fish.lua")
|
|
|
|
load_file(path .. "/mobs", "wolf.lua")
|
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
|
2022-08-12 22:17:42 -07:00
|
|
|
dofile(path.."/api/spawning.lua")
|
2021-08-20 13:08:17 -07:00
|
|
|
end
|
2020-11-11 23:16:50 -08:00
|
|
|
|
2022-08-27 20:15:57 -07:00
|
|
|
dofile(path.."/api/libri.lua")
|
|
|
|
|
2022-02-10 18:00:06 -08:00
|
|
|
minetest.register_on_mods_loaded(function()
|
2022-08-12 22:17:42 -07:00
|
|
|
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
|
|
|
|
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)
|
|
|
|
local pos = self.object:get_pos()
|
2022-12-03 23:23:06 -08:00
|
|
|
if not pos then return end
|
2023-03-15 14:27:40 -07:00
|
|
|
local plyr_name = puncher:is_player() and puncher:get_player_name()
|
|
|
|
local pets = (plyr_name and animalia.pets[plyr_name]) or {}
|
2022-12-03 23:23:06 -08:00
|
|
|
for _, obj in ipairs(pets) do
|
|
|
|
local ent = obj and obj:get_luaentity()
|
2022-12-11 17:21:49 -08:00
|
|
|
if ent
|
|
|
|
and ent.assist_owner then
|
2022-12-03 23:23:06 -08:00
|
|
|
ent.owner_target = self
|
2022-08-12 22:17:42 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def.on_punch = on_punch
|
|
|
|
minetest.register_entity(":" .. name, def)
|
|
|
|
end
|
2022-02-10 18:00:06 -08:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-08-27 21:30:18 -07:00
|
|
|
local convert_mobs_redo = minetest.settings:get_bool("convert_redo_items", false)
|
|
|
|
|
|
|
|
if convert_mobs_redo then
|
|
|
|
minetest.register_alias_force("mobs:leather", "animalia:leather")
|
|
|
|
minetest.register_alias_force("mobs:meat_raw", "animalia:beef_raw")
|
|
|
|
minetest.register_alias_force("mobs:meat", "animalia:beef_cooked")
|
|
|
|
minetest.register_alias_force("mobs:lasso", "animalia:lasso")
|
|
|
|
minetest.register_alias_force("mobs:net", "animalia:net")
|
|
|
|
minetest.register_alias_force("mobs:shears", "animalia:shears")
|
|
|
|
minetest.register_alias_force("mobs:saddles", "animalia:saddles")
|
|
|
|
minetest.register_alias_force("mobs:nametag", "animalia:nametag")
|
|
|
|
end
|
|
|
|
|
2023-04-03 19:25:01 -07:00
|
|
|
minetest.log("action", "[MOD] Animalia [0.6] loaded")
|