update mobs_redo

This commit is contained in:
Sergei Mozhaisky 2020-04-10 10:19:41 +00:00
parent c3f98db7a4
commit bc13bc8432
5 changed files with 372 additions and 70 deletions

View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20190912",
version = "20200407",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -230,10 +230,16 @@ function mob_class:set_velocity(v)
local yaw = (self.object:get_yaw() or 0) + self.rotate
-- nil check for velocity
v = v or 0
-- set velocity with hard limit of 10
local vel = self.object:get_velocity()
self.object:set_velocity({
x = (sin(yaw) * -v) + c_x,
y = self.object:get_velocity().y,
z = (cos(yaw) * v) + c_y
x = max(-10, min((sin(yaw) * -v) + c_x, 10)),
y = max(-10, min((vel and vel.y or 0), 10)),
z = max(-10, min((cos(yaw) * v) + c_y, 10))
})
end
@ -248,6 +254,8 @@ function mob_class:get_velocity()
local v = self.object:get_velocity()
if not v then return 0 end
return (v.x * v.x + v.z * v.z) ^ 0.5
end
@ -586,11 +594,7 @@ function mob_class:do_stay_near()
local target = nearby_nodes[math.random(1, #nearby_nodes)]
local direction = vector.direction(pos, target)
local vec = {
x = target.x - pos.x,
z = target.z - pos.z
}
local vec = {x = target.x - pos.x, z = target.z - pos.z}
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -735,7 +739,7 @@ function mob_class:check_for_death(cmi_cause)
-- has health actually changed?
if self.health == self.old_health and self.health > 0 then
return
return false
end
self.old_health = self.health
@ -838,6 +842,11 @@ function mob_class:is_at_cliff()
return false
end
-- if object no longer exists then return
if not self.object:get_luaentity() then
return false
end
local yaw = self.object:get_yaw()
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)
@ -894,7 +903,7 @@ function mob_class:do_env_damage()
-- remove mob if standing inside ignore node
if self.standing_in == "ignore" then
self.object:remove()
return
return true
end
-- is mob light sensative, or scared of the dark :P
@ -909,7 +918,7 @@ function mob_class:do_env_damage()
effect(pos, 5, "tnt_smoke.png")
if self:check_for_death({type = "light"}) then return end
if self:check_for_death({type = "light"}) then return true end
end
end
@ -928,7 +937,7 @@ function mob_class:do_env_damage()
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
if self:check_for_death({type = "environment",
pos = pos, node = self.standing_in}) then return end
pos = pos, node = self.standing_in}) then return true end
end
-- lava or fire or ignition source
@ -944,8 +953,8 @@ function mob_class:do_env_damage()
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
if self:check_for_death({type = "environment",
pos = pos, node = self.standing_in, hot = true}) then return end
if self:check_for_death({type = "environment", pos = pos,
node = self.standing_in, hot = true}) then return true end
end
-- damage_per_second node check
@ -956,7 +965,7 @@ function mob_class:do_env_damage()
effect(pos, 5, "tnt_smoke.png")
if self:check_for_death({type = "environment",
pos = pos, node = self.standing_in}) then return end
pos = pos, node = self.standing_in}) then return true end
end
--[[
--- suffocation inside solid node
@ -968,10 +977,10 @@ function mob_class:do_env_damage()
self.health = self.health - self.suffocation
if self:check_for_death({type = "environment",
pos = pos, node = self.standing_in}) then return end
pos = pos, node = self.standing_in}) then return true end
end
]]
self:check_for_death({type = "unknown"})
return self:check_for_death({type = "unknown"})
end
@ -1342,17 +1351,22 @@ function mob_class:replace(pos)
-- print ("replace node = ".. minetest.get_node(pos).name, pos.y)
local oldnode = {name = what}
local newnode = {name = with}
local on_replace_return
if self.on_replace then
on_replace_return = self:on_replace(pos, oldnode, newnode)
local oldnode = what
local newnode = with
-- convert any group: replacements to actual node name
if oldnode:find("group:") then
oldnode = minetest.get_node(pos).name
end
if self:on_replace(pos, oldnode, newnode) == false then
return
end
end
if on_replace_return ~= false then
minetest.set_node(pos, {name = with})
end
minetest.set_node(pos, {name = with})
end
end
@ -2026,7 +2040,7 @@ function mob_class:do_states(dtime)
and self.walk_chance ~= 0
and self.facing_fence ~= true
and random(1, 100) <= self.walk_chance
and self:is_at_cliff() == false then
and self.at_cliff == false then
self:set_velocity(self.walk_velocity)
self.state = "walk"
@ -2107,10 +2121,8 @@ function mob_class:do_states(dtime)
end
-- stand for great fall in front
local temp_is_cliff = self:is_at_cliff()
if self.facing_fence == true
or temp_is_cliff
or self.at_cliff
or random(1, 100) <= self.stand_chance then
self:set_velocity(0)
@ -2136,7 +2148,7 @@ function mob_class:do_states(dtime)
-- stop after 5 seconds or when at cliff
if self.runaway_timer > 5
or self:is_at_cliff()
or self.at_cliff
or self.order == "stand" then
self.runaway_timer = 0
self:set_velocity(0)
@ -2386,7 +2398,7 @@ function mob_class:do_states(dtime)
self:smart_mobs(s, p, dist, dtime)
end
if self:is_at_cliff() then
if self.at_cliff then
self:set_velocity(0)
self:set_animation("stand")
@ -2523,6 +2535,9 @@ function mob_class:falling(pos)
-- floating in water (or falling)
local v = self.object:get_velocity()
-- sanity check
if not v then return end
if v.y > 0 then
-- apply gravity when moving up
@ -3105,7 +3120,10 @@ function mob_class:on_step(dtime)
end
local pos = self.object:get_pos()
local yaw = 0
local yaw = self.object:get_yaw()
-- early warning check, if no yaw then no entity, skip rest of function
if not yaw then return end
-- get node at foot level every quarter second
self.node_timer = (self.node_timer or 0) + dtime
@ -3136,6 +3154,13 @@ function mob_class:on_step(dtime)
})
end
-- check and stop if standing at cliff and fear of heights
self.at_cliff = self:is_at_cliff()
if self.at_cliff then
self:set_velocity(0)
end
-- check for mob expiration (0.25 instead of dtime since were in a timer)
self:mob_expire(pos, 0.25)
end
@ -3147,8 +3172,6 @@ function mob_class:on_step(dtime)
if self.delay and self.delay > 0 then
local yaw = self.object:get_yaw()
if self.delay == 1 then
yaw = self.target_yaw
else
@ -3231,7 +3254,7 @@ function mob_class:on_step(dtime)
self.env_damage_timer = 0
-- check for environmental damage (water, fire, lava etc.)
self:do_env_damage()
if self:do_env_damage() then return end
-- node replace check (cow eats grass etc.)
self:replace(pos)
@ -3263,7 +3286,8 @@ function mob_class:on_blast(damage)
damage_groups = {fleshy = damage},
}, nil)
return false, true, {}
-- return no damage, no knockback, no item drops, mob api handles all
return false, false, {}
end
@ -3289,6 +3313,7 @@ minetest.register_entity(name, setmetatable({
jump_height = def.jump_height,
drawtype = def.drawtype, -- DEPRECATED, use rotate instead
rotate = math.rad(def.rotate or 0), -- 0=front, 90=side, 180=back, 270=side2
glow = def.glow,
lifetimer = def.lifetimer,
hp_min = max(1, (def.hp_min or 5) * difficulty),
hp_max = max(1, (def.hp_max or 10) * difficulty),
@ -3821,6 +3846,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
local mob = minetest.add_entity(pos, mob, data)
local ent = mob:get_luaentity()
if not ent then return end -- sanity check
-- set owner if not a monster
if ent.type ~= "monster" then
ent.owner = placer:get_player_name()
@ -3866,6 +3893,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
local mob = minetest.add_entity(pos, mob)
local ent = mob:get_luaentity()
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
@ -4247,6 +4276,11 @@ end)
-- compatibility function for old entities to new modpack entities
function mobs:alias_mob(old_name, new_name)
-- check old_name entity doesnt already exist
if minetest.registered_entities[old_name] then
return
end
-- spawn egg
minetest.register_alias(old_name, new_name)
@ -4255,13 +4289,17 @@ function mobs:alias_mob(old_name, new_name)
physical = false,
on_activate = function(self)
on_activate = function(self, staticdata)
if minetest.registered_entities[new_name] then
minetest.add_entity(self.object:get_pos(), new_name)
minetest.add_entity(self.object:get_pos(), new_name, staticdata)
end
self.object:remove()
end,
get_staticdata = function(self)
return self
end
})
end

