forked from ElCeejo/animalia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
202 lines (172 loc) · 5.35 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
animalia = {}
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
animalia.pets = {}
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
animalia.pets[name] = {}
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
animalia.pets[name] = nil
end)
-- 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()
-- 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 = {}
animalia.food_bear = {}
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
if (minetest.get_item_group(name, "food_berry") > 0
and not name:find("seed"))
or minetest.get_item_group(name, "food_fish") > 0 then
table.insert(animalia.food_bear, name)
end
end
end)
-- Load Files
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
dofile(path.."/api/api.lua")
dofile(path.."/api/mob_ai.lua")
dofile(path.."/api/lasso.lua")
dofile(path.."/craftitems.lua")
animalia.animals = {
"animalia:bat",
"animalia:song_bird",
"animalia:cat",
"animalia:chicken",
"animalia:cow",
"animalia:fox",
"animalia:frog",
"animalia:grizzly_bear",
"animalia:horse",
"animalia:opossum",
"animalia:owl",
"animalia:pig",
"animalia:rat",
"animalia:reindeer",
"animalia:sheep",
"animalia:turkey",
"animalia:tropical_fish",
"animalia:wolf",
}
dofile(path.."/api/api.lua")
load_file(path .. "/mobs", "bat.lua")
load_file(path .. "/mobs", "bear.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")
if minetest.settings:get_bool("spawn_mobs", true) then
dofile(path.."/api/spawning.lua")
end
dofile(path.."/api/libri.lua")
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
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()
if not pos then return end
local plyr_name = puncher:is_player() and puncher:get_player_name()
local pets = (plyr_name and animalia.pets[plyr_name]) or {}
for _, obj in ipairs(pets) do
local ent = obj and obj:get_luaentity()
if ent
and ent.assist_owner then
ent.owner_target = self
end
end
end
def.on_punch = on_punch
minetest.register_entity(":" .. name, def)
end
end
end)
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
minetest.log("action", "[MOD] Animalia [0.6] loaded")