Update 0.6.3

This commit is contained in:
ElCeejo 2023-12-28 21:28:05 -08:00
parent 8954aa3493
commit 20c55da709
42 changed files with 1423 additions and 693 deletions

View file

@ -83,13 +83,13 @@ local function activate_nametag(self)
})
end
local animate_player = {}
animalia.animate_player = {}
if minetest.get_modpath("default")
and minetest.get_modpath("player_api") then
animate_player = player_api.set_animation
animalia.animate_player = player_api.set_animation
elseif minetest.get_modpath("mcl_player") then
animate_player = mcl_player.player_set_animation
animalia.animate_player = mcl_player.player_set_animation
end
-----------------------
@ -100,7 +100,7 @@ function animalia.rotate_to_pitch(self)
local rot = self.object:get_rotation()
if self._anim == "fly" then
local vel = vec_normal(self.object:get_velocity())
local step = math.min(self.dtime * 5, abs(diff(rot.x, vel.y)) % (pi2))
local step = min(self.dtime * 5, abs(diff(rot.x, vel.y)) % (pi2))
local n_rot = interp_angle(rot.x, vel.y, step)
self.object:set_rotation({
x = clamp(n_rot, -0.75, 0.75),
@ -249,8 +249,8 @@ end
function animalia.particle_spawner(pos, texture, type, min_pos, max_pos)
type = type or "float"
min_pos = min_pos or vec_sub(pos, 2)
max_pos = max_pos or vec_add(pos, 2)
min_pos = min_pos or vec_sub(pos, 1)
max_pos = max_pos or vec_add(pos, 1)
if type == "float" then
minetest.add_particlespawner({
amount = 16,
@ -384,6 +384,7 @@ function animalia.set_nametag(self, clicker)
end
function animalia.initialize_api(self)
-- Set Gender
self.gender = self:recall("gender") or nil
if not self.gender then
local genders = {"male", "female"}
@ -391,10 +392,14 @@ function animalia.initialize_api(self)
-- Reset Texture ID
self.texture_no = nil
end
-- Taming/Breeding
self.food = self:recall("food") or 0
self.gotten = self:recall("gotten") or false
self.breeding = false
self.breeding_cooldown = self:recall("breeding_cooldown") or 0
-- Textures/Scale
activate_nametag(self)
if self.growth_scale then
self:memorize("growth_scale", self.growth_scale) -- This is for spawning children
@ -580,12 +585,11 @@ function animalia.mount(self, player, params)
})
player:set_eye_offset()
if minetest.get_modpath("player_api") then
animate_player(player, "stand", 30)
animalia.animate_player(player, "stand", 30)
if player_api.player_attached then
player_api.player_attached[plyr_name] = false
end
end
self.rider = nil
return
end
if minetest.get_modpath("player_api") then
@ -593,10 +597,10 @@ function animalia.mount(self, player, params)
end
self.rider = player
player:set_attach(self.object, "Torso", params.pos, params.rot)
player:set_eye_offset({x = 0, y = 25, z = 0}, {x = 0, y = 15, z = 15})
player:set_eye_offset({x = 0, y = 20, z = 5}, {x = 0, y = 15, z = 15})
self:clear_utility()
minetest.after(0.4, function()
animate_player(player, "sit" , 30)
animalia.animate_player(player, "sit" , 30)
end)
end
@ -630,6 +634,18 @@ function animalia.eat_crop(self, pos)
return true
end
function animalia.eat_turf(mob, pos)
for name, sub_name in pairs(mob.consumable_nodes) do
if minetest.get_node(pos).name == name then
--add_break_particle(turf_pos)
minetest.set_node(pos, {name = sub_name})
mob.collected = mob:memorize("collected", false)
--creatura.action_idle(mob, 1, "eat")
return true
end
end
end
--------------
-- Spawning --
--------------

File diff suppressed because it is too large Load diff

View file

@ -447,6 +447,8 @@ minetest.register_craftitem("animalia:libri_animalia", {
description = "Libri Animalia",
inventory_image = "animalia_libri_animalia.png",
stack_max = 1,
groups = {book = 1},
on_place = function(itemstack, player)
local meta = itemstack:get_meta()
if meta:get_string("pages") ~= "" then meta:set_string("pages", "") end

View file

@ -2,7 +2,9 @@
-- Spawning --
--------------
local function is_value_in_table(tbl, val)
local random = math.random
local function table_contains(tbl, val)
for _, v in pairs(tbl) do
if v == val then
return true
@ -11,13 +13,13 @@ local function is_value_in_table(tbl, val)
return false
end
local common_spawn_chance = tonumber(minetest.settings:get("animalia_common_chance")) or 30000
local common_spawn_chance = tonumber(minetest.settings:get("animalia_common_chance")) or 45000
local ambient_spawn_chance = tonumber(minetest.settings:get("animalia_ambient_chance")) or 6000
local ambient_spawn_chance = tonumber(minetest.settings:get("animalia_ambient_chance")) or 9000
local pest_spawn_chance = tonumber(minetest.settings:get("animalia_pest_chance")) or 2000
local pest_spawn_chance = tonumber(minetest.settings:get("animalia_pest_chance")) or 3000
local predator_spawn_chance = tonumber(minetest.settings:get("animalia_predator_chance")) or 30000
local predator_spawn_chance = tonumber(minetest.settings:get("animalia_predator_chance")) or 45000
-- Get Biomes --
@ -44,6 +46,9 @@ end)
creatura.register_abm_spawn("animalia:chicken", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 3,
@ -62,9 +67,11 @@ creatura.register_abm_spawn("animalia:cat", {
neighbors = {"group:wood"}
})
creatura.register_abm_spawn("animalia:cow", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 3,
@ -86,6 +93,9 @@ creatura.register_abm_spawn("animalia:fox", {
creatura.register_abm_spawn("animalia:horse", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 3,
@ -119,6 +129,9 @@ creatura.register_abm_spawn("animalia:owl", {
creatura.register_abm_spawn("animalia:pig", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 2,
@ -129,6 +142,9 @@ creatura.register_abm_spawn("animalia:pig", {
creatura.register_abm_spawn("animalia:reindeer", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 6,
@ -139,6 +155,9 @@ creatura.register_abm_spawn("animalia:reindeer", {
creatura.register_abm_spawn("animalia:sheep", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 3,
@ -150,6 +169,9 @@ creatura.register_abm_spawn("animalia:sheep", {
creatura.register_abm_spawn("animalia:turkey", {
chance = common_spawn_chance,
chance_on_load = 64,
spawn_active = true,
spawn_on_load = true,
min_height = 0,
max_height = 1024,
min_group = 3,
@ -234,12 +256,12 @@ 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
if table_contains(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
elseif table_contains(animalia.registered_biome_groups["temperate"].biomes, biome_name)
or table_contains(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
elseif table_contains(animalia.registered_biome_groups["grassland"].biomes, biome_name) then
self:set_mesh(2)
else
self.object:remove()
@ -259,3 +281,94 @@ creatura.register_abm_spawn("animalia:tropical_fish", {
nodes = {"group:water"},
neighbors = {"group:coral"}
})
-- World Gen Spawning
minetest.register_node("animalia:spawner", {
description = "???",
drawtype = "airlike",
walkable = false,
pointable = false,
sunlight_propagates = true,
groups = {oddly_breakable_by_hand = 1, not_in_creative_inventory = 1}
})
minetest.register_decoration({
name = "animalia:world_gen_spawning",
deco_type = "simple",
place_on = {"group:stone", "group:sand", "group:soil"},
sidelen = 1,
fill_ratio = 0.0001, -- One node per chunk
decoration = "animalia:spawner"
})
local function do_on_spawn(pos, obj)
local name = obj and obj:get_luaentity().name
if not name then return end
local spawn_functions = creatura.registered_on_spawns[name] or {}
if #spawn_functions > 0 then
for _, func in ipairs(spawn_functions) do
func(obj:get_luaentity(), pos)
if not obj:get_yaw() then break end
end
end
end
minetest.register_abm({
label = "[animalia] World Gen Spawning",
nodenames = {"animalia:spawner"},
interval = 10, -- TODO: Set this to 1 if world is singleplayer and just started
chance = 16,
action = function(pos, _, active_object_count)
minetest.remove_node(pos)
if active_object_count > 8 then return end
local spawnable_mobs = {}
local current_biome = minetest.get_biome_name(minetest.get_biome_data(pos).biome)
local spawn_definitions = creatura.registered_mob_spawns
for mob, def in pairs(spawn_definitions) do
if mob:match("^animalia:")
and def.biomes
and table_contains(def.biomes, current_biome) then
table.insert(spawnable_mobs, mob)
end
end
if #spawnable_mobs > 0 then
local mob_to_spawn = spawnable_mobs[math.random(#spawnable_mobs)]
local spawn_definition = creatura.registered_mob_spawns[mob_to_spawn]
local group_size = random(spawn_definition.min_group or 1, spawn_definition.max_group or 1)
local obj
if group_size > 1 then
local offset
local spawn_pos
for _ = 1, group_size do
offset = group_size * 0.5
spawn_pos = creatura.get_ground_level({
x = pos.x + random(-offset, offset),
y = pos.y,
z = pos.z + random(-offset, offset)
}, 3)
if not creatura.is_pos_moveable(spawn_pos, 0.5, 0.5) then
spawn_pos = pos
end
obj = minetest.add_entity(spawn_pos, mob_to_spawn)
do_on_spawn(spawn_pos, obj)
end
else
obj = minetest.add_entity(pos, mob_to_spawn)
do_on_spawn(pos, obj)
end
end
end
})

View file

@ -3,11 +3,20 @@ local mod_storage = minetest.get_mod_storage()
local data = {
spawn_points = minetest.deserialize(mod_storage:get_string("spawn_points")) or {},
libri_font_size = minetest.deserialize(mod_storage:get_string("libri_font_size")) or {},
bound_horse = minetest.deserialize(mod_storage:get_string("bound_horse")) or {}
}
local function save()
mod_storage:set_string("spawn_points", minetest.serialize(data.spawn_points))
mod_storage:set_string("libri_font_size", minetest.serialize(data.libri_font_size))
for name, bound_data in pairs(data.bound_horse) do
if bound_data
and bound_data.obj then
data.bound_horse[name].obj = nil
end
end
mod_storage:set_string("bound_horse", minetest.serialize(data.bound_horse))
end
minetest.register_on_shutdown(save)