Update Mobs Redo

master
Wuzzy 2018-01-08 02:03:31 +01:00
parent a818995d2a
commit a89b9e9c45
4 changed files with 77 additions and 50 deletions

View File

@ -3,7 +3,7 @@
mobs = {}
mobs.mod = "redo"
mobs.version = "20171018"
mobs.version = "20180104"
-- Intllib
@ -61,6 +61,7 @@ local remove_far = minetest.settings:get_bool("remove_far_mobs")
local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0
local show_health = false
local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 99)
local mob_chance_multiplier = tonumber(minetest.settings:get("mob_chance_multiplier") or 1)
-- Peaceful mode message so players will know there are no monsters
if peaceful_only then
@ -88,6 +89,7 @@ local node_snowblock = "mcl_core:snowblock"
local node_snow = "mcl_core:snow"
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt"
-- play sound
local mob_sound = function(self, sound)
@ -425,7 +427,8 @@ local check_for_death = function(self, cause, cmi_cause)
self.nametag2 = self.nametag or ""
end
if show_health then
if show_health
and (cmi_cause and cmi_cause.type == "punch") then
self.htimer = 2
self.nametag = "" .. self.health .. " / " .. self.hp_max
@ -828,6 +831,7 @@ local breed = function(self)
mesh = self.base_mesh,
visual_size = self.base_size,
collisionbox = self.base_colbox,
selectionbox = self.base_selbox,
})
-- custom function when child grows up
@ -948,6 +952,14 @@ local breed = function(self)
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
@ -1078,10 +1090,10 @@ local smart_mobs = function(self, s, p, dist, dtime)
p1.y = floor(p1.y + 0.5)
p1.z = floor(p1.z + 0.5)
local dropheight = 10
local dropheight = 6
if self.fear_height ~= 0 then dropheight = self.fear_height end
-- self.path.way = minetest.find_path(s, p1, 16, 2, 6, "Dijkstra") -- "A*_noprefetch"
-- self.path.way = minetest.find_path(s, p1, 16, 2, 6, "Dijkstra")
self.path.way = minetest.find_path(s, p1, 16, self.stepheight, dropheight, "A*_noprefetch")
-- attempt to unstick mob that is "daydreaming"
@ -2423,6 +2435,7 @@ local mob_activate = function(self, staticdata, def, dtime)
self.base_mesh = def.mesh
self.base_size = self.visual_size
self.base_colbox = self.collisionbox
self.base_selbox = self.selectionbox
end
-- set texture, model and size
@ -2430,6 +2443,7 @@ local mob_activate = function(self, staticdata, def, dtime)
local mesh = self.base_mesh
local vis_size = self.base_size
local colbox = self.base_colbox
local selbox = self.base_selbox
-- specific texture if gotten
if self.gotten == true
@ -2463,6 +2477,14 @@ local mob_activate = function(self, staticdata, def, dtime)
self.base_colbox[5] * .5,
self.base_colbox[6] * .5
}
selbox = {
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
}
end
if self.health == 0 then
@ -2485,6 +2507,7 @@ local mob_activate = function(self, staticdata, def, dtime)
self.textures = textures
self.mesh = mesh
self.collisionbox = colbox
self.selectionbox = selbox
self.visual_size = vis_size
self.standing_in = ""
@ -2674,6 +2697,7 @@ minetest.register_entity(name, {
hp_max = max(1, (def.hp_max or 10) * difficulty),
physical = true,
collisionbox = def.collisionbox,
selectionbox = def.selectionbox or def.collisionbox,
visual = def.visual,
visual_size = def.visual_size or {x = 1, y = 1},
mesh = def.mesh,
@ -2832,13 +2856,14 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
nodenames = nodes,
neighbors = neighbors,
interval = interval,
chance = chance,
chance = max(1, (chance * mob_chance_multiplier)),
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
-- is mob actually registered?
if not mobs.spawning_mobs[name] then
if not mobs.spawning_mobs[name]
or not minetest.registered_entities[name] then
--print ("--- mob doesn't exist", name)
return
end
@ -2907,39 +2932,34 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return
end
-- are we spawning inside solid nodes?
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
--print ("--- feet in block", name, node_ok(pos).name)
return
end
-- do we have enough height clearance to spawn mob?
local ent = minetest.registered_entities[name]
local height = max(0, math.ceil(ent.collisionbox[5] - ent.collisionbox[2]) - 1)
pos.y = pos.y + 1
for n = 0, height do
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
--print ("--- head in block", name, node_ok(pos).name)
return
local pos2 = {x = pos.x, y = pos.y + n, z = pos.z}
if minetest.registered_nodes[node_ok(pos2).name].walkable == true then
--print ("--- inside block", name, node_ok(pos2).name)
return
end
end
-- spawn mob half block higher than ground
pos.y = pos.y - 0.5
pos.y = pos.y + 0.5
if minetest.registered_entities[name] then
local mob = minetest.add_entity(pos, name)
local mob = minetest.add_entity(pos, name)
--[[
print ("[mobs] Spawned " .. name .. " at "
.. minetest.pos_to_string(pos) .. " on "
.. node.name .. " near " .. neighbors[1])
print ("[mobs] Spawned " .. name .. " at "
.. minetest.pos_to_string(pos) .. " on "
.. node.name .. " near " .. neighbors[1])
]]
if on_spawn then
if on_spawn then
local ent = mob:get_luaentity()
local ent = mob:get_luaentity()
on_spawn(ent, pos)
end
else
minetest.log("warning", string.format("[mobs] %s failed to spawn at %s",
name, minetest.pos_to_string(pos)))
on_spawn(ent, pos)
end
end
})

