QoL Update

This commit is contained in:
ElCeejo 2023-03-15 14:27:40 -07:00
parent 1b9382bee3
commit 5cd21a7a37
62 changed files with 2078 additions and 1614 deletions

View file

@ -2,18 +2,6 @@
-- API --
---------
animalia.walkable_nodes = {}
minetest.register_on_mods_loaded(function()
for name in pairs(minetest.registered_nodes) do
if name ~= "air" and name ~= "ignore" then
if minetest.registered_nodes[name].walkable then
table.insert(animalia.walkable_nodes, name)
end
end
end
end)
-- Math --
local abs = math.abs
@ -65,12 +53,6 @@ local vec_len = vector.length
local dir2yaw = minetest.dir_to_yaw
local yaw2dir = minetest.yaw_to_dir
--------------
-- Settings --
--------------
local creative = minetest.settings:get_bool("creative_mode")
------------
-- Common --
------------
@ -88,8 +70,6 @@ function animalia.correct_name(str)
end
end
local correct_name = animalia.correct_name
---------------------
-- Local Utilities --
---------------------
@ -109,7 +89,7 @@ if minetest.get_modpath("default")
and minetest.get_modpath("player_api") then
animate_player = player_api.set_animation
elseif minetest.get_modpath("mcl_player") then
animate_player = mcl_player.set_animation
animate_player = mcl_player.player_set_animation
end
-----------------------
@ -269,16 +249,8 @@ end
function animalia.particle_spawner(pos, texture, type, min_pos, max_pos)
type = type or "float"
min_pos = min_pos or {
x = pos.x - 2,
y = pos.y - 2,
z = pos.z - 2,
}
max_pos = max_pos or {
x = pos.x + 2,
y = pos.y + 2,
z = pos.z + 2,
}
min_pos = min_pos or vec_sub(pos, 2)
max_pos = max_pos or vec_add(pos, 2)
if type == "float" then
minetest.add_particlespawner({
amount = 16,
@ -312,14 +284,52 @@ function animalia.particle_spawner(pos, texture, type, min_pos, max_pos)
end
end
function animalia.add_food_particle(self, item_name)
local pos, yaw = self.object:get_pos(), self.object:get_yaw()
if not pos then return end
local head = self.head_data
local offset_h = (head and head.pivot_h) or self.width
local offset_v = (head and head.pivot_v) or self.height
local head_pos = {
x = pos.x + sin(yaw) * -offset_h,
y = pos.y + offset_v,
z = pos.z + cos(yaw) * offset_h
}
local def = minetest.registered_items[item_name]
local image = def.inventory_image
if def.tiles then
image = def.tiles[1].name or def.tiles[1]
end
if image then
local crop = "^[sheet:4x4:" .. random(4) .. "," .. random(4)
minetest.add_particlespawner({
pos = head_pos,
time = 0.5,
amount = 12,
collisiondetection = true,
collision_removal = true,
vel = {min = {x = -1, y = 1, z = -1}, max = {x = 1, y = 2, z = 1}},
acc = {x = 0, y = -9.8, z = 0},
size = {min = 1, max = 2},
texture = image .. crop
})
end
end
----------
-- Mobs --
----------
function animalia.get_dropped_food(self, item)
function animalia.death_func(self)
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end
function animalia.get_dropped_food(self, item, radius)
local pos = self.object:get_pos()
if not pos then return end
local objects = minetest.get_objects_inside_radius(pos, self.tracking_range)
local objects = minetest.get_objects_inside_radius(pos, radius or self.tracking_range)
for _, object in ipairs(objects) do
local ent = object:get_luaentity()
if ent
@ -337,6 +347,19 @@ function animalia.protect_from_despawn(self)
self.despawn_after = self:memorize("despawn_after", false)
end
function animalia.despawn_inactive_mob(self)
local os_time = os.time()
self._last_active = self:recall("_last_active")
if self._last_active
and self.despawn_after then
local last_active = self._last_active
if os_time - last_active > self.despawn_after then
self.object:remove()
return true
end
end
end
function animalia.set_nametag(self, clicker)
local plyr_name = clicker and clicker:get_player_name()
if not plyr_name then return end
@ -391,7 +414,12 @@ function animalia.initialize_api(self)
self.texture_no = random(#textures)
end
self:set_texture(self.texture_no, textures)
return
end
if self.growth_scale < 0.8
and self.child_mesh then
self.object:set_properties({
mesh = self.child_mesh
})
end
end
@ -406,6 +434,7 @@ function animalia.step_timers(self)
end
self:memorize("breeding_cooldown", self.breeding_cooldown)
self:memorize("trust_cooldown", self.trust_cooldown)
self:memorize("_last_active", os.time())
end
function animalia.do_growth(self, interval)
@ -422,6 +451,7 @@ function animalia.do_growth(self, interval)
end
self:set_texture(tex_no, self.child_textures)
elseif self.growth_scale == 0.8 then
if self.child_mesh then self:set_mesh() end
if self.male_textures
and self.female_textures then
if #self.child_textures == 1 then
@ -434,6 +464,9 @@ function animalia.do_growth(self, interval)
end
self:set_texture(self.texture_no, self.textures)
end
if self.on_grown then
self:on_grown()
end
end
self:memorize("growth_scale", self.growth_scale)
end
@ -448,6 +481,7 @@ function animalia.random_sound(self)
end
function animalia.add_trust(self, player, amount)
if self.trust_cooldown > 0 then return end
self.trust_cooldown = 60
local plyr_name = player:get_player_name()
local trust = self.trust[plyr_name] or 0
@ -513,7 +547,7 @@ function animalia.feed(self, clicker, tame, breed)
if self.breeding_cooldown <= 0 then
self.breeding = true
self.breeding_cooldown = 60
animalia.particle_spawner(pos, "heart.png", "float", minp, maxp)
animalia.particle_spawner(pos, "heart.png", "float")
end
end
self._despawn = self:memorize("_despawn", false)
@ -575,6 +609,26 @@ function animalia.punch(self, puncher, ...)
end
end
function animalia.find_crop(self)
local pos = self.object:get_pos()
if not pos then return end
local nodes = minetest.find_nodes_in_area(vec_sub(pos, 6), vec_add(pos, 6), "group:crop") or {}
if #nodes < 1 then return end
return nodes[math.random(#nodes)]
end
function animalia.eat_crop(self, pos)
local node_name = minetest.get_node(pos).name
local new_name = node_name:sub(1, #node_name - 1) .. (tonumber(node_name:sub(-1)) or 2) - 1
local new_def = minetest.registered_nodes[new_name]
if not new_def then return false end
local p2 = new_def.place_param2 or 1
minetest.set_node(pos, {name = new_name, param2 = p2})
animalia.add_food_particle(self, new_name)
return true
end
--------------
-- Spawning --
--------------

File diff suppressed because it is too large Load diff

View file

@ -3,18 +3,9 @@
-----------
local abs = math.abs
local asin = math.asin
local atan2 = math.atan2
local cos = math.cos
local deg = math.deg
local sin = math.sin
local function diff(a, b) -- Get difference between 2 angles
return atan2(sin(b - a), cos(b - a))
end
local vec_add, vec_dir, vec_dist, vec_len = vector.add, vector.direction, vector.distance, vector.length
local dir2yaw, dir2rot = minetest.dir_to_yaw, vector.dir_to_rotation
local dir2rot = vector.dir_to_rotation
-- Entities --
@ -29,7 +20,7 @@ minetest.register_entity("animalia:lasso_entity", {
self.object:set_armor_groups({immortal = 1})
end,
_scale = 1,
on_step = function(self, dtime)
on_step = function(self)
local pos, parent = self.object:get_pos(), (self.object:get_attach() or self._attached)
local pointed_ent = self._point_to and self._point_to:get_luaentity()
local point_to = self._point_to and self._point_to:get_pos()
@ -126,10 +117,10 @@ local function add_lasso(self, origin)
if not ent then return end
-- Attachment point of entity
ent._attached = origin
if type(origin) == "string" then
if type(origin) ~= "string" then
--local player = minetest.get_player_by_name(origin)
--object:set_attach(player)
else
--else
object:set_pos(origin)
end
self._lassod_to = origin

View file

@ -8,8 +8,6 @@ local path = minetest.get_modpath(minetest.get_current_modname())
local color = minetest.colorize
local page_spacing = 0.5
local libri_bg = {
"formspec_version[3]",
"size[16,10]",
@ -33,7 +31,6 @@ local pages = {}
local generate_mobs = {
["animalia:bat"] = "Bat",
["animalia:bird"] = "Song Bird",
["animalia:cat"] = "Cat",
["animalia:chicken"] = "Chicken",
["animalia:cow"] = "Cow",
@ -46,6 +43,7 @@ local generate_mobs = {
["animalia:rat"] = "Rat",
["animalia:reindeer"] = "Reindeer",
["animalia:sheep"] = "Sheep",
["animalia:song_bird"] = "Song Bird",
["animalia:turkey"] = "Turkey",
["animalia:wolf"] = "Wolf",
}
@ -53,7 +51,6 @@ local generate_mobs = {
local spawn_biomes = {
["animalia:bat"] = "cave",
["animalia:bird"] = "temperate",
["animalia:cat"] = "urban",
["animalia:chicken"] = "tropical",
["animalia:cow"] = "grassland",
@ -66,6 +63,7 @@ local spawn_biomes = {
["animalia:rat"] = "urban",
["animalia:reindeer"] = "boreal",
["animalia:sheep"] = "grassland",
["animalia:song_bird"] = "temperate",
["animalia:turkey"] = "boreal",
["animalia:wolf"] = "boreal",
}
@ -310,13 +308,14 @@ function libri.render_element(def, meta, playername)
local filename = path .. "/libri/" .. def.file
local file = io.open(filename)
if file then
local i = 0
local full_text = ""
local text = ""
for line in file:lines() do
full_text = full_text .. line .. "\n"
text = text .. line .. "\n"
end
local total_offset = (offset_x + (0.35 - 0.35 * font_size_x)) .. "," .. offset_y
form = form .. "hypertext[" .. total_offset .. ";8,9;text;<global color=#000000 size=".. font_size .. " halign=center>" .. full_text .. "]"
form = form ..
"hypertext[" .. total_offset .. ";8,9;text;<global color=#000000 size="..
font_size .. " halign=center>" .. text .. "]"
file:close()
end
else

View file

@ -2,11 +2,20 @@
-- Spawning --
--------------
local function is_value_in_table(tbl, val)
for _, v in pairs(tbl) do
if v == val then
return true
end
end
return false
end
local common_spawn_chance = tonumber(minetest.settings:get("animalia_common_chance")) or 20000
local ambient_spawn_chance = tonumber(minetest.settings:get("animalia_ambient_chance")) or 6000
local pest_spawn_chance = tonumber(minetest.settings:get("animalia_pest_chance")) or 4000
local pest_spawn_chance = tonumber(minetest.settings:get("animalia_pest_chance")) or 2000
local predator_spawn_chance = tonumber(minetest.settings:get("animalia_predator_chance")) or 30000
@ -43,6 +52,17 @@ creatura.register_abm_spawn("animalia:chicken", {
nodes = {"group:soil"},
})
creatura.register_abm_spawn("animalia:cat", {
chance = common_spawn_chance,
min_height = 0,
max_height = 1024,
min_group = 1,
max_group = 2,
nodes = {"group:soil"},
neighbors = {"group:wood"}
})
creatura.register_abm_spawn("animalia:cow", {
chance = common_spawn_chance,
min_height = 0,
@ -76,7 +96,7 @@ creatura.register_abm_spawn("animalia:horse", {
})
creatura.register_abm_spawn("animalia:rat", {
chance = 2000,
chance = pest_spawn_chance,
interval = 60,
min_height = -1,
max_height = 1024,
@ -162,7 +182,7 @@ creatura.register_abm_spawn("animalia:bat", {
nodes = {"group:stone"}
})
creatura.register_abm_spawn("animalia:bird", {
creatura.register_abm_spawn("animalia:song_bird", {
chance = ambient_spawn_chance,
interval = 60,
min_light = 0,
@ -170,25 +190,21 @@ creatura.register_abm_spawn("animalia:bird", {
max_height = 1024,
min_group = 6,
max_group = 12,
spawn_cap = 12,
nodes = {"group:leaves"},
spawn_cap = 6,
nodes = {"group:leaves", "animalia:nest_song_bird"},
neighbors = {"group:leaves"}
})
creatura.register_on_spawn("animalia:bird", function(self, pos)
creatura.register_on_spawn("animalia:song_bird", function(self, pos)
local nests = minetest.find_nodes_in_area_under_air(
{x = pos.x - 12, y = pos.y - 12, z = pos.z - 12},
{x = pos.x + 12, y = pos.y + 12, z = pos.z + 12},
{x = pos.x - 16, y = pos.y - 16, z = pos.z - 16},
{x = pos.x + 16, y = pos.y + 16, z = pos.z + 16},
"animalia:nest_song_bird"
)
if nests[1] then
self.home_position = self:memorize("home_position", nests[1])
return
end
if nests[1] then return end
local node = minetest.get_node(pos)
if node.name == "air" then
minetest.set_node(pos, {name = "animalia:nest_song_bird"})
self.home_position = self:memorize("home_position", pos)
else
local nodes = minetest.find_nodes_in_area_under_air(
{x = pos.x - 3, y = pos.y - 3, z = pos.z - 3},
@ -198,23 +214,42 @@ creatura.register_on_spawn("animalia:bird", function(self, pos)
if nodes[1] then
pos = nodes[1]
minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "animalia:nest_song_bird"})
self.home_position = self:memorize("home_position", {x = pos.x, y = pos.y + 1, z = pos.z})
end
end
end)
creatura.register_abm_spawn("animalia:frog", {
chance = ambient_spawn_chance,
chance = ambient_spawn_chance * 0.75,
interval = 60,
min_light = 0,
min_height = -1,
max_height = 8,
min_group = 2,
max_group = 4,
min_group = 1,
max_group = 2,
neighbors = {"group:water"},
nodes = {"group:soil"}
})
creatura.register_on_spawn("animalia:frog", function(self, pos)
local biome_data = minetest.get_biome_data(pos)
local biome_name = minetest.get_biome_name(biome_data.biome)
if is_value_in_table(animalia.registered_biome_groups["tropical"].biomes, biome_name) then
self:set_mesh(3)
elseif is_value_in_table(animalia.registered_biome_groups["temperate"].biomes, biome_name)
or is_value_in_table(animalia.registered_biome_groups["boreal"].biomes, biome_name) then
self:set_mesh(1)
elseif is_value_in_table(animalia.registered_biome_groups["grassland"].biomes, biome_name) then
self:set_mesh(2)
else
self.object:remove()
end
local activate = self.activate_func
activate(self)
end)
creatura.register_abm_spawn("animalia:tropical_fish", {
chance = ambient_spawn_chance,
min_height = -128,