View File

@ -186,6 +186,7 @@ functions needed for the mob to work properly which contains the following:
self.gotten is true for mobs.
'rotate' custom model rotation, 0 = front, 90 = side, 180 = back,
270 = other side.
'glow' has mob glow without light source, 0 to 15 or nil to disable
'double_melee_attack' when true has the api choose between 'punch' and
'punch2' animations. [DEPRECATED]
@ -321,43 +322,45 @@ for each mob.
Spawning Mobs in World
----------------------
mobs:spawn({
name = "mobs_monster:tree_monster",
nodes = {"group:leaves"},
max_light = 7,
})
Spawn functions require the following settings, some of which already have a
default setting and can be omitted:
'name' is the name of the animal/monster
'nodes' is a list of nodenames on that the animal/monster can
spawn on top of (defaults to {"group:dirt", "group:stone"}
'neighbors' is a list of nodenames on that the animal/monster will
spawn beside (default is {"air"})
'interval' is same as in register_abm() (default is 30)
'chance' is same as in register_abm() (default is 5000)
'min_light' is the minimum light level (default is 0)
'max_light' is the maximum light (default is 15)
'min_height' is the minimum height a mob can spawn (default: -31000)
'max_height' is the maximum height a mob can spawn (default is 31000)
'active_object_count' number of this type of mob to spawn at one time inside
map area (default is 1)
'day_toggle' true for day spawning, false for night or nil for
anytime
'on_spawn' is a custom function which runs after mob has spawned
and gives self and pos values.
The older spawn functions are still active and working but have no defaults like
the mobs:spawn, so it is recommended to use the above instead.
mobs:register_spawn(name, nodes, max_light, min_light, chance,
active_object_count, max_height, day_toggle)
mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval,
chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
These functions register a spawn algorithm for the mob. Without this function
the call the mobs won't spawn.
'name' is the name of the animal/monster
'nodes' is a list of nodenames on that the animal/monster can
spawn on top of
'neighbors' is a list of nodenames on that the animal/monster will
spawn beside (default is {"air"} for
mobs:register_spawn)
'max_light' is the maximum of light
'min_light' is the minimum of light
'interval' is same as in register_abm() (default is 30 for
mobs:register_spawn)
'chance' is same as in register_abm()
'active_object_count' number of this type of mob to spawn at one time inside
map area
'min_height' is the minimum height the mob can spawn
'max_height' is the maximum height the mob can spawn
'day_toggle' true for day spawning, false for night or nil for
anytime
'on_spawn' is a custom function which runs after mob has spawned
and gives self and pos values.
A simpler way to handle mob spawns has been added with the mobs:spawn(def)
command which uses above names to make settings clearer:
mobs:spawn({name = "mobs_monster:tree_monster",
nodes = {"group:leaves"},
max_light = 7,
})
For each mob that spawns with this function is a field in mobs.spawning_mobs.
It tells if the mob should spawn or not. Default is true. So other mods can
@ -417,7 +420,8 @@ Spawn Eggs
mobs:register_egg(name, description, background, addegg, no_creative)
This function registers a spawn egg which can be used by admin to properly spawn in a mob.
This function registers a spawn egg which can be used to properly spawn in a mob.
Animals are spawned as tamed unless sneak/shift is held while spawning.
'name' this is the name of your new mob to spawn e.g. "mob:sheep"
'description' the name of the new egg you are creating e.g. "Spawn Sheep"
@ -747,7 +751,7 @@ mobs:register_mob("mob_horse:horse", {
if inv:room_for_item("main", "mobs:saddle") then
inv:add_item("main", "mobs:saddle")
else
minetest.add_item(clicker.getpos(), "mobs:saddle")
minetest.add_item(clicker.get_pos(), "mobs:saddle")
end
-- attach player to horse

130
mobs_redo/locale/zh_CN.po Normal file
View File

@ -0,0 +1,130 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# IFRFSX<1079092922@qq.com>, 2020.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-02 16:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: api.lua
msgid "** Peaceful Mode Active - No Monsters Will Spawn"
msgstr "** 和平模式已激活——没有怪物会产生"
#: api.lua
msgid "Mob has been protected!"
msgstr "Mob 已经被保护了!"
#: api.lua
msgid "@1 (Tamed)"
msgstr "@1已驯服"
#: api.lua
msgid "Not tamed!"
msgstr "没有驯服!"
#: api.lua
msgid "@1 is owner!"
msgstr "@1 是主人"
#: api.lua
msgid "Missed!"
msgstr "没抓住!"
#: api.lua
msgid "Already protected!"
msgstr "已经被保护!"
#: api.lua
msgid "@1 at full health (@2)"
msgstr "@1已经满血@2"
#: api.lua
msgid "@1 has been tamed!"
msgstr "@1已经被驯服"
#: api.lua
msgid "Enter name:"
msgstr "输入名称:"
#: api.lua
msgid "Rename"
msgstr "重新命名"
#: crafts.lua
msgid "Name Tag"
msgstr "名称标签"
#: crafts.lua
msgid "Leather"
msgstr "皮革"
#: crafts.lua
msgid "Raw Meat"
msgstr "生肉"
#: crafts.lua
msgid "Meat"
msgstr "肉"
#: crafts.lua
msgid "Lasso (right-click animal to put in inventory)"
msgstr "套索(右键单击动物以放入物品栏)"
#: crafts.lua
msgid "Net (right-click animal to put in inventory)"
msgstr "网(右键单击动物以放入物品栏)"
#: crafts.lua
msgid "Steel Shears (right-click to shear)"
msgstr "钢剪(右键单击以剪切)"
#: crafts.lua
msgid "Mob Protection Rune"
msgstr "Mob 保护符文"
#: crafts.lua
msgid "Saddle"
msgstr "鞍"
#: crafts.lua
msgid "Mob Fence"
msgstr "Mob 栅栏"
#: spawner.lua
msgid "Mob Spawner"
msgstr "Mob 孵化器"
#: spawner.lua
msgid "Mob MinLight MaxLight Amount PlayerDist"
msgstr "Mob/最小光量/最大光量/玩家距离"
#: spawner.lua
msgid "Spawner Not Active (enter settings)"
msgstr "孵化器未使用(输入设置)"
#: spawner.lua
msgid "Spawner Active (@1)"
msgstr "孵化器正在运转(@1"
#: spawner.lua
msgid "Mob Spawner settings failed!"
msgstr "Mob 孵化器设置失败!"
#: spawner.lua
msgid ""
"Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] "
"distance[1-20] y_offset[-10 to 10]”"
msgstr ""
"语法: “物品名称 最小光亮[0-14] 最大光亮[0-14] 范围内的最大Mob数量[0 to disable] "
"距离[1-20] y_offset[-10 to 10]”"

130
mobs_redo/locale/zh_TW.po Normal file
View File

@ -0,0 +1,130 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# IFRFSX<1079092922@qq.com>, 2020.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-02 16:48+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: api.lua
msgid "** Peaceful Mode Active - No Monsters Will Spawn"
msgstr "** 和平模式已激活——沒有怪物會產生"
#: api.lua
msgid "Mob has been protected!"
msgstr "Mob 已經被保護了!"
#: api.lua
msgid "@1 (Tamed)"
msgstr "@1已馴服"
#: api.lua
msgid "Not tamed!"
msgstr "沒有馴服!"
#: api.lua
msgid "@1 is owner!"
msgstr "@1 是主人"
#: api.lua
msgid "Missed!"
msgstr "沒抓住!"
#: api.lua
msgid "Already protected!"
msgstr "已經被保護!"
#: api.lua
msgid "@1 at full health (@2)"
msgstr "@1已經滿血@2"
#: api.lua
msgid "@1 has been tamed!"
msgstr "@1已經被馴服"
#: api.lua
msgid "Enter name:"
msgstr "輸入名稱:"
#: api.lua
msgid "Rename"
msgstr "重新命名"
#: crafts.lua
msgid "Name Tag"
msgstr "名稱標籤"
#: crafts.lua
msgid "Leather"
msgstr "皮革"
#: crafts.lua
msgid "Raw Meat"
msgstr "生肉"
#: crafts.lua
msgid "Meat"
msgstr "肉"
#: crafts.lua
msgid "Lasso (right-click animal to put in inventory)"
msgstr "套索(右鍵單擊動物以放入物品欄)"
#: crafts.lua
msgid "Net (right-click animal to put in inventory)"
msgstr "網(右鍵單擊動物以放入物品欄)"
#: crafts.lua
msgid "Steel Shears (right-click to shear)"
msgstr "鋼剪(右鍵單擊以剪切)"
#: crafts.lua
msgid "Mob Protection Rune"
msgstr "Mob 保護符文"
#: crafts.lua
msgid "Saddle"
msgstr "鞍"
#: crafts.lua
msgid "Mob Fence"
msgstr "Mob 柵欄"
#: spawner.lua
msgid "Mob Spawner"
msgstr "Mob 孵化器"
#: spawner.lua
msgid "Mob MinLight MaxLight Amount PlayerDist"
msgstr "Mob/最小光量/最大光量/玩家距離"
#: spawner.lua
msgid "Spawner Not Active (enter settings)"
msgstr "孵化器未使用(輸入設置)"
#: spawner.lua
msgid "Spawner Active (@1)"
msgstr "孵化器正在運轉(@1"
#: spawner.lua
msgid "Mob Spawner settings failed!"
msgstr "Mob 孵化器設置失敗!"
#: spawner.lua
msgid ""
"Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] "
"distance[1-20] y_offset[-10 to 10]”"
msgstr ""
"語法: “物品名稱 最小光亮[0-14] 最大光亮[0-14] 範圍內的最大Mob數量[0 to disable] "
"距離[1-20] y_offset[-10 to 10]”"

View File

@ -23,7 +23,7 @@ Lucky Blocks: 9
Changelog:
- 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)
- 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