View File

@ -1,5 +1,5 @@
MOB API (18th October 2017)
MOB API
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -13,6 +13,7 @@ The mob api is a function that can be called on by other mods to add new animals
'mobname' can change specific mob chance rate (0 to disable) and 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 spawning.
mobs:register_mob(name, definition)
@ -33,6 +34,7 @@ This functions registers a new mob as a Minetest entity.
'nametag' string containing name of mob to display above entity
'physical' same is in minetest.register_entity()
'collisionbox' same is in minetest.register_entity()
'selectionbox' same is in minetest.register_entity()
'visual' same is in minetest.register_entity()
'visual_size' same is in minetest.register_entity()
'textures' same is in minetest.register_entity()

View File

@ -1,6 +1,6 @@
Mobs Redo API (last updated 18th Oct 2017)
==========================================
Mobs Redo API
=============
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.
@ -140,8 +140,9 @@ functions needed for the mob to work properly which contains the following:
'wielditem' how it looks when player holds it in hand.
'mesh' uses separate object file to define mob.
'visual_size' has the size of the mob, defaults to {x = 1, y = 1}
'collision_box' has the box in which mob can be interacted with e.g.
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
'collision_box' has the box in which mob can be interacted with the
world e.g. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
'selection_box' has the box in which player can interact with mob
'textures' holds a table list of textures to be used for mob, or you
could use multiple lists inside another table for random
selection e.g. { {"texture1.png"}, {"texture2.png"} }
@ -531,21 +532,25 @@ Certain variables need to be set before using the above functions:
External Settings for "minetest.conf"
------------------------------------
'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_disable_blood' if false blood effects appear when mob is hit (default
is false)
'mobs_spawn_protected' if set to false then mobs will not spawn in protected
areas (default is true)
'remove_far_mobs' if true then mobs that are outside players visual
range will be removed (default is false)
'mobname' can change specific mob chance rate (0 to disable) and
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)
'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_disable_blood' if false blood effects appear when mob is hit (default
is false)
'mobs_spawn_protected' if set to false then mobs will not spawn in protected
areas (default is true)
'remove_far_mobs' if true then mobs that are outside players visual
range will be removed (default is false)
'mobname' can change specific mob chance rate (0 to disable) and
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
spawning.
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

View File

@ -7,7 +7,7 @@ if minetest.get_modpath("lucky_block") then
{"dro", {"mobs:nametag"}, 1},
{"dro", {"mobs:leather"}, 5},
{"dro", {"mobs:net"}, 1},
{"dro", {"mobs:magic_lasso"}, 1},
{"dro", {"mobs:lasso"}, 1},
{"dro", {"mobs:shears"}, 1},
{"dro", {"mobs:protector"}, 1},
{"lig"},