diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..22f803f --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,26 @@ +unused_args = false + +read_globals = { + "minetest", + "lucky_block", + "intllib", + "vector", + "table", + "invisibility", + "cmi", + "toolranks", + "pathfinder", + "tnt", + "ItemStack" +} + +globals = { + "mobs", + "player_api", + "default" +} + +ignore = { + "431", -- Shadowing an upvalue + "432", -- Shadowing an upvalue argument +} diff --git a/api.lua b/api.lua index e5c5844..21baf84 100644 --- a/api.lua +++ b/api.lua @@ -8,11 +8,10 @@ else if minetest.get_modpath("intllib") then dofile(minetest.get_modpath("intllib").."/init.lua") if intllib.make_gettext_pair then - gettext, ngettext = intllib.make_gettext_pair() -- new gettext method + S = intllib.make_gettext_pair() -- new gettext method else - gettext = intllib.Getter() -- old text file method + S = intllib.Getter() -- old text file method end - S = gettext else -- boilerplate function S = function(str, ...) local args = {...} @@ -28,7 +27,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20220722", + version = "20230527", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -45,6 +44,7 @@ local random = math.random local floor = math.floor local ceil = math.ceil local rad = math.rad +local deg = math.deg local atann = math.atan local atan = function(x) if not x or x ~= x then @@ -64,8 +64,7 @@ local settings = minetest.settings -- creative check local creative_cache = minetest.settings:get_bool("creative_mode") function mobs.is_creative(name) - return creative_cache or minetest.check_player_privs(name, - {creative = true}) + return creative_cache or minetest.check_player_privs(name, {creative = true}) end -- Load settings @@ -73,6 +72,7 @@ local damage_enabled = settings:get_bool("enable_damage") local mobs_spawn = settings:get_bool("mobs_spawn") ~= false local peaceful_only = settings:get_bool("only_peaceful_mobs") local disable_blood = settings:get_bool("mobs_disable_blood") +local mob_hit_effect = settings:get_bool("mob_hit_effect") local mobs_drop_items = settings:get_bool("mobs_drop_items") ~= false local mobs_griefing = settings:get_bool("mobs_griefing") ~= false local spawn_protected = settings:get_bool("mobs_spawn_protected") ~= false @@ -80,15 +80,46 @@ local spawn_monster_protected = settings:get_bool("mobs_spawn_monster_protected" local remove_far = settings:get_bool("remove_far_mobs") ~= false local mob_area_spawn = settings:get_bool("mob_area_spawn") local difficulty = tonumber(settings:get("mob_difficulty")) or 1.0 -local show_health = settings:get_bool("mob_show_health") ~= false local max_per_block = tonumber(settings:get("max_objects_per_block") or 99) local mob_nospawn_range = tonumber(settings:get("mob_nospawn_range") or 12) local active_limit = tonumber(settings:get("mob_active_limit") or 0) local mob_chance_multiplier = tonumber(settings:get("mob_chance_multiplier") or 1) local peaceful_player_enabled = settings:get_bool("enable_peaceful_player") local mob_smooth_rotate = settings:get_bool("mob_smooth_rotate") ~= false +local mob_height_fix = settings:get_bool("mob_height_fix") ~= false local active_mobs = 0 +-- get loop timers for node and main functions +local node_timer_interval = tonumber(settings:get("mob_node_timer_interval") or 0.25) +local main_timer_interval = tonumber(settings:get("mob_main_timer_interval") or 1.0) + +-- pathfinding settings +local pathfinding_enable = settings:get_bool("mob_pathfinding_enable") or true +-- Use pathfinder mod if available +local pathfinder_enable = settings:get_bool("mob_pathfinder_enable") or true +-- how long before stuck mobs start searching +local pathfinding_stuck_timeout = tonumber( + settings:get("mob_pathfinding_stuck_timeout")) or 3.0 +-- how long will mob follow path before giving up +local pathfinding_stuck_path_timeout = tonumber(settings:get("mob_pathfinding_stuck_path_timeout")) or 5.0 +-- which algorithm to use, Dijkstra(default) or A*_noprefetch or A* +-- fix settings not allowing "*" +local pathfinding_algorithm = settings:get("mob_pathfinding_algorithm") or "Dijkstra" + +if pathfinding_algorithm == "AStar_noprefetch" then + pathfinding_algorithm = "A*_noprefetch" +elseif pathfinding_algorithm == "AStar" then + pathfinding_algorithm = "A*" +end + +-- max search distance from search positions (default 16) +local pathfinding_searchdistance = tonumber( + settings:get("mob_pathfinding_searchdistance") or 16) +-- max jump height (default 4) +local pathfinding_max_jump = tonumber(settings:get("mob_pathfinding_max_jump") or 4) +-- max drop height (default 6) +local pathfinding_max_drop = tonumber(settings:get("mob_pathfinding_max_drop") or 6) + -- Peaceful mode message so players will know there are no monsters if peaceful_only then minetest.register_on_joinplayer(function(player) @@ -100,20 +131,18 @@ end -- calculate aoc range for mob count local aoc_range = tonumber(settings:get("active_block_range")) * 16 --- pathfinding settings -local enable_pathfinding = true -local stuck_timeout = 3 -- how long before stuck mod starts searching -local stuck_path_timeout = 5 -- how long will mob follow path before giving up +-- can we attack Creatura mobs ? +local creatura = minetest.get_modpath("creatura") and + settings:get_bool("mobs_attack_creatura") == true -- default nodes ---local node_fire = "fire:basic_flame" ---local node_permanent_flame = "fire:permanent_flame" local node_ice = "default:ice" local node_snowblock = "default:snowblock" local node_snow = "default:snow" + mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt" -local mob_class = { +mobs.mob_class = { stepheight = 1.1, fly_in = "air", owner = "", @@ -179,26 +208,27 @@ local mob_class = { attack_animals = false, attack_players = true, attack_npcs = true, + friendly_fire = true, facing_fence = false, _breed_countdown = nil, _cmi_is_mob = true } +local mob_class = mobs.mob_class -- Compatibility local mob_class_meta = {__index = mob_class} -- play sound function mob_class:mob_sound(sound) - local pitch = 1.0 - - -- higher pitch for a child - if self.child then pitch = pitch * 1.5 end - - -- a little random pitch to be different - pitch = pitch + random(-10, 10) * 0.005 - if sound then + + -- higher pitch for a child + local pitch = self.child and 1.5 or 1.0 + + -- a little random pitch to be different + pitch = pitch + random(-10, 10) * 0.005 + minetest.sound_play(sound, { object = self.object, gain = 1.0, @@ -228,7 +258,7 @@ end -- calculate distance local get_distance = function(a, b) - if not a or not b then return 50 end -- nil check + if not a or not b then return 50 end -- nil check and default distance local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z @@ -239,8 +269,9 @@ end -- collision function based on jordan4ibanez' open_ai mod function mob_class:collision() - local pos = self.object:get_pos() + local pos = self.object:get_pos() ; if not pos then return {0, 0} end local x, z = 0, 0 + local vel = self.object:get_velocity() local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5 for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do @@ -249,9 +280,12 @@ function mob_class:collision() local pos2 = object:get_pos() local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z} + local force = (width + 0.5) - vector.distance( + {x = pos.x, y = 0, z = pos.z}, + {x = pos2.x, y = 0, z = pos2.z}) - x = x + vec.x - z = z + vec.z + x = x + (vec.x * force) + z = z + (vec.z * force) end end @@ -260,7 +294,7 @@ end -- check if string exists in another string or table -local check_for = function(look_for, look_inside) +local function check_for(look_for, look_inside) if type(look_inside) == "string" and look_inside == look_for then @@ -323,8 +357,7 @@ function mob_class:set_velocity(v) -- only slow mob trying to move while inside a viscous fluid that -- they aren't meant to be in (fish in water, spiders in cobweb etc) - if v > 0 and visc and visc > 0 - and not check_for(self.standing_in, self.fly_in) then + if v > 0 and visc and visc > 0 and not check_for(self.standing_in, self.fly_in) then v = v / (visc + 1) end @@ -363,7 +396,14 @@ function mob_class:set_yaw(yaw, delay) yaw = 0 end - delay = mob_smooth_rotate and (delay or 0) or 0 + delay = mob_smooth_rotate and delay or 0 + + -- simplified yaw clamp + if yaw > 6.283185 then + yaw = yaw - 6.283185 + elseif yaw < 0 then + yaw = 6.283185 + yaw + end if delay == 0 then @@ -414,7 +454,7 @@ function mob_class:set_animation(anim, force) anim = anim .. (num ~= 0 and num or "") end - if anim == self.animation.current + if (anim == self.animation.current and force ~= true) or not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"] then return @@ -435,11 +475,11 @@ end -- check line of sight (BrunoMine) -local line_of_sight = function(self, pos1, pos2, stepsize) +local function line_of_sight(self, pos1, pos2, stepsize) stepsize = stepsize or 1 - local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) + local s = minetest.line_of_sight(pos1, pos2, stepsize) -- normal walking and flying mobs can see you through air if s == true then @@ -466,7 +506,7 @@ local line_of_sight = function(self, pos1, pos2, stepsize) -- It continues to advance in the line of sight in search of a real -- obstruction which counts as 'walkable' nodebox. while minetest.registered_nodes[nn] - and (minetest.registered_nodes[nn].walkable == false) do + and minetest.registered_nodes[nn].walkable == false do -- Check if you can still move forward if td < ad + stepsize then @@ -482,9 +522,7 @@ local line_of_sight = function(self, pos1, pos2, stepsize) -- NaN checks if d == 0 - or npos1.x ~= npos1.x - or npos1.y ~= npos1.y - or npos1.z ~= npos1.z then + or npos1.x ~= npos1.x or npos1.y ~= npos1.y or npos1.z ~= npos1.z then return false end @@ -503,55 +541,8 @@ local line_of_sight = function(self, pos1, pos2, stepsize) end --- check line of sight (by BrunoMine, tweaked by Astrobe) -local new_line_of_sight = function(self, pos1, pos2, stepsize) - - if not pos1 or not pos2 then return end - - stepsize = stepsize or 1 - - local stepv = vmultiply(vdirection(pos1, pos2), stepsize) - - local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) - - -- normal walking and flying mobs can see you through air - if s == true then return true end - - -- New pos1 to be analyzed - local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} - - local r, pos = minetest.line_of_sight(npos1, pos2, stepsize) - - -- Checks the return - if r == true then return true end - - -- Nodename found - local nn = minetest.get_node(pos).name - - -- It continues to advance in the line of sight in search of a real - -- obstruction which counts as 'walkable' nodebox. - while minetest.registered_nodes[nn] - and (minetest.registered_nodes[nn].walkable == false) do - - npos1 = vadd(npos1, stepv) - - if get_distance(npos1, pos2) < stepsize then return true end - - -- scan again - r, pos = minetest.line_of_sight(npos1, pos2, stepsize) - - if r == true then return true end - - -- New Nodename found - nn = minetest.get_node(pos).name - end - - return false -end - - -- check line of sight using raycasting (thanks Astrobe) -local ray_line_of_sight = function(self, pos1, pos2) +local function ray_line_of_sight(self, pos1, pos2) local ray = minetest.raycast(pos1, pos2, true, false) local thing = ray:next() @@ -605,8 +596,7 @@ function mob_class:attempt_flight_correction(override) local flyable_nodes = minetest.find_nodes_in_area( {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}, - {x = pos.x + 1, y = pos.y + 0, z = pos.z + 1}, searchnodes) - -- pos.y + 0 hopefully fixes floating swimmers + {x = pos.x + 1, y = pos.y + 2, z = pos.z + 1}, searchnodes) if #flyable_nodes < 1 then return false @@ -615,8 +605,7 @@ function mob_class:attempt_flight_correction(override) local escape_target = flyable_nodes[random(#flyable_nodes)] local escape_direction = vdirection(pos, escape_target) - self.object:set_velocity( - vmultiply(escape_direction, 1)) + self.object:set_velocity(vmultiply(escape_direction, 1)) return true end @@ -646,7 +635,7 @@ end -- turn mob to face position -local yaw_to_pos = function(self, target, rot) +local function yaw_to_pos(self, target, rot) rot = rot or 0 @@ -705,8 +694,8 @@ end -- custom particle effects -local effect = function(pos, amount, texture, min_size, max_size, - radius, gravity, glow, fall) +local function effect( + pos, amount, texture, min_size, max_size, radius, gravity, glow, fall) radius = radius or 2 min_size = min_size or 0.5 @@ -740,8 +729,8 @@ local effect = function(pos, amount, texture, min_size, max_size, }) end -function mobs:effect(pos, amount, texture, min_size, max_size, - radius, gravity, glow, fall) +function mobs:effect( + pos, amount, texture, min_size, max_size, radius, gravity, glow, fall) effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, fall) end @@ -754,7 +743,7 @@ local HORNY_AGAIN_TIME = 60 * 5 -- 5 minutes local CHILD_GROW_TIME = 60 * 20 -- 20 minutes --- update nametag colour +-- update nametag and infotext function mob_class:update_tag() local col = "#00FF00" @@ -775,29 +764,28 @@ function mob_class:update_tag() local text = "" if self.horny == true then - text = "\nLoving: " .. (self.hornytimer - (HORNY_TIME + HORNY_AGAIN_TIME)) - elseif self.child == true then - text = "\nGrowing: " .. (self.hornytimer - CHILD_GROW_TIME) - elseif self._breed_countdown then - text = "\nBreeding: " .. self._breed_countdown + end + if self.protected then + if self.protected == 2 then + text = text .. "\nProtection: Level 2" + else + text = text .. "\nProtection: Level 1" + end end self.infotext = "Health: " .. self.health .. " / " .. self.hp_max - .. (self.owner == "" and "" or "\n" .. "Owner: " .. self.owner) + .. (self.owner == "" and "" or "\nOwner: " .. self.owner) .. text -- set changes self.object:set_properties({ - nametag = self.nametag, - nametag_color = col, - infotext = self.infotext - }) + nametag = self.nametag, nametag_color = col, infotext = self.infotext}) end @@ -810,8 +798,7 @@ function mob_class:item_drop() local pos = self.object:get_pos() -- check for drops function - self.drops = type(self.drops) == "function" - and self.drops(pos) or self.drops + self.drops = type(self.drops) == "function" and self.drops(pos) or self.drops -- check for nil or no drops if not self.drops or #self.drops == 0 then @@ -823,6 +810,25 @@ function mob_class:item_drop() and self.cause_of_death.puncher and self.cause_of_death.puncher:is_player() + -- check for tool 'looting_level' under tool_capabilities as default, or use + -- meta string 'looting_level' if found (max looting level is 3). + local looting = 0 + + if death_by_player then + + local wield_stack = self.cause_of_death.puncher:get_wielded_item() + local wield_name = wield_stack:get_name() + local wield_stack_meta = wield_stack:get_meta() + local item_def = minetest.registered_items[wield_name] + local item_looting = item_def and item_def.tool_capabilities and + item_def.tool_capabilities.looting_level or 0 + + looting = tonumber(wield_stack_meta:get_string("looting_level")) or item_looting + looting = min(looting, 3) + end + +--print("--- looting level", looting) + local obj, item, num for n = 1, #self.drops do @@ -845,7 +851,7 @@ function mob_class:item_drop() -- only drop rare items (drops.min = 0) if killed by player if death_by_player or self.drops[n].min ~= 0 then - obj = minetest.add_item(pos, ItemStack(item .. " " .. num)) + obj = minetest.add_item(pos, ItemStack(item .. " " .. (num + looting))) end if obj and obj:get_luaentity() then @@ -867,17 +873,12 @@ end -- remove mob and descrease counter -local remove_mob = function(self, decrease) +local function remove_mob(self, decrease) self.object:remove() if decrease and active_limit > 0 then - active_mobs = active_mobs - 1 - - if active_mobs < 0 then - active_mobs = 0 - end end --print("-- active mobs: " .. active_mobs .. " / " .. active_limit) end @@ -925,9 +926,8 @@ function mob_class:check_for_death(cmi_cause) self.cause_of_death = cmi_cause - -- drop items + -- drop items and play death sound self:item_drop() - self:mob_sound(self.sounds.death) local pos = self.object:get_pos() @@ -946,6 +946,16 @@ function mob_class:check_for_death(cmi_cause) return true end + -- reset vars and set state + self.attack = nil + self.following = nil + self.v_start = false + self.timer = 0 + self.blinktimer = 0 + self.passive = true + self.state = "die" + self.fly = false + -- check for custom death function and die animation if self.animation and self.animation.die_start @@ -956,13 +966,6 @@ function mob_class:check_for_death(cmi_cause) local length = max((frames / speed), 0) local rot = self.animation.die_rotate and 5 - self.attack = nil - self.following = nil - self.v_start = false - self.timer = 0 - self.blinktimer = 0 - self.passive = true - self.state = "die" self.object:set_properties({ pointable = false, collide_with_objects = false, automatic_rotate = rot, static_save = false @@ -984,7 +987,7 @@ function mob_class:check_for_death(cmi_cause) return true - elseif pos then -- otherwise remove mod and show particle effect + elseif pos then -- otherwise remove mob and show particle effect if use_cmi then cmi.notify_die(self.object, cmi_cause) @@ -1000,9 +1003,7 @@ end -- get node but use fallback for nil or unknown -local node_ok = function(pos, fallback) - - fallback = fallback or mobs.fallback_node +local function node_ok(pos, fallback) local node = minetest.get_node_or_nil(pos) @@ -1010,7 +1011,7 @@ local node_ok = function(pos, fallback) return node end - return minetest.registered_nodes[fallback] + return minetest.registered_nodes[(fallback or mobs.fallback_node)] end @@ -1070,7 +1071,7 @@ function mob_class:is_at_cliff() return true end - local bnode = node_ok(blocker) + local bnode = node_ok(blocker, "air") -- will we drop onto dangerous node? if is_node_dangerous(self, bnode.name) then @@ -1086,11 +1087,6 @@ end -- environmental damage (water, lava, fire, light etc.) function mob_class:do_env_damage() - -- feed/tame text timer (so mob 'full' messages dont spam chat) - if self.htimer > 0 then - self.htimer = self.htimer - 1 - end - self:update_tag() local pos = self.object:get_pos() ; if not pos then return end @@ -1177,10 +1173,17 @@ function mob_class:do_env_damage() end end - -- is mob light sensative, or scared of the dark :P + -- is mob light sensitive, or scared of the dark :P if self.light_damage ~= 0 then - local light = minetest.get_node_light(pos) or 0 + local light + + -- if max set to 16 then only kill mob with natural sunlight + if self.light_damage_max == 16 then + light = minetest.get_natural_light(pos) or 0 + else + light = minetest.get_node_light(pos) or 0 + end if light >= self.light_damage_min and light <= self.light_damage_max then @@ -1216,6 +1219,9 @@ function mob_class:do_env_damage() pos = pos, node = self.standing_in}) then return true end + + -- try to jump out of block + self.object:set_velocity({x = 0, y = self.jump_height, z = 0}) end return self:check_for_death({type = "unknown"}) @@ -1225,60 +1231,20 @@ end -- jump if facing a solid node (not fences or gates) function mob_class:do_jump() - if not self.jump - or self.jump_height == 0 - or self.fly - or self.child - or self.order == "stand" then + local vel = self.object:get_velocity() ; if not vel then return false end + + -- don't jump if ordered to stand or already in mid-air or moving forwards + if self.state == "stand" or vel.y ~= 0 or self:get_velocity() > 0.2 then return false end - self.facing_fence = false - - -- something stopping us while moving? - if self.state ~= "stand" - and self:get_velocity() > 0.5 - and self.object:get_velocity().y ~= 0 then - return false - end - - local pos = self.object:get_pos() - local yaw = self.object:get_yaw() - - -- sanity check - if not yaw then return false end - -- we can only jump if standing on solid node if minetest.registered_nodes[self.standing_on].walkable == false then return false end - -- where is front - local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) - local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) - - -- set y_pos to base of mob - pos.y = pos.y + self.collisionbox[2] - - -- what is in front of mob and above? - local nod = node_ok({x = pos.x + dir_x, y = pos.y + 0.5, z = pos.z + dir_z}) - local nodt = node_ok({x = pos.x + dir_x, y = pos.y + 1.5, z = pos.z + dir_z}) - - local blocked = minetest.registered_nodes[nodt.name].walkable - - -- are we facing a fence or wall - if nod.name:find("fence") or nod.name:find("gate") or nod.name:find("wall") then - self.facing_fence = true - end - ---[[ -print("on: " .. self.standing_on - .. ", front: " .. nod.name - .. ", front above: " .. nodt.name - .. ", blocked: " .. (blocked and "yes" or "no") - .. ", fence: " .. (self.facing_fence and "yes" or "no") -) -]] + -- is there anything stopping us from jumping up onto a block? + local blocked = minetest.registered_nodes[self.looking_above].walkable -- if mob can leap then remove blockages and let them try if self.can_leap == true then @@ -1286,15 +1252,19 @@ print("on: " .. self.standing_on self.facing_fence = false end - -- jump if standing on solid node (not snow) and not blocked - if (self.walk_chance == 0 or minetest.registered_items[nod.name].walkable) - and not blocked and not self.facing_fence and nod.name ~= node_snow then + -- jump if possible + if self.jump and self.jump_height > 0 and not self.fly and not self.child + and self.order ~= "stand" + and (self.walk_chance == 0 or minetest.registered_items[self.looking_at].walkable) + and not blocked + and not self.facing_fence + and self.looking_at ~= node_snow then local v = self.object:get_velocity() v.y = self.jump_height - self:set_animation("jump") -- only when defined + self:set_animation("jump") -- only if defined self.object:set_velocity(v) @@ -1330,7 +1300,7 @@ print("on: " .. self.standing_on local yaw = self.object:get_yaw() or 0 local turn = random(0, 2) + 1.35 - yaw = self:set_yaw(yaw + turn, 12) + self:set_yaw(yaw + turn, 12) self.jump_count = 0 end @@ -1341,7 +1311,7 @@ end -- blast damage to entities nearby (modified from TNT mod) -local entity_physics = function(pos, radius) +local function entity_physics(pos, radius) radius = radius * 2 @@ -1357,19 +1327,18 @@ local entity_physics = function(pos, radius) if dist < 1 then dist = 1 end local damage = floor((4 / dist) * radius) - local ent = objs[n]:get_luaentity() -- punches work on entities AND players objs[n]:punch(objs[n], 1.0, { full_punch_interval = 1.0, - damage_groups = {fleshy = damage}, + damage_groups = {fleshy = damage} }, pos) end end -- can mob see player -local is_invisible = function(self, player_name) +local function is_invisible(self, player_name) if mobs.invis[player_name] and not self.ignore_invisibility then return true @@ -1408,6 +1377,12 @@ function mob_class:breed() self.child = false self.hornytimer = 0 + -- replace child texture with adult one + if self.mommy_tex then + self.base_texture = self.mommy_tex + self.mommy_tex = nil + end + self.object:set_properties({ textures = self.base_texture, mesh = self.base_mesh, @@ -1428,7 +1403,7 @@ function mob_class:breed() self.object:set_pos(pos) -- jump slightly when fully grown so as not to fall into ground - self.object:set_velocity({x = 0, y = 0.5, z = 0 }) + self.object:set_velocity({x = 0, y = 2, z = 0 }) end end @@ -1521,12 +1496,16 @@ function mob_class:breed() return end + -- reset parent movement + self.follow_stop = false + ent.follow_stop = false + -- custom breed function if self.on_breed then -- when false skip going any further if self:on_breed(ent) == false then - return + return end else effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5) @@ -1538,39 +1517,46 @@ function mob_class:breed() local ent2 = mob:get_luaentity() local textures = self.base_texture - -- using specific child texture (if found) - if self.child_texture then - textures = self.child_texture[1] - end + -- make sure baby is actually there + if ent2 then - -- and resize to half height - mob:set_properties({ - textures = textures, - visual_size = { - x = self.base_size.x * .5, - y = self.base_size.y * .5 - }, - collisionbox = { - self.base_colbox[1] * .5, - self.base_colbox[2] * .5, - self.base_colbox[3] * .5, - self.base_colbox[4] * .5, - self.base_colbox[5] * .5, - self.base_colbox[6] * .5 - }, - selectionbox = { - self.base_selbox[1] * .5, - self.base_selbox[2] * .5, - self.base_selbox[3] * .5, - self.base_selbox[4] * .5, - self.base_selbox[5] * .5, - self.base_selbox[6] * .5 - } - }) - -- tamed and owned by parents' owner - ent2.child = true - ent2.tamed = true - ent2.owner = self.owner + -- using specific child texture (if found) + if self.child_texture then + textures = self.child_texture[1] + ent2.mommy_tex = self.base_texture + end + + -- and resize to half height + mob:set_properties({ + textures = textures, + visual_size = { + x = self.base_size.x * .5, + y = self.base_size.y * .5 + }, + collisionbox = { + self.base_colbox[1] * .5, + self.base_colbox[2] * .5, + self.base_colbox[3] * .5, + self.base_colbox[4] * .5, + self.base_colbox[5] * .5, + self.base_colbox[6] * .5 + }, + selectionbox = { + self.base_selbox[1] * .5, + self.base_selbox[2] * .5, + self.base_selbox[3] * .5, + self.base_selbox[4] * .5, + self.base_selbox[5] * .5, + self.base_selbox[6] * .5 + } + }) + + -- tamed and owned by parents' owner + ent2.child = true + ent2.tamed = true + ent2.owner = self.owner + ent2.base_texture = textures + end end, self, ent) break @@ -1652,7 +1638,9 @@ end local los_switcher = false local height_switcher = false -local can_dig_drop = function(pos) + +-- are we able to dig this node and add drops? +local function can_dig_drop(pos) if minetest.is_protected(pos, "") then return false @@ -1737,7 +1725,7 @@ function mob_class:smart_mobs(s, p, dist, dtime) end -- can see target! end - if (self.path.stuck_timer > stuck_timeout and not self.path.following) then + if self.path.stuck_timer > pathfinding_stuck_timeout and not self.path.following then use_pathfind = true self.path.stuck_timer = 0 @@ -1753,7 +1741,7 @@ function mob_class:smart_mobs(s, p, dist, dtime) end, self) end - if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then + if self.path.stuck_timer > pathfinding_stuck_path_timeout and self.path.following then use_pathfind = true self.path.stuck_timer = 0 @@ -1769,7 +1757,7 @@ function mob_class:smart_mobs(s, p, dist, dtime) end, self) end - if abs(vsubtract(s,target_pos).y) > self.stepheight then + if abs(vsubtract(s, target_pos).y) > self.stepheight then if height_switcher then use_pathfind = true @@ -1805,24 +1793,25 @@ function mob_class:smart_mobs(s, p, dist, dtime) p1.y = floor(p1.y + 0.5) p1.z = floor(p1.z + 0.5) - local dropheight = 6 + local dropheight = pathfinding_max_drop if self.fear_height ~= 0 then dropheight = self.fear_height end local jumpheight = 0 - if self.jump and self.jump_height >= 4 then - jumpheight = min(ceil(self.jump_height / 4), 4) + if self.jump and self.jump_height >= pathfinding_max_jump then + jumpheight = min(ceil( + self.jump_height / pathfinding_max_jump), pathfinding_max_jump) elseif self.stepheight > 0.5 then jumpheight = 1 end - if pathfinder_mod then + if pathfinder_mod and pathfinder_enable then self.path.way = pathfinder.find_path(s, p1, self, dtime) else - self.path.way = minetest.find_path(s, p1, 16, jumpheight, - dropheight, "Dijkstra") + self.path.way = minetest.find_path(s, p1, pathfinding_searchdistance, + jumpheight, dropheight, pathfinding_algorithm) end --[[ -- show path using particles @@ -1831,15 +1820,16 @@ function mob_class:smart_mobs(s, p, dist, dtime) print("-- path length:" .. tonumber(#self.path.way)) for _,pos in pairs(self.path.way) do + minetest.add_particle({ - pos = pos, - velocity = {x=0, y=0, z=0}, - acceleration = {x=0, y=0, z=0}, - expirationtime = 1, - size = 4, - collisiondetection = false, - vertical = false, - texture = "heart.png", + pos = pos, + velocity = {x=0, y=0, z=0}, + acceleration = {x=0, y=0, z=0}, + expirationtime = 1, + size = 4, + collisiondetection = false, + vertical = false, + texture = "heart.png", }) end end @@ -1910,7 +1900,7 @@ function mob_class:smart_mobs(s, p, dist, dtime) end -- will try again in 2 second - self.path.stuck_timer = stuck_timeout - 2 + self.path.stuck_timer = pathfinding_stuck_timeout - 2 elseif s.y < p1.y and (not self.fly) then self:do_jump() --add jump to pathfinding @@ -1935,14 +1925,17 @@ end -- peaceful player privilege support local function is_peaceful_player(player) + -- main setting enabled if peaceful_player_enabled then + return true + end - local player_name = player:get_player_name() + local player_name = player:get_player_name() - if player_name - and minetest.check_player_privs(player_name, "peaceful_player") then - return true - end + -- player priv enabled + if player_name + and minetest.check_player_privs(player_name, "peaceful_player") then + return true end return false @@ -1982,6 +1975,22 @@ function mob_class:general_attack() --print("- pla", n) end + -- are we a creatura mob? + elseif creatura and ent and ent._cmi_is_mob ~= true + and ent.hitbox and ent.stand_node then + + -- monsters attack all creatura mobs, npc and animals will only attack + -- if the animal owner is currently being attacked by creatura mob + if self.name == ent.name + or (self.type ~= "monster" + and self.owner ~= (ent._target and ent._target:get_player_name() or ".")) + or (self.specific_attack + and not check_for(ent.name, self.specific_attack)) then + + objs[n] = nil +--print("-- creatura", ent.name) + end + -- or are we a mob? elseif ent and ent._cmi_is_mob then @@ -2085,8 +2094,7 @@ function mob_class:do_runaway_from() dist = get_distance(p, s) -- choose closest player/mob to runaway from - if dist < min_dist - and self:line_of_sight(sp, p, 2) == true then + if dist < min_dist and self:line_of_sight(sp, p, 2) == true then min_dist = dist min_player = player end @@ -2118,12 +2126,13 @@ function mob_class:follow_flop() for n = 1, #players do - if players[n] then - if get_distance(players[n]:get_pos(), s) < self.view_range - and not is_invisible(self, players[n]:get_player_name()) then - self.following = players[n] - break - end + if players[n] + and not is_invisible(self, players[n]:get_player_name()) + and get_distance(players[n]:get_pos(), s) < self.view_range then + + self.following = players[n] + + break end end end @@ -2135,16 +2144,13 @@ function mob_class:follow_flop() -- npc stop following player if not owner if self.following - and self.owner - and self.owner ~= self.following:get_player_name() then + and self.owner and self.owner ~= self.following:get_player_name() then self.following = nil end else -- stop following player if not holding specific item or mob is horny - if self.following - and self.following:is_player() - and (self:follow_holding(self.following) == false - or self.horny) then + if self.following and self.following:is_player() + and (self:follow_holding(self.following) == false or self.horny) then self.following = nil end @@ -2157,11 +2163,8 @@ function mob_class:follow_flop() local p if self.following:is_player() then - p = self.following:get_pos() - elseif self.following.object then - p = self.following.object:get_pos() end @@ -2176,10 +2179,11 @@ function mob_class:follow_flop() yaw_to_pos(self, p) -- anyone but standing npc's can move along - if dist > self.reach + if dist >= self.reach and self.order ~= "stand" then self:set_velocity(self.walk_velocity) + self.follow_stop = nil if self.walk_chance ~= 0 then self:set_animation("walk") @@ -2187,6 +2191,7 @@ function mob_class:follow_flop() else self:set_velocity(0) self:set_animation("stand") + self.follow_stop = true end return @@ -2226,17 +2231,14 @@ end function mob_class:dogswitch(dtime) -- switch mode not activated - if not self.dogshoot_switch - or not dtime then + if not self.dogshoot_switch or not dtime then return 0 end self.dogshoot_count = self.dogshoot_count + dtime - if (self.dogshoot_switch == 1 - and self.dogshoot_count > self.dogshoot_count_max) - or (self.dogshoot_switch == 2 - and self.dogshoot_count > self.dogshoot_count2_max) then + if (self.dogshoot_switch == 1 and self.dogshoot_count > self.dogshoot_count_max) + or (self.dogshoot_switch == 2 and self.dogshoot_count > self.dogshoot_count2_max) then self.dogshoot_count = 0 @@ -2256,7 +2258,57 @@ function mob_class:do_states(dtime) local yaw = self.object:get_yaw() ; if not yaw then return end - if self.state == "stand" then + -- are we standing in something that hurts ? Try to get out + if is_node_dangerous(self, self.standing_in) then + + local s = self.object:get_pos() + local lp + + -- is there something I need to avoid? + if self.water_damage > 0 + and self.lava_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:water", "group:igniter"}) + + elseif self.water_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:water"}) + + elseif self.lava_damage > 0 then + + lp = minetest.find_node_near(s, 1, {"group:igniter"}) + end + + if lp then + + if self.pause_timer <= 0 then + + lp = minetest.find_nodes_in_area_under_air( + {x = s.x - 5, y = s.y , z = s.z - 5}, + {x = s.x + 5, y = s.y + 2, z = s.z + 5}, + {"group:soil", "group:stone", "group:sand", node_ice, node_snowblock}) + + -- did we find land? + if lp and #lp > 0 then + + -- select position of random block to climb onto + lp = lp[random(#lp)] + + yaw = yaw_to_pos(self, lp) + end + + self.pause_timer = 3 + self.following = nil + + self:set_velocity(self.run_velocity) + self:set_animation("walk") + + return + end + end + end + + if self.state == "stand" and not self.follow_stop then if self.randomly_turn and random(4) == 1 then @@ -2279,7 +2331,7 @@ function mob_class:do_states(dtime) yaw = yaw + random(-0.5, 0.5) end - yaw = self:set_yaw(yaw, 8) + self:set_yaw(yaw, 8) end self:set_velocity(0) @@ -2299,62 +2351,14 @@ function mob_class:do_states(dtime) elseif self.state == "walk" then - local s = self.object:get_pos() - local lp - - -- is there something I need to avoid? - if self.water_damage > 0 - and self.lava_damage > 0 then - - lp = minetest.find_node_near(s, 1, {"group:water", "group:igniter"}) - - elseif self.water_damage > 0 then - - lp = minetest.find_node_near(s, 1, {"group:water"}) - - elseif self.lava_damage > 0 then - - lp = minetest.find_node_near(s, 1, {"group:igniter"}) - end - - if lp then - - -- if mob in dangerous node then look for land - if not is_node_dangerous(self, self.standing_in) then - - lp = minetest.find_nodes_in_area_under_air( - {s.x - 5, s.y - 1, s.z - 5}, - {s.x + 5, s.y + 2, s.z + 5}, - {"group:soil", "group:stone", "group:sand", - node_ice, node_snowblock}) - - -- select position of random block to climb onto - lp = #lp > 0 and lp[random(#lp)] - - -- did we find land? - if lp then - - yaw = yaw_to_pos(self, lp) - - self:do_jump() - self:set_velocity(self.walk_velocity) - else - yaw = yaw + random(-0.5, 0.5) - end - end - - yaw = self:set_yaw(yaw, 8) - - -- otherwise randomly turn - elseif self.randomly_turn and random(100) <= 30 then + if self.randomly_turn and random(100) <= 30 then yaw = yaw + random(-0.5, 0.5) - yaw = self:set_yaw(yaw, 8) + self:set_yaw(yaw, 8) -- for flying/swimming mobs randomly move up and down also - if self.fly_in - and not self.following then + if self.fly_in and not self.following then self:attempt_flight_correction(true) end end @@ -2365,8 +2369,7 @@ function mob_class:do_states(dtime) or random(100) <= self.stand_chance then -- don't stand if mob flies and keep_flying set - if (self.fly and not self.keep_flying) - or not self.fly then + if (self.fly and not self.keep_flying) or not self.fly then self:set_velocity(0) self.state = "stand" @@ -2430,23 +2433,24 @@ function mob_class:do_states(dtime) or (self.attack:is_player() and is_invisible(self, self.attack:get_player_name())) then ---print(" ** stop attacking **", dist, self.view_range) +--print(" ** stop attacking **", self.name, self.health, dist, self.view_range) - self.state = "stand" - self:set_velocity(0) - self:set_animation("stand") self.attack = nil + self.following = nil self.v_start = false self.timer = 0 self.blinktimer = 0 self.path.way = nil + self:set_velocity(0) + self.state = "stand" + self:set_animation("stand", true) return end if self.attack_type == "explode" then - yaw = yaw_to_pos(self, p) + yaw_to_pos(self, p) local node_break_radius = self.explosion_radius or 1 local entity_damage_radius = self.explosion_damage_radius @@ -2508,8 +2512,7 @@ function mob_class:do_states(dtime) self.object:set_texture_mod(self.texture_mods) else - self.object:set_texture_mod(self.texture_mods - .. "^[brighten") + self.object:set_texture_mod(self.texture_mods .. "^[brighten") end self.blinkstatus = not self.blinkstatus @@ -2521,7 +2524,7 @@ function mob_class:do_states(dtime) local pos = self.object:get_pos() - -- dont damage anything if area protected or next to water + -- dont damage anything if area protected or next to waterpathfinding_max_jump if minetest.find_node_near(pos, 1, {"group:water"}) or minetest.is_protected(pos, "") then @@ -2530,27 +2533,7 @@ function mob_class:do_states(dtime) remove_mob(self, true) - if minetest.get_modpath("tnt") and tnt and tnt.boom - and not minetest.is_protected(pos, "") then - - tnt.boom(pos, { - radius = node_break_radius, - damage_radius = entity_damage_radius, - sound = self.sounds.explode - }) - else - - minetest.sound_play(self.sounds.explode, { - pos = pos, - gain = 1.0, - max_hear_distance = self.sounds.distance or 32 - }) - - entity_physics(pos, entity_damage_radius) - - effect(pos, 32, "tnt_smoke.png", nil, nil, - node_break_radius, 1, 0) - end + mobs:boom(self, pos, entity_damage_radius, node_break_radius) return true end @@ -2575,35 +2558,21 @@ function mob_class:do_states(dtime) if me_y < p_y then self.object:set_velocity({ - x = v.x, - y = 1 * self.walk_velocity, - z = v.z - }) + x = v.x, y = 1 * self.walk_velocity, z = v.z}) elseif me_y > p_y then self.object:set_velocity({ - x = v.x, - y = -1 * self.walk_velocity, - z = v.z - }) + x = v.x, y = -1 * self.walk_velocity, z = v.z}) end else if me_y < p_y then - self.object:set_velocity({ - x = v.x, - y = 0.01, - z = v.z - }) + self.object:set_velocity({x = v.x, y = 0.01, z = v.z}) elseif me_y > p_y then - self.object:set_velocity({ - x = v.x, - y = -0.01, - z = v.z - }) + self.object:set_velocity({x = v.x, y = -0.01, z = v.z}) end end end @@ -2614,8 +2583,7 @@ function mob_class:do_states(dtime) and self.attack_type ~= "dogshoot" then -- no paths longer than 50 - if #self.path.way > 50 - or dist < self.reach then + if #self.path.way > 50 or dist < self.reach then self.path.following = false return end @@ -2636,15 +2604,13 @@ function mob_class:do_states(dtime) p = {x = p1.x, y = p1.y, z = p1.z} end - yaw = yaw_to_pos(self, p) + yaw_to_pos(self, p) -- move towards enemy if beyond mob reach if dist > (self.reach + (self.reach_ext or 0)) then - -- path finding by rnd - if self.pathfinding -- only if mob has pathfinding enabled - and enable_pathfinding then - + -- path finding by rnd (only when enabled in setting and mob) + if self.pathfinding and pathfinding_enable then self:smart_mobs(s, p, dist, dtime) end @@ -2730,12 +2696,11 @@ function mob_class:do_states(dtime) local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z} - yaw = yaw_to_pos(self, p) + yaw_to_pos(self, p) self:set_velocity(0) - if self.shoot_interval - and self.timer > self.shoot_interval + if self.shoot_interval and self.timer > self.shoot_interval and random(100) <= 60 then self.timer = 0 @@ -2841,17 +2806,14 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) return true end - -- custom punch function - if self.do_punch - and self:do_punch(hitter, tflp, tool_capabilities, dir) == false then + -- custom punch function (if false returned, do not continue and return true) + if self.do_punch and self:do_punch(hitter, tflp, tool_capabilities, dir) == false then return true end -- error checking when mod profiling is enabled if not tool_capabilities then - minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled") - return true end @@ -2878,11 +2840,8 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) local ent = hitter and hitter:get_luaentity() if ent and ent._is_arrow then - return true -- arrow entity - elseif not ent then - return true -- non entity end end @@ -2890,7 +2849,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) local weapon = hitter:get_wielded_item() local weapon_def = weapon:get_definition() or {} - local punch_interval = 1.4 -- calculate mob damage local damage = 0 @@ -2952,18 +2910,13 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) end -- add weapon wear - punch_interval = tool_capabilities.full_punch_interval or 1.4 + local punch_interval = tool_capabilities.full_punch_interval or 1.4 -- toolrank support local wear = floor((punch_interval / 75) * 9000) if mobs.is_creative(hitter:get_player_name()) then - - if tr then - wear = 1 - else - wear = 0 - end + wear = tr and 1 or 0 end if tr and weapon_def.original_description then @@ -2978,8 +2931,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) if damage >= 1 then -- select tool use sound if found, or fallback to default - local snd = weapon_def.sound and weapon_def.sound.use - or "default_punch" + local snd = weapon_def.sound and weapon_def.sound.use or "mobs_punch" minetest.sound_play(snd, {object = self.object, max_hear_distance = 8}, true) @@ -3005,8 +2957,35 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) effect(pos, amount, blood, 1, 2, 1.75, nil, nil, true) end - -- do damage - self.health = self.health - floor(damage) + -- add healthy afterglow when hit (can cause lag with larger textures) + if mob_hit_effect then + + self.old_texture_mods = self.texture_mods + + self.object:set_texture_mod(self.texture_mods .. self.damage_texture_modifier) + + minetest.after(0.3, function() + + if self and self.object and self.object:get_pos() then + + self.texture_mods = self.old_texture_mods + self.old_texture_mods = nil + self.object:set_texture_mod(self.texture_mods) + end + end) + end + + -- check for friendly fire (arrows from same mob) + if self.friendly_fire then + self.health = self.health - floor(damage) -- do damage regardless + else + local entity = hitter and hitter:get_luaentity() + + -- check if arrow from same mob, if so then do no damage + if (entity and entity.name ~= self.arrow) or hitter:is_player() then + self.health = self.health - floor(damage) + end + end -- exit here if dead, check for tools with fire damage local hot = tool_capabilities and tool_capabilities.damage_groups @@ -3029,8 +3008,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) local up = 2 -- if already in air then dont go up anymore when hit - if v.y > 0 - or self.fly then + if v.y > 0 or self.fly then up = 0 end @@ -3042,15 +3020,24 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) self.object:set_velocity({x = dir.x * kb, y = up, z = dir.z * kb}) + -- turn mob on knockback and play run/walk animation + self:set_yaw((random(0, 360) - 180) / 180 * pi, 12) + + if self.animation and self.animation.injured_end and damage >= 1 then + self:set_animation("injured") + else + self:set_animation("walk") + end + self.pause_timer = 0.25 end -- if skittish then run away - if self.runaway == true - and self.order ~= "stand" then + if self.runaway == true and self.order ~= "stand" then local lp = hitter:get_pos() - local yaw = yaw_to_pos(self, lp, 3) + + yaw_to_pos(self, lp, 3) self.state = "runaway" self.runaway_timer = 0 @@ -3073,8 +3060,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) self:do_attack(hitter) -- alert others to the attack - local objs = minetest.get_objects_inside_radius( - hitter:get_pos(), self.view_range) + local objs = minetest.get_objects_inside_radius(hitter:get_pos(), self.view_range) local obj for n = 1, #objs do @@ -3087,9 +3073,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) if obj.group_attack == true and obj.state ~= "attack" and obj.owner ~= name - and (obj.name == self.name - or obj.name == self.group_helper) then - + and (obj.name == self.name or obj.name == self.group_helper) then obj:do_attack(hitter) end @@ -3100,6 +3084,30 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) end end end + + return true +end + + +-- helper function to clean mob staticdata +local function clean_staticdata(self) + + local tmp, t = {} + + for _,stat in pairs(self) do + + t = type(stat) + + if t ~= "function" + and t ~= "nil" + and t ~= "userdata" + and _ ~= "object" + and _ ~= "_cmi_components" then + tmp[_] = self[_] + end + end + + return tmp end @@ -3139,26 +3147,10 @@ function mob_class:mob_staticdata() end if use_cmi then - self.serialized_cmi_components = cmi.serialize_components( - self._cmi_components) + self.serialized_cmi_components = cmi.serialize_components(self._cmi_components) end - local tmp, t = {} - - for _,stat in pairs(self) do - - t = type(stat) - - if t ~= "function" - and t ~= "nil" - and t ~= "userdata" - and _ ~= "object" - and _ ~= "_cmi_components" then - tmp[_] = self[_] - end - end - - return minetest.serialize(tmp) + return minetest.serialize(clean_staticdata(self)) end @@ -3187,7 +3179,7 @@ function mob_class:mob_activate(staticdata, def, dtime) return end - -- load entity variables + -- load entity variables from staticdata into self. local tmp = minetest.deserialize(staticdata) if tmp then @@ -3198,9 +3190,7 @@ function mob_class:mob_activate(staticdata, def, dtime) t = type(stat) - if t ~= "function" - and t ~= "nil" - and t ~= "userdata" then + if t ~= "function" and t ~= "nil" and t ~= "userdata" then self[_] = stat end end @@ -3302,10 +3292,8 @@ function mob_class:mob_activate(staticdata, def, dtime) self.standing_in = "air" self.standing_on = "air" - -- check existing nametag - if not self.nametag then - self.nametag = def.nametag - end + -- check for existing nametag + self.nametag = self.nametag or def.nametag -- set anything changed above self.object:set_properties(self) @@ -3322,10 +3310,8 @@ function mob_class:mob_activate(staticdata, def, dtime) end -- run on_spawn function if found - if self.on_spawn and not self.on_spawn_run then - if self.on_spawn(self) then - self.on_spawn_run = true -- if true, set flag to run once only - end + if self.on_spawn and not self.on_spawn_run and self.on_spawn(self) then + self.on_spawn_run = true -- if true, set flag to run once only end -- run after_activate @@ -3334,8 +3320,7 @@ function mob_class:mob_activate(staticdata, def, dtime) end if use_cmi then - self._cmi_components = cmi.activate_components( - self.serialized_cmi_components) + self._cmi_components = cmi.activate_components(self.serialized_cmi_components) cmi.notify_activate(self.object, dtime) end end @@ -3380,6 +3365,50 @@ function mob_class:mob_expire(pos, dtime) end +-- get nodes mob is standing on/in, facing/above +function mob_class:get_nodes() + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + + -- child mobs have a lower y_level + local y_level = self.child and self.collisionbox[2] * 0.5 or self.collisionbox[2] + + self.standing_in = node_ok({ + x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name + + self.standing_on = node_ok({ + x = pos.x, y = pos.y + y_level - 0.25, z = pos.z}, "air").name + + -- find front position + local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + + -- nodes in front of mob and front/above + self.looking_at = node_ok({ + x = pos.x + dir_x, y = pos.y + y_level + 0.25, z = pos.z + dir_z}).name + + self.looking_above = node_ok({ + x = pos.x + dir_x, y = pos.y + y_level + 1.25, z = pos.z + dir_z}).name + + -- are we facing a fence or wall + if self.looking_at:find("fence") + or self.looking_at:find("gate") + or self.looking_at:find("wall") then + self.facing_fence = true + else + self.facing_fence = nil + end +--[[ +print("on: " .. self.standing_on + .. ", front: " .. self.looking_at + .. ", front above: " .. self.looking_above + .. ", fence: " .. (self.facing_fence and "yes" or "no") +) +]] +end + + -- main mob function function mob_class:on_step(dtime, moveresult) @@ -3397,46 +3426,26 @@ function mob_class:on_step(dtime, moveresult) self.node_timer = (self.node_timer or 0) + dtime - -- get nodes above and below foot level every 1/4 second - if self.node_timer > 0.25 then + -- get nodes every 1/4 second + if self.node_timer > node_timer_interval then + + -- get nodes above, below, in front and front-above + self:get_nodes() self.node_timer = 0 - local y_level = self.collisionbox[2] - - if self.child then - y_level = self.collisionbox[2] * 0.5 - end - - -- what is mob standing in? - self.standing_in = node_ok({ - x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name - - self.standing_on = node_ok({ - x = pos.x, y = pos.y + y_level - 0.25, z = pos.z}, "air").name - ---print("standing in " .. self.standing_in) - - -- if standing inside solid block then jump to escape - if minetest.registered_nodes[self.standing_in].walkable - and minetest.registered_nodes[self.standing_in].drawtype == "normal" then - - self.object:set_velocity({ - x = 0, - y = self.jump_height, - z = 0 - }) - end - -- check and stop if standing at cliff and fear of heights self.at_cliff = self:is_at_cliff() - if self.at_cliff then + if self.pause_timer <= 0 and self.at_cliff then self:set_velocity(0) end -- has mob expired (0.25 instead of dtime since were in a timer) - self:mob_expire(pos, 0.25) + self:mob_expire(pos, node_timer_interval) + + -- check if mob can jump or is blocked facing fence/gate etc. + self:do_jump() end -- check if falling, flying, floating and return if player died @@ -3455,8 +3464,8 @@ function mob_class:on_step(dtime, moveresult) if yaw > self.target_yaw then if dif > pi then - dif = 2 * pi - dif -- need to add - yaw = yaw + dif / self.delay + dif = 2 * pi - dif + yaw = yaw + dif / self.delay -- need to add else yaw = yaw - dif / self.delay -- need to subtract end @@ -3479,50 +3488,10 @@ function mob_class:on_step(dtime, moveresult) self.object:set_yaw(yaw) end - -- knockback timer - if self.pause_timer > 0 then - - self.pause_timer = self.pause_timer - dtime - - return - end - - -- run custom function (defined in mob lua file) - if self.do_custom then - - -- when false skip going any further - if self:do_custom(dtime) == false then - return - end - end - - -- attack timer - self.timer = self.timer + dtime - - if self.state ~= "attack" then - - if self.timer < 1 then - return - end - - self.timer = 0 - end - - -- never go over 100 - if self.timer > 100 then - self.timer = 1 - end - - -- mob plays random sound at times - if random(100) == 1 then - self:mob_sound(self.sounds.random) - end - -- environmental damage timer (every 1 second) self.env_damage_timer = self.env_damage_timer + dtime - if (self.state == "attack" and self.env_damage_timer > 1) - or self.state ~= "attack" then + if self.env_damage_timer > 1 then self.env_damage_timer = 0 @@ -3533,19 +3502,66 @@ function mob_class:on_step(dtime, moveresult) self:replace(pos) end - self:general_attack() + -- knockback timer + if self.pause_timer > 0 then - self:breed() + self.pause_timer = self.pause_timer - dtime - self:follow_flop() + if self.pause_timer <= 0 and self.order == "stand" then - if self:do_states(dtime) then return end + self.pause_timer = 0 + self:set_velocity(0) + self:set_animation("stand", true) + end - self:do_jump() + return + end - self:do_runaway_from(self) + -- run custom function (defined in mob lua file) - when false skip going any further + if self.do_custom and self:do_custom(dtime, moveresult) == false then + return + end - self:do_stay_near() + -- attack timer + self.timer = self.timer + dtime + + -- never go over 100 + if self.timer > 100 then + self.timer = 1 + end + + -- when attacking call do_states live (return if dead) + if self.state == "attack" then + if self:do_states(dtime) then return end + end + + -- one second timed calls + self.timer1 = (self.timer1 or 0) + dtime + + if self.timer1 >= main_timer_interval then + + -- mob plays random sound at times + if random(100) == 1 then + self:mob_sound(self.sounds.random) + end + + self:general_attack() + + self:breed() + + self:follow_flop() + + -- when not attacking call do_states every second (return if dead) + if self.state ~= "attack" then + if self:do_states(main_timer_interval) then return end + end + + self:do_runaway_from(self) + + self:do_stay_near() + + self.timer1 = 0 + end end @@ -3555,9 +3571,7 @@ function mob_class:on_blast(damage) --print("-- blast damage", damage) self.object:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = damage}, - }, nil) + full_punch_interval = 1.0, damage_groups = {fleshy = damage}}, nil) -- return no damage, no knockback, no item drops, mob api handles all return false, false, {} @@ -3574,7 +3588,7 @@ function mobs:register_mob(name, def) local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25} -- quick fix to stop mobs glitching through nodes if too small - if -collisionbox[2] + collisionbox[5] < 1.01 then + if mob_height_fix and -collisionbox[2] + collisionbox[5] < 1.01 then collisionbox[5] = collisionbox[2] + 0.99 end @@ -3611,7 +3625,7 @@ minetest.register_entity(name, setmetatable({ run_velocity = def.run_velocity, damage = max(0, (def.damage or 0) * difficulty), damage_group = def.damage_group, - damage_texture_modifier = def.damage_texture_modifier, + damage_texture_modifier = def.damage_texture_modifier or "^[colorize:#c9900070", light_damage = def.light_damage, light_damage_min = def.light_damage_min, light_damage_max = def.light_damage_max, @@ -3672,21 +3686,19 @@ minetest.register_entity(name, setmetatable({ attack_players = def.attack_players, attack_npcs = def.attack_npcs, specific_attack = def.specific_attack, + friendly_fire = def.friendly_fire, runaway_from = def.runaway_from, owner_loyal = def.owner_loyal, pushable = def.pushable, stay_near = def.stay_near, randomly_turn = def.randomly_turn ~= false, ignore_invisibility = def.ignore_invisibility, + messages = def.messages, on_spawn = def.on_spawn, - on_blast = def.on_blast, -- class redifinition - do_punch = def.do_punch, - on_breed = def.on_breed, - on_grown = def.on_grown, on_activate = function(self, staticdata, dtime) @@ -3704,7 +3716,7 @@ end -- END mobs:register_mob function -- count how many mobs of one type are inside an area -- will also return true for second value if player is inside area -local count_mobs = function(pos, type) +local function count_mobs(pos, type) local total = 0 local objs = minetest.get_objects_inside_radius(pos, aoc_range * 2) @@ -3731,7 +3743,7 @@ end -- do we have enough space to spawn mob? (thanks wuzzy) -local can_spawn = function(pos, name) +local function can_spawn(pos, name) local ent = minetest.registered_entities[name] local width_x = max(1, ceil(ent.collisionbox[4] - ent.collisionbox[1])) @@ -3793,6 +3805,12 @@ end function mobs:add_mob(pos, def) + -- nil check + if not pos or not def then +--print("--- no position or definition given") + return + end + -- is mob actually registered? if not mobs.spawning_mobs[def.name] or not minetest.registered_entities[def.name] then @@ -3814,8 +3832,7 @@ function mobs:add_mob(pos, def) return end - local aoc = mobs.spawning_mobs[def.name] - and mobs.spawning_mobs[def.name].aoc or 1 + local aoc = mobs.spawning_mobs[def.name] and mobs.spawning_mobs[def.name].aoc or 1 if def.ignore_count ~= true and num_mob >= aoc then --print("--- too many " .. def.name .. " in area", num_mob .. "/" .. aoc) @@ -3842,7 +3859,7 @@ function mobs:add_mob(pos, def) textures = ent.child_texture[1] end - -- and resize to half height + -- and resize to half height (multiplication is faster than division) mob:set_properties({ textures = textures, visual_size = { @@ -3929,8 +3946,8 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter mobs.spawning_mobs[name].aoc = aoc - local spawn_action = function(pos, node, active_object_count, - active_object_count_wider) + local spawn_action = function( + pos, node, active_object_count, active_object_count_wider) -- use instead of abm's chance setting when using lbm if map_load and random(max(1, (chance * mob_chance_multiplier))) > 1 then @@ -3962,8 +3979,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter end -- do not spawn if too many entities in area - if active_object_count_wider - and active_object_count_wider >= max_per_block then + if active_object_count_wider and active_object_count_wider >= max_per_block then --print("--- too many entities in area", active_object_count_wider) return end @@ -4005,17 +4021,14 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter pos.y = pos.y + 1 -- are we spawning within height limits? - if pos.y > max_height - or pos.y < min_height then + if pos.y > max_height or pos.y < min_height then --print("--- height limits not met", name, pos.y) return end -- are light levels ok? local light = minetest.get_node_light(pos) - if not light - or light > max_light - or light < min_light then + if not light or light > max_light or light < min_light then --print("--- light limits not met", name, light) return end @@ -4073,7 +4086,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter -- .. minetest.pos_to_string(pos) .. " on " -- .. node.name .. " near " .. neighbors[1]) - if on_spawn then + if on_spawn and mob then on_spawn(mob:get_luaentity(), pos) end else @@ -4095,9 +4108,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter spawn_action(pos, node) end }) - else - minetest.register_abm({ label = name .. " spawning", nodenames = nodes, @@ -4174,8 +4185,7 @@ function mobs:register_arrow(name, def) on_activate = def.on_activate, - on_punch = def.on_punch or function( - self, hitter, tflp, tool_capabilities, dir) + on_punch = def.on_punch or function(self, hitter, tflp, tool_capabilities, dir) end, on_step = def.on_step or function(self, dtime) @@ -4220,8 +4230,7 @@ function mobs:register_arrow(name, def) self.lastpos = (self.lastpos or pos) - minetest.add_item(self.lastpos, - self.object:get_luaentity().name) + minetest.add_item(self.lastpos, self.object:get_luaentity().name) end self.object:remove() ; -- print("hit node") @@ -4232,8 +4241,7 @@ function mobs:register_arrow(name, def) if self.hit_player or self.hit_mob or self.hit_object then - for _,player in pairs( - minetest.get_objects_inside_radius(pos, 1.0)) do + for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.0)) do if self.hit_player and player:is_player() then @@ -4254,7 +4262,7 @@ function mobs:register_arrow(name, def) self:hit_mob(player) - self.object:remove() ; --print("hit mob") + self.object:remove() ; -- print("hit mob") return end @@ -4280,14 +4288,14 @@ function mobs:register_arrow(name, def) end --- compatibility function +-- compatibility function (deprecated) function mobs:explosion(pos, radius) - mobs:boom({sounds = {explode = "tnt_explode"}}, pos, radius) + mobs:boom({sounds = {explode = "tnt_explode"}}, pos, radius, radius, "tnt_smoke.png") end -- no damage to nodes explosion -function mobs:safe_boom(self, pos, radius) +function mobs:safe_boom(self, pos, radius, texture) minetest.sound_play(self.sounds and self.sounds.explode or "tnt_explode", { pos = pos, @@ -4297,12 +4305,12 @@ function mobs:safe_boom(self, pos, radius) entity_physics(pos, radius) - effect(pos, 32, "tnt_smoke.png", radius * 3, radius * 5, radius, 1, 0) + effect(pos, 32, texture, radius * 3, radius * 5, radius, 1, 0) end -- make explosion with protection and tnt mod check -function mobs:boom(self, pos, radius) +function mobs:boom(self, pos, radius, damage_radius, texture) if mobs_griefing and minetest.get_modpath("tnt") and tnt and tnt.boom @@ -4310,12 +4318,13 @@ function mobs:boom(self, pos, radius) tnt.boom(pos, { radius = radius, - damage_radius = radius, + damage_radius = damage_radius, sound = self.sounds and self.sounds.explode, - explode_center = true + explode_center = true, + tiles = {(texture or "tnt_smoke.png")} }) else - mobs:safe_boom(self, pos, radius) + mobs:safe_boom(self, pos, radius, texture) end end @@ -4341,7 +4350,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) "^[mask:mobs_chicken_egg_overlay.png)" end - -- register new spawn egg containing mob information + -- register new spawn egg containing mob information (cannot be stacked) minetest.register_craftitem(mob .. "_set", { description = S("@1 (Tamed)", desc), @@ -4389,7 +4398,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) end return itemstack - end, + end }) @@ -4414,8 +4423,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) pointed_thing.under, under, placer, itemstack, pointed_thing) end - if pos - and not minetest.is_protected(pos, placer:get_player_name()) then + if pos and not minetest.is_protected(pos, placer:get_player_name()) then if not minetest.registered_entities[mob] then return @@ -4438,8 +4446,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) if not ent then return end -- sanity check -- don't set owner if monster or sneak pressed - if ent.type ~= "monster" - and not placer:get_player_control().sneak then + if ent.type ~= "monster" and not placer:get_player_control().sneak then ent.owner = placer:get_player_name() ent.tamed = true end @@ -4451,7 +4458,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) end return itemstack - end, + end }) end @@ -4462,20 +4469,7 @@ function mobs:force_capture(self, clicker) -- add special mob egg with all mob information local new_stack = ItemStack(self.name .. "_set") - local tmp, t = {} - - for _,stat in pairs(self) do - - t = type(stat) - - if t ~= "function" - and t ~= "nil" - and t ~= "userdata" then - tmp[_] = self[_] - end - end - - local data_str = minetest.serialize(tmp) + local data_str = minetest.serialize(clean_staticdata(self)) new_stack:set_metadata(data_str) @@ -4494,12 +4488,10 @@ end -- capture critter (thanks to blert2112 for idea) -function mobs:capture_mob(self, clicker, chance_hand, chance_net, - chance_lasso, force_take, replacewith) +function mobs:capture_mob( + self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith) - if not self - or not clicker:is_player() - or not clicker:get_inventory() then + if not self or not clicker:is_player() or not clicker:get_inventory() then return false end @@ -4576,20 +4568,7 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, new_stack = ItemStack(mobname .. "_set") - local tmp, t = {} - - for _,stat in pairs(self) do - - t = type(stat) - - if t ~= "function" - and t ~= "nil" - and t ~= "userdata" then - tmp[_] = self[_] - end - end - - local data_str = minetest.serialize(tmp) + local data_str = minetest.serialize(clean_staticdata(self)) new_stack:set_metadata(data_str) end @@ -4634,8 +4613,7 @@ function mobs:protect(self, clicker) local tool = clicker:get_wielded_item() local tool_name = tool:get_name() - if tool_name ~= "mobs:protector" - and tool_name ~= "mobs:protector2" then + if tool_name ~= "mobs:protector" and tool_name ~= "mobs:protector2" then return false end @@ -4681,8 +4659,7 @@ local mob_sta = {} function mobs:feed_tame(self, clicker, feed_count, breed, tame) -- can eat/tame with item in hand - if self.follow - and self:follow_holding(clicker) then + if self.follow and self:follow_holding(clicker) then -- if not in creative then take item if not mobs.is_creative(clicker:get_player_name()) then @@ -4802,14 +4779,11 @@ end minetest.register_on_player_receive_fields(function(player, formname, fields) -- right-clicked with nametag and name entered? - if formname == "mobs_nametag" - and fields.name - and fields.name ~= "" then + if formname == "mobs_nametag" and fields.name and fields.name ~= "" then local name = player:get_player_name() - if not mob_obj[name] - or not mob_obj[name].object then + if not mob_obj[name] or not mob_obj[name].object then return end @@ -4872,7 +4846,7 @@ function mobs:alias_mob(old_name, new_name) end, get_staticdata = function(self) - return self + return minetest.serialize(clean_staticdata(self)) end }) end @@ -4893,7 +4867,6 @@ minetest.register_chatcommand("clear_mobs", { if player then local pos = player:get_pos() - local objs = minetest.get_objects_inside_radius(pos, 28) for _, obj in pairs(objs) do diff --git a/api.txt b/api.txt index 30bb2a3..cc6514a 100644 --- a/api.txt +++ b/api.txt @@ -6,6 +6,17 @@ Welcome to the world of mobs in minetest and hopefully an easy guide to defining your own mobs and having them appear in your worlds. +Quick Note +---------- + +Since the mobs redo api checks for nodes around the mob to function, it relies on a +default node incase anything goes wrong, so in the default game this is default:dirt +but for any custom game please make sure the following line is registered with your +preferred dirt node of choice: + +minetest.register_alias("mapgen_dirt", "mymod:my_dirt_node") + + Registering Mobs ---------------- @@ -60,6 +71,7 @@ functions needed for the mob to work properly which contains the following: mob when melee attacking. 'damage_group' group in which damage is dealt, dedaults to "fleshy". 'damage_texture_modifier' applies texture modifier on hit e.g "^[brighten" + or default when enabled is "^[colorize:#c9900070". 'knock_back' when true has mobs falling backwards when hit, the greater the damage the more they move back. 'fear_height' is how high a cliff or edge has to be before the mob stops @@ -78,6 +90,7 @@ functions needed for the mob to work properly which contains the following: level is between the min and max values below 'light_damage_min' minimum light value when mob is affected (default: 14) 'light_damage_max' maximum light value when mob is affected (default: 15) + When set to 16 then only natural light will kill mob. 'suffocation' when > 0 mobs will suffocate inside solid blocks and will be hurt by the value given every second (0 to disable). 'floats' when set to 1 mob will float in water, 0 has them sink. @@ -138,6 +151,9 @@ functions needed for the mob to work properly which contains the following: arrow/fireball appears on mob. 'specific_attack' has a table of entity names that mob can also attack e.g. {"player", "mobs_animal:chicken"}. + 'friendly_fire` when set to false, mobs will not be able to harm other + mobs of the same type with friendly fire arrows. + Defaults to true. 'runaway_from' contains a table with mob names to run away from, add "player" to list to runaway from player also. 'ignore_invisibility' When true mob will still be able to see and attack @@ -237,6 +253,9 @@ functions needed for the mob to work properly which contains the following: 'shoot_start' shooting animation. 'shoot_end' 'shoot_speed' + 'injured_start' when hit or damaged > 1 hp (if not set then 'walk' is used) + 'injured_end' + 'injured_speed' 'die_start' death animation 'die_end' 'die_speed' @@ -290,11 +309,9 @@ Custom Definition Functions Along with the above mob registry settings we can also use custom functions to enhance mob functionality and have them do many interesting things: - 'on_die' a function that is called when the mob is killed the - parameters are (self, pos) 'on_rightclick' its same as in minetest.register_entity() 'on_blast' is called when an explosion happens near mob when using TNT - functions, parameters are (object, damage) and returns + functions, parameters are (damage) and returns (do_damage, do_knockback, drops) 'on_spawn' is a custom function that runs on mob spawn with 'self' as variable, return true at end of function to run only once. @@ -335,6 +352,8 @@ for each mob. 'self.child_texture' contains mob child texture when growing up 'self.base_texture' contains current skin texture which was randomly selected from textures list + 'self.texture_mods' contains a list of textures to overlay above the mobs + base texture (used for horse saddle) 'self.gotten' this is used for obtaining milk from cow and wool from sheep 'self.horny' when animal fed enough it is set to true and animal can @@ -348,6 +367,10 @@ for each mob. 'self.order' set to "follow" or "stand" so that npc will follow owner or stand it's ground 'self.nametag' contains the name of the mob which it can show above + 'self.pause_timer' used to stop mob thinking when punched so that knockback + can take effect. + 'self.disable_falling' currently used on spider mob when climbing walls, stops + the mob from experiencing gravity when true. 'self.state' Current mob state. "stand": no movement (except turning around) "walk": walk or move around aimlessly @@ -356,6 +379,12 @@ for each mob. "flop": bounce around aimlessly (for swimming mobs that have stranded) "die": during death + 'self.standing_on' Node name mob is standing on. + 'self.standing_in' Node name mob is standing inside. + 'self.looking_at' Node name in front of mob. + 'self.looking_above'Node name in front/above mob. + 'self.facing_fence' True if mob facing node containing "wall", "fence", "gate" + in it's name. Adding Mobs in World @@ -526,10 +555,12 @@ Explosion Function mobs:explosion(pos, radius) -- DEPRECATED!!! use mobs:boom() instead -mobs:boom(self, pos, radius) +mobs:boom(self, pos, radius, damage_radius, texture) 'self' mob entity 'pos' centre position of explosion 'radius' radius of explosion (typically set to 3) + 'damage_radius' radius of damage around explosion + 'texture' particle texture during explosion, defaults to "tnt_smoke.png" This function generates an explosion which removes nodes in a specific radius and damages any entity caught inside the blast radius. Protection will limit @@ -702,14 +733,29 @@ This function returns true if the node name given is harmful to the mob (mob_obj it is mainly used when a mob is near a node it has to avoid. +Looting Level +------------- + +If a tool is used with 'looting_level' defined under tool_capabilities then mobs can drop +extra items per level up to a maximum of 3 levels. 'looting_level' can also be read from +the tools own meta to override the default. + + External Settings for "minetest.conf" ------------------------------------ + 'mob_node_timer_interval' How often mobs get nodes around them (0.25 is default) + for every 1/4 second. + 'mob_main_timer_interval' How often mobs run main functions (1.0 is default) for + every one second. 'enable_damage' if true monsters will attack players (default is true) 'only_peaceful_mobs' if true only animals will spawn in game (default is false) + 'mobs_attack_creatura' When True mobs redo mobs will attack Creatura mod mobs. 'mobs_disable_blood' if false blood effects appear when mob is hit (default is false) + 'mob_hit_effect' False by default, when True and mobs are hit then + damage_texture_modifier is used to highlight mob. 'mobs_spawn_protected' if set to false then mobs will not spawn in protected areas (default is true) 'mobs_spawn_monster_protected' if set to false then monsters will not spawn in @@ -720,8 +766,6 @@ External Settings for "minetest.conf" spawn number e.g. mobs_animal:cow = 1000,5 'mob_difficulty' sets difficulty level (health and hit damage multiplied by this number), defaults to 1.0. - 'mob_show_health' if false then punching mob will not show health status - (true by default) 'mob_chance_multiplier' multiplies chance of all mobs spawning and can be set to 0.5 to have mobs spawn more or 2.0 to spawn less. e.g. 1 in 7000 * 0.5 = 1 in 3500 so better odds of @@ -738,6 +782,17 @@ External Settings for "minetest.conf" mob for obstructions before spawning, otherwise it defaults to checking the height of the mob only. 'mob_smooth_rotate' Enables smooth rotation when mobs turn by default. + 'mob_height_fix' Enabled by default, increases smaller mob heights so they wont + glitch through certain nodes. + 'mob_pathfinding_enable' Enable pathfinding. + 'mob_pathfinder_enable' Use pathfinder mod if available. + 'mob_pathfinding_stuck_timeout' How long before stuck mobs start searching. (default 3.0) + 'mob_pathfinding_stuck_path_timeout' How long will mob follow path before giving up. (default 5.0) + 'mob_pathfinding_algorithm' Which pathfinding algorithm to use Dijkstra (default), A*_noprefetch (AStar_noprefetch) or A* (AStar) + (A* names differ cause Minetest doesn´t allow "*" in settings) + 'mob_pathfinding_searchdistance' max search distance from search positions (default 16) + 'mob_pathfinding_max_jump' max jump height for pathfinding (default 4) + 'mob_pathfinding_max_drop' max drop height for pathfinding (default 6) Players can override the spawn chance for each mob registered by adding a line to their minetest.conf file with a new value, the lower the value the more each diff --git a/crafts.lua b/crafts.lua index a28af9b..aa8edca 100644 --- a/crafts.lua +++ b/crafts.lua @@ -53,6 +53,7 @@ minetest.register_tool("mobs:lasso", { }) if minetest.get_modpath("farming") then + minetest.register_craft({ output = "mobs:lasso", recipe = { @@ -73,6 +74,7 @@ minetest.register_tool("mobs:net", { }) if minetest.get_modpath("farming") then + minetest.register_craft({ output = "mobs:net", recipe = { @@ -148,7 +150,9 @@ minetest.register_craft({ -- make sure we can register fences -if minetest.get_modpath("default") and default.register_fence then +local mod_def = minetest.get_modpath("default") + +if mod_def and default.register_fence then -- mob fence (looks like normal fence but collision is 2 high) default.register_fence("mobs:fence_wood", { @@ -156,7 +160,7 @@ default.register_fence("mobs:fence_wood", { texture = "default_wood.png", material = "default:fence_wood", groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, - sounds = default.node_sound_wood_defaults(), + sounds = mod_def and default.node_sound_wood_defaults(), collision_box = { type = "fixed", fixed = { @@ -174,7 +178,7 @@ minetest.register_node("mobs:fence_top", { paramtype = "light", is_ground_content = false, groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, - sounds = default.node_sound_wood_defaults(), + sounds = mod_def and default.node_sound_wood_defaults(), node_box = { type = "fixed", fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} @@ -244,6 +248,7 @@ minetest.register_craft({ -- this tool spawns same mob and adds owner, protected, nametag info -- then removes original entity, this is used for fixing any issues. +-- also holding sneak while punching mob lets you change texture name. local tex_obj @@ -353,23 +358,49 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end) --- Meat Block (thanks to painterlypack.net for allowing me to use these textures) +-- Meat Block minetest.register_node("mobs:meatblock", { description = S("Meat Block"), tiles = {"mobs_meat_top.png", "mobs_meat_bottom.png", "mobs_meat_side.png"}, paramtype2 = "facedir", groups = {choppy = 1, oddly_breakable_by_hand = 1, flammable = 2}, - sounds = default and default.node_sound_leaves_defaults(), + sounds = mod_def and default.node_sound_leaves_defaults(), on_place = minetest.rotate_node, on_use = minetest.item_eat(20) }) minetest.register_craft({ output = "mobs:meatblock", --- type = "shapeless", recipe = { {"group:food_meat", "group:food_meat", "group:food_meat"}, {"group:food_meat", "group:food_meat", "group:food_meat"}, {"group:food_meat", "group:food_meat", "group:food_meat"} } }) + +-- Meat Block (raw) +minetest.register_node("mobs:meatblock_raw", { + description = S("Raw Meat Block"), + tiles = {"mobs_meat_raw_top.png", "mobs_meat_raw_bottom.png", "mobs_meat_raw_side.png"}, + paramtype2 = "facedir", + groups = {choppy = 1, oddly_breakable_by_hand = 1, flammable = 2}, + sounds = mod_def and default.node_sound_leaves_defaults(), + on_place = minetest.rotate_node, + on_use = minetest.item_eat(20) +}) + +minetest.register_craft({ + output = "mobs:meatblock_raw", + recipe = { + {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"}, + {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"}, + {"group:food_meat_raw", "group:food_meat_raw", "group:food_meat_raw"} + } +}) + +minetest.register_craft({ + type = "cooking", + output = "mobs:meatblock", + recipe = "mobs:meatblock_raw", + cooktime = 30 +}) diff --git a/depends.txt b/depends.txt index 94516a7..ed62468 100644 --- a/depends.txt +++ b/depends.txt @@ -8,3 +8,4 @@ lucky_block? cmi? toolranks? pathfinder? +player_api? diff --git a/license.txt b/license.txt index fec6f6a..8bde134 100644 --- a/license.txt +++ b/license.txt @@ -19,3 +19,19 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +Textures under CC0 license by TenPlus1 + + +ShadowNinja (CC BY-SA 3.0): + tnt_smoke.png + +mobs_swing.ogg by qubodup (CC0) + - http://freesound.org/people/qubodup/sounds/60012/ + +mobs_spell.ogg by littlerobotsoundfactory (CC0) + - http://freesound.org/people/LittleRobotSoundFactory/sounds/270396/ + +mobs_punch.ogg by Merrick079 (CC0) + - https://freesound.org/people/Merrick079/sounds/566436/ diff --git a/mount.lua b/mount.lua index fe917a9..88cbcd0 100644 --- a/mount.lua +++ b/mount.lua @@ -492,6 +492,7 @@ function mobs.fly(entity, _, speed, shoots, arrow, moving_anim, stand_anim) ent.switch = 1 -- for mob specific arrows ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding + local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6} yaw = entity.driver:get_look_horizontal() diff --git a/readme.MD b/readme.MD index 36fe019..5366da4 100644 --- a/readme.MD +++ b/readme.MD @@ -1,98 +1,415 @@ - MOBS REDO for MINETEST ====================== -Built from PilzAdam's original Simple Mobs with additional mobs by KrupnoPavel, Zeg9, ExeterDad and AspireMint. +This mod contains the API only for adding your own mobs into the world, so +please use the additional modpacks to add animals, monsters, and npcs. +https://forum.minetest.net/viewtopic.php?f=11&t=9917 Information ----------- -This mod contains the API only for adding your own mobs into the world, so please use the additional modpacks to add animals, monsters etc. +Built from PilzAdam's original Simple Mobs with additional mobs by KrupnoPavel, +Zeg9, ExeterDad and AspireMint. + +## Crafts + +- **Nametag**. Can be crafted by paper, black dye, and string. Can be used + to right-click on a tamed mob to give them a name. +- **Net**. Used to right-click tamed mobs to pick them up and place inside + inventory as a spawn egg. +- **Magic lasso**. Similar to nets but with a better chance of picking up + larger mobs. +- **Shears**. Used to right-click sheep and return 1-3 wool. +- **Protection Rune**. Protects tamed mobs from being harmed by other players. +- **Mob Fence and Fence Top**. Stops mobs escaping or glitching throughfences. + +**Lucky Blocks**: 12 + +## Changelog + +### Version 1.57 + +* Added 'injured' animation when mob hurt +* Fixed yaw clamping to stop spinning mobs +* Added 'mob_node_timer_interval' and 'mob_main_timer_interval' settings +* Added ability for mobs to die only in natural daylight +* Refactored do_jump and added get_nodes function +* Many bug fixes and tweaks to improve performance +* Added 'mobs_attack_creatura' setting so that monsters can attack Creatura mobs + +### Version 1.56 + +* Added `arrow_override` function to mob definition to tweak arrow entity settings +* Added injured animation and mob hit effect +* Tamed monsters no longer despawn when outside loaded map area +* `looting_level` can be read from tool definition or tool meta to add extra + drops when mob killed + +### Version 1.55 + +* Added `peaceful_player` privilege and setting so mobs don't attack specific + players (thanks sfence) +* Added support for MarkBu's `pathfinder` mod, remove need for default mod + +### Version 1.54 + +* **New support for swimming mobs** + - `on_flop` (for mobs not in water) + - `air_damage` added +* Added editable settings (thanks Wuzzy) +* Simplified animal breeding function +* Child mobs now take twenty minutes to grow up +* Reverted to simple mob spawning with setting to use area checks + +### Version 1.53 + +* Added `on_map_load` settings to `mobs:spawn` so that mobs will only spawn + when new areas of map are loaded. + +### Version 1.52 + +* Added `mob_active_limit` in settings to set number of mobs in game. The + default is 0, for unlimited mobs. +* Removed `{immortal}` from mob armor +* Fluid viscocity slows mobs (for example, water) + +### Version 1.51 + +* Added node checks for dangerous nodes +* Add `mob_nospawn_range` setting +* Jumping and falling tweaks +* Spawn area check (thanks for idea wuzzy) +* Re-enabled mob suffocation + +### Version 1.50 + +* Added new `line_of_sight` function that uses raycasting if Minetest 5.0 is + found, (thanks Astrobe) +* Added Chinese local +* Removed ability to spawn mobs if world anchor nearby (`technic` or + `simple_anchor` mods) + +### Version 1.49 + +* Added `mobs:force_capture(self, player)` function +* API functions now use metatables thanks to bell07 + +### Version 1.48 + +* Added `mobs:set_velocity(self, velocity)` global function + +### Version 1.47 + +* Added minimum and maximum light level for damage +* Mob damage changes +* Ignition sources checked for lava damage + +### Version 1.46 + +* Mobs only drop rare items when killed by player. You can make change the + drops to rare items by using `drops.min = 0` +* Pathfinding no longer sees through walkable nodes + +### Version 1.45 + +* Added fence top to add on top of any fence to stop mobs escaping +* New `line_of_sight` tweaked by `Astrobe` + +### Version 1.44 + +* Added `ToolRanks` support for swords when attacking mobs + +### Version 1.43 + +* Added general attack function and settings +* Better Minetest 0.4.16 compatibility + +### Version 1.42 + +* Added `"all"` option to `immune_to` definition table +* Tidied floating mobs to be less intensive + +### Version 1.41 + +* Mob pathfinding has been updated thanks to `Elkien3` + +### Version 1.40 + +* Updated to use newer functions, requires Minetest 0.4.16+ to work + +### Version 1.39 + +* **New custom functions**: + - `on_breed` (called when mobs have just been bred) + - `on_grown` (called when baby mobs have grown up) + - `do_punch` (called when the mob has been punched or damaged by another mob) + +### Version 1.38 + +* Better entity checking +* Nametag setting +* `on_spawn` function added to mob registry +* Tweaked light damage + +### Version 1.37 + +* Added support for `Raymoo`'s CMI (common mob interface) mod. See + https://forum.minetest.net/viewtopic.php?f=9&t=15448 for details + +### Version 1.36 + +* Added death check. If the mob dies in fire/lava/with lava pick, then drops + are cooked + +### Version 1.35 + +* Added `owner_loyal` flag for owned mobs to attack player enemies +* Fixed `group_attack` + +### Version 1.34 + +* Added function to fly mob using directional movement (thanks D00Med for + flying code) + +### Version 1.33 + +* Added functions to mount ride mobs: + - `mobs.attach` + - `mobs.detach` + - `mobs.drive`. Many thanks to `Blert2112` + +### Version 1.32 + +* Added new spawn check to count specific mobs AND new `minetest.conf` setting + to chance spawn chance and numbers +* Added ability to protect tamed mobs + +### Version 1.31 + +* Added `attack_animals` and `specific_attack` flags for custom monster + attacks +* Added 'mob_difficulty' .conf setting to make mobs harder + +### Version 1.30 + +* Added support for `invisibility` mod +* Tweaked and tidied code + +### Version 1.29 + +* Split original Mobs Redo into a modpack to make it easier to disable mob sets + (animal, monster, npc) or simply use the API itself for your own mod + +### Version 1.28 + +* Added new damage system with ability for mob to be immune to weapons or + healed by them :) + +### Version 1.27 + +* Added new sheep, lava flan and spawn egg textures +* New Lava Pick tool smelts what you dig +* New `atan` checking function + +### Version 1.26 + +* Pathfinding feature added thanks to rnd +* When monsters attack they become scary smart in finding you :) +* Beehive produces honey now :) + +### Version 1.25 + +* Mobs no longer spawn within 12 blocks of player or despawn within same + range +* Spawners now have player detection +* Tidy and tweak code + +### Version 1.24 + +* Added feature where certain animals run away when punched + (`runaway = true` in mob definition) + +### Version 1.23 + +* Added mob spawner block for admin to setup spawners in-game (place and + right-click to enter settings) + +### Version 1.22 + +* Added ability to name tamed animals and NPCs using nametags +* NPCs will attack anyone who punches them apart from owner + +### Version 1.21 + +* Added some more error checking to reduce `serialize.h` error and added height + checks for falling off cliffs (thanks `cmdskp`) + +### Version 1.20 + +* Error checking added to remove bad mobs +* Out of map limit mobs and stop `serialize.h` error + +### Version 1.19 + +* Chickens now drop egg items instead of placing the egg +* Throwing eggs result in ⅛ chance of spawning chick + +### Version 1.18 + +* Added `docile_by_day` flag so that monsters will not attack automatically + during daylight hours unless hit first + +### Version 1.17 + +* Added `dogshoot` attack type. Mobs now shoot when out of reach +* Melee attack when in reach, also API tweaks and `self.reach` added + +### Version 1.16 + +* Mobs follow multiple items now +* NPCs can now breed + +### Version 1.15 + +* Added feeding, taming, and breeding function +* Right-click to pick up any sheep with X mark on them and replace with new one + to fix compatibility. + +### Version 1.14 + +* All variables saved in staticdata +* Fixed health bug + +### Version 1.13 + +* Added capture function (thanks `blert2112`) chance of picking up mob with a + hand, a net, or a magic lasso +* Replaced some `.x` models with newer `.b3d` ones + +### Version 1.12 + +* Added animal ownership so that players cannot steal your tamed animals + +### Version 1.11 + +* Added flying and swimming mobs +* `fly=true` and `fly_in="air"` or `"default:water_source"` for fishy + +### Version 1.10 + +* Added explosion routine for exploding mob +* Footstep removed (use replace) + +### Version 1.09 -https://forum.minetest.net/viewtopic.php?f=11&t=9917 +* Added mob rotation value +* Added footstep feature +* Added jumping mobs with sounds feature +* Aadded magic lasso for picking up animals +* Reworked breeding routine +### Version 1.08 -### Crafts: +* Added drops that appear when mob is killed +* New custom function: `on_die` function +* Mob throwing attack has been rehauled so that they can damage one another, - - Nametag (paper, black dye, string) can be used right-click on a tamed mob to give them a name. - - Nets can be used to right-click tamed mobs to pick them up and place inside inventory as a spawn egg. - - Magic Lasso is similar to nets but with a better chance of picking up larger mobs. - - Shears are used to right-click sheep and return 1-3 wool. - - Protection Rune lets you protect tamed mobs from harm by other players - - Mob Fence and Fence Top (to stop mobs escaping/glitching through fences) +### Version 1.07 -Lucky Blocks: 9 +* NPCs can now be set to follow player or stand by using `order` and `owner` + variables +* BETA: Npc mob added. They kill monsters (maybe as guards) and attack players + when punched by them. Right-clicking them with food will heal them, and + giving them gold lump will make them drop a random item. -## Changelog: +### Version 1.06 + +* Changed recovery times after breeding. Time taken to grow up can be sped up + by feeding the baby animal. + +### Version 1.05 + +* Added `ExeterDad`'s bunniess which can be picked up and tamed with four carrots from `farming_redo` or `farming_plus` +* Added shears to get wool from sheep +* Added Jordach/BSD's kitten + +### Version 1.04 + +* Added mating for sheep, cows and hogs +* Added feature to feed animals to make horny and hope for a baby which is half + size, they will grow up quick though :) + +### Version 1.03 + +* Added mob drop/replace feature so that chickens can drop eggs and cow/sheep + can eat grass/wheat etc. + +### Version 1.02 + +* Sheared sheep are remembered and spawn shaven +* Warthogs will attack when threatened +* API additions + +### Version 1.01 + +* Mobs that suffer fall damage or die in water/lava/sunlight will now drop + items + +### Version 1.0 + +* More work on API so that certain mobs can float in water while some sink like + a brick :) + +### Version 0.9 + +* Spawn eggs added for all mobs (admin only, cannot be placed in protected + areas) +* Tweaked API + +### Version 0.8 + +* Added sounds to monster mobs (thanks `Cyberpangolin` for the `sfx`) +* Added chicken sound +### Version 0.7 + +* `mobs.protected` switch added to `api.lua`. When set to 1 mobs no longer + spawn in protected areas +* Minor bugfixes + +### Version 0.6 + +* API now supports multi-textured mobs, e.g oerkki, dungeon master, rats and + chickens have random skins when spawning (sheep fix TODO) +* Added new Honey block + +### Version 0.5 + +* Mobs now float in water, die from falling +* Minor code improvements + +### Version 0.4 + +* Added new sheep sound :) +* Dungeon Masters and Mese Monsters have much better aim due to `shoot_offset` +* They can both shoot through nodes that aren't walkable (flowers, grass, etc.) + +### Version 0.3 + +* Added `LOTT`'s Spider mob +* Added Cobwebs +* Added KPavel's Bee with Honey and Beehives (made texture) +* Warthogs now have sound and can be tamed +* Taming of shaved sheep or milked cow with 8 wheat so it will not despawn +* Multiple bug fixes :) + +### Version 0.2 + +* Cooking bucket of milk into cheese now returns empty bucket + +### Version 0.1 + +- Initial Release -- 1.56 - Added arrow_override function to mob definition to tweak arrow entity settings, tamed monsters no longer despawn when outside loaded map area. -- 1.55 - Add 'peaceful_player' privelage and setting so mobs don't attack specific players (thanks sfence), add support for MarkBu's pathfinder mod, remove need for default mod -- 1.54 - Simplified animal breeding function, added editable settings (thanks Wuzzy), Child mobs now take 20 mins to grow up, reverted to simple mob spawning with setting to use area checks, on_flop added, air_damage added. -- 1.53 - Added 'on_map_load' settings to mobs:spawn so that mobs will only spawn when new areas of map are loaded. -- 1.52 - Added 'mob_active_limit' in settings to set number of mobs in game, -(default is 0 for unlimited), removed {immortal} from mob armor, fluid viscocity slows mobs -- 1.51 - Added some node checks for dangerous nodes, jumping and falling tweaks, spawn area check (thx for idea wuzzy), re-enabled mob suffocation, add 'mob_nospawn_range' setting -- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found, (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods), chinese local added -- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07 -- 1.48- Add mobs:set_velocity(self, velocity) global function -- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage -- 1.46- Mobs only drop rare items when killed by player (drops.min = 0 makes them rare), code tweak, pathfinding no longer sees through walkable nodes -- 1.45- Added Fence Top to add on top of any fence to stop mobs escaping, new line_of_sight tweaked by Astrobe -- 1.44- Added ToolRanks support for swords when attacking mobs -- 1.43- Better 0.4.16 compatibility, added general attack function and settings -- 1.42- Added "all" option to immune_to table, tidied floating mobs to be less intensive -- 1.41- Mob pathfinding has been updated thanks to Elkien3 -- 1.40- Updated to use newer functions, requires Minetest 0.4.16+ to work. -- 1.39- Added 'on_breed', 'on_grown' and 'do_punch' custom functions per mob -- 1.38- Better entity checking, nametag setting and on_spawn function added to mob registry, tweaked light damage -- 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448 -- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked -- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack -- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code) -- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112 -- 1.32- Added new spawn check to count specific mobs AND new minetest.conf setting to chance spawn chance and numbers, added ability to protect tamed mobs -- 1.31- Added 'attack_animals' and 'specific_attack' flags for custom monster attacks, also 'mob_difficulty' .conf setting to make mobs harder. -- 1.30- Added support for invisibility mod (mobs cant attack what they cant see), tweaked and tidied code -- 1.29- Split original Mobs Redo into a modpack to make it easier to disable mob sets (animal, monster, npc) or simply use the Api itself for your own mod -- 1.28- New damage system added with ability for mob to be immune to weapons or healed by them :) -- 1.27- Added new sheep, lava flan and spawn egg textures. New Lava Pick tool smelts what you dig. New atan checking function. -- 1.26- Pathfinding feature added thanks to rnd, when monsters attack they become scary smart in finding you :) also, beehive produces honey now :) -- 1.25- Mobs no longer spawn within 12 blocks of player or despawn within same range, spawners now have player detection, Code tidy and tweak. -- 1.24- Added feature where certain animals run away when punched (runaway = true in mob definition) -- 1.23- Added mob spawner block for admin to setup spawners in-game (place and right click to enter settings) -- 1.22- Added ability to name tamed animals and npc using nametags, also npc will attack anyone who punches them apart from owner -- 1.21- Added some more error checking to reduce serialize.h error and added height checks for falling off cliffs (thanks cmdskp) -- 1.20- Error checking added to remove bad mobs, out of map limit mobs and stop serialize.h error -- 1.19- Chickens now drop egg items instead of placing the egg, also throwing eggs result in 1/8 chance of spawning chick -- 1.18- Added docile_by_day flag so that monsters will not attack automatically during daylight hours unless hit first -- 1.17- Added 'dogshoot' attack type, shoots when out of reach, melee attack when in reach, also api tweaks and self.reach added -- 1.16- Mobs follow multiple items now, Npc's can breed -- 1.15- Added Feeding/Taming/Breeding function, right-click to pick up any sheep with X mark on them and replace with new one to fix compatibility. -- 1.14- All .self variables saved in staticdata, Fixed self.health bug -- 1.13- Added capture function (thanks blert2112) chance of picking up mob with hand; net; magic lasso, replaced some .x models with newer .b3d one's -- 1.12- Added animal ownership so that players cannot steal your tamed animals -- 1.11- Added flying mobs (and swimming), fly=true and fly_in="air" or "deafult:water_source" for fishy -- 1,10- Footstep removed (use replace), explosion routine added for exploding mobs. -- 1.09- reworked breeding routine, added mob rotation value, added footstep feature, added jumping mobs with sounds feature, added magic lasso for picking up animals -- 1.08- Mob throwing attack has been rehauled so that they can damage one another, also drops and on_die function added -- 1.07- Npc's can now be set to follow player or stand by using self.order and self.owner variables -- beta- Npc mob added, kills monsters, attacks player when punched, right click with food to heal or gold lump for drop -- 1.06- Changed recovery times after breeding, and time taken to grow up (can be sped up by feeding baby animal) -- 1.05- Added ExeterDad's bunny's which can be picked up and tamed with 4 carrots from farming redo or farming_plus, also shears added to get wool from sheep and lastly Jordach/BSD's kitten -- 1.04- Added mating for sheep, cows and hogs... feed animals to make horny and hope for a baby which is half size, will grow up quick though :) -- 1.03- Added mob drop/replace feature so that chickens can drop eggs, cow/sheep can eat grass/wheat etc. -- 1.02- Sheared sheep are remembered and spawn shaven, Warthogs will attack when threatened, Api additions -- 1.01- Mobs that suffer fall damage or die in water/lava/sunlight will now drop items -- 1.0 - more work on Api so that certain mobs can float in water while some sink like a brick :) -- 0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked -- 0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound -- 0.7 - mobs.protected switch added to api.lua, when set to 1 mobs no longer spawn in protected areas, also bug fixes -- 0.6 - Api now supports multi-textured mobs, e.g oerkki, dungeon master, rats and chickens have random skins when spawning (sheep fix TODO), also new Honey block -- 0.5 - Mobs now float in water, die from falling, and some code improvements -- 0.4 - Dungeon Masters and Mese Monsters have much better aim due to shoot_offset, also they can both shoot through nodes that aren't walkable (flowers, grass etc) plus new sheep sound :) -- 0.3 - Added LOTT's Spider mob, made Cobwebs, added KPavel's Bee with Honey and Beehives (made texture), Warthogs now have sound and can be tamed, taming of shaved sheep or milked cow with 8 wheat so it will not despawn, many bug fixes :) -- 0.2 - Cooking bucket of milk into cheese now returns empty bucket -- 0.1 - Initial Release diff --git a/settingtypes.txt b/settingtypes.txt index dae580d..18db2bf 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,3 +1,12 @@ +# Enable setting so that Mobs Redo mobs can attack Creatura mobs +mobs_attack_creatura (Attack Creatura Mobs) bool false + +# How often mobs get nodes around them (default is 0.25, 1/4 second) +mob_node_timer_interval (Mob Node Timer Interval) float 0.25 + +# How often mobs run main functions (default is 1.00, 1 second) +mob_main_timer_interval (Mob Node Timer Interval) float 1.00 + # If false then mobs no longer spawn in world without spawner or spawn egg mobs_spawn (Spawn Mobs) bool true @@ -7,6 +16,9 @@ only_peaceful_mobs (Only spawn peaceful Mobs) bool false # If enabled then punching mobs no longer shows blood effects mobs_disable_blood (Disable Mob blood) bool false +# If enabled the mobs will be highlighted when hit +mob_hit_effect (Highlight Mob when Hit) bool false + # If disabled then Mobs no longer destroy world blocks mobs_griefing (Griefing Mobs) bool true @@ -22,9 +34,6 @@ remove_far_mobs (Remove far Mobs) bool true # Sets Mob difficulty level by multiplying punch damage mob_difficulty (Mob difficulty) float 1.0 -# If disabled health status no longer appears above Mob when punched -mob_show_health (Show Mob health) bool true - # Contains a value used to multiply Mob spawn values mob_chance_multiplier (Mob chance multiplier) float 1.0 @@ -45,3 +54,28 @@ enable_peaceful_player (Mobs do not attack peaceful player without reason) bool # Enable mobs smooth rotation mob_smooth_rotate (Smooth rotation for mobs) bool true + +# Fix Mob Height if too low so they cannot escape through specific nodes +mob_height_fix (Fix Mob Height) bool true + +[Pathfinding] +# Enable pathfinding (default Enabled) +mob_pathfinding_enable (Enable pathfinding) bool true +# Use pathfinder mod if available (default Enabled) +mob_pathfinder_enable (Use pathfinder mod if available) bool true +# How long before stuck mobs starts searching (default 3.0) +mob_pathfinding_stuck_timeout (How long before stuck mobs start searching) float 3.0 +# How long will mob follow path before giving up (default 5.0) +mob_pathfinding_stuck_path_timeout (How long will mob follow path before giving up) float 5.0 +# Which pathfinding algorithm to use +# - Dijkstra (default) +# - A*_noprefetch (AStar_noprefetch) +# - A* (AStar) +# (A* names differ cause Minetest doesn´t allow "*" in settings) +mob_pathfinding_algorithm (pathfinding algorithm) enum Dijkstra Dijkstra,AStar_noprefetch,AStar +# max search distance from search positions (default 16) +mob_pathfinding_searchdistance (path search distance) int 16 +# max jump height for pathfinding (default 4) +mob_pathfinding_max_jump (path max jump height) int 4 +# max drop height for pathfinding (default 6) +mob_pathfinding_max_drop (path max drop height) int 6 diff --git a/sounds/default_punch.ogg b/sounds/default_punch.ogg deleted file mode 100644 index 28a500b..0000000 Binary files a/sounds/default_punch.ogg and /dev/null differ diff --git a/sounds/license.txt b/sounds/license.txt deleted file mode 100644 index 3b160fe..0000000 --- a/sounds/license.txt +++ /dev/null @@ -1,7 +0,0 @@ -Creative Commons sounds from Freesound.org - -mobs_swing.ogg by qubodup - - http://freesound.org/people/qubodup/sounds/60012/ - -mobs_spell.ogg by littlerobotsoundfactory - - http://freesound.org/people/LittleRobotSoundFactory/sounds/270396/ diff --git a/sounds/mobs_punch.ogg b/sounds/mobs_punch.ogg new file mode 100644 index 0000000..86cabff Binary files /dev/null and b/sounds/mobs_punch.ogg differ diff --git a/textures/mobs_meat_bottom.png b/textures/mobs_meat_bottom.png index 351c16f..559e6e3 100644 Binary files a/textures/mobs_meat_bottom.png and b/textures/mobs_meat_bottom.png differ diff --git a/textures/mobs_meat_raw_bottom.png b/textures/mobs_meat_raw_bottom.png new file mode 100644 index 0000000..e6ef6c5 Binary files /dev/null and b/textures/mobs_meat_raw_bottom.png differ diff --git a/textures/mobs_meat_raw_side.png b/textures/mobs_meat_raw_side.png new file mode 100644 index 0000000..4ba1ed0 Binary files /dev/null and b/textures/mobs_meat_raw_side.png differ diff --git a/textures/mobs_meat_raw_top.png b/textures/mobs_meat_raw_top.png new file mode 100644 index 0000000..1dcc6d9 Binary files /dev/null and b/textures/mobs_meat_raw_top.png differ diff --git a/textures/mobs_meat_side.png b/textures/mobs_meat_side.png index 10dac08..4a3da50 100644 Binary files a/textures/mobs_meat_side.png and b/textures/mobs_meat_side.png differ diff --git a/textures/mobs_meat_top.png b/textures/mobs_meat_top.png index 0058e6a..14116b4 100644 Binary files a/textures/mobs_meat_top.png and b/textures/mobs_meat_top.png differ