mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-04-19 03:50:24 +02:00
add missing prop checks, update WIP api
This commit is contained in:
parent
f1daaa4a14
commit
56f4eb4274
12
api.lua
12
api.lua
@ -905,6 +905,7 @@ function mob_class:check_for_death(cmi_cause)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local damaged = self.health < self.old_health
|
local damaged = self.health < self.old_health
|
||||||
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
self.old_health = self.health
|
self.old_health = self.health
|
||||||
|
|
||||||
@ -917,8 +918,8 @@ function mob_class:check_for_death(cmi_cause)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- make sure health isn't higher than max
|
-- make sure health isn't higher than max
|
||||||
if self.health > self.hp_max then
|
if self.health > prop.hp_max then
|
||||||
self.health = self.hp_max
|
self.health = prop.hp_max
|
||||||
end
|
end
|
||||||
|
|
||||||
self:update_tag()
|
self:update_tag()
|
||||||
@ -2933,13 +2934,14 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
|
|
||||||
minetest.sound_play(snd, {object = self.object, max_hear_distance = 8}, true)
|
minetest.sound_play(snd, {object = self.object, max_hear_distance = 8}, true)
|
||||||
|
|
||||||
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
-- blood_particles
|
-- blood_particles
|
||||||
if not disable_blood and self.blood_amount > 0 then
|
if not disable_blood and self.blood_amount > 0 then
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local blood = self.blood_texture
|
local blood = self.blood_texture
|
||||||
local amount = self.blood_amount
|
local amount = self.blood_amount
|
||||||
local prop = self.object:get_properties()
|
|
||||||
|
|
||||||
pos.y = pos.y + (-prop.collisionbox[2] + prop.collisionbox[5]) * .5
|
pos.y = pos.y + (-prop.collisionbox[2] + prop.collisionbox[5]) * .5
|
||||||
|
|
||||||
@ -2961,7 +2963,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
|
|
||||||
self.old_texture_mods = self.texture_mods
|
self.old_texture_mods = self.texture_mods
|
||||||
|
|
||||||
self.object:set_texture_mod(self.texture_mods .. self.damage_texture_modifier)
|
self.object:set_texture_mod(self.texture_mods .. prop.damage_texture_modifier)
|
||||||
|
|
||||||
minetest.after(0.3, function()
|
minetest.after(0.3, function()
|
||||||
|
|
||||||
@ -4097,7 +4099,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
if pos then
|
if pos then
|
||||||
|
|
||||||
-- adjust for mob collision box
|
-- adjust for mob collision box
|
||||||
pos.y = pos.y + (ent.collisionbox[2] * -1) - 0.4
|
pos.y = pos.y + (ent.base_colbox[2] * -1) - 0.4
|
||||||
|
|
||||||
local mob = minetest.add_entity(pos, name)
|
local mob = minetest.add_entity(pos, name)
|
||||||
|
|
||||||
|
210
api_WIP.lua
210
api_WIP.lua
@ -11,7 +11,7 @@ local use_mc2 = minetest.get_modpath("mcl_core")
|
|||||||
-- Global
|
-- Global
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20231003",
|
version = "20231005",
|
||||||
translate = S,
|
translate = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
node_snow = minetest.registered_aliases["mapgen_snow"]
|
node_snow = minetest.registered_aliases["mapgen_snow"]
|
||||||
@ -124,6 +124,7 @@ local aoc_range = tonumber(settings:get("active_block_range")) * 16
|
|||||||
local creatura = minetest.get_modpath("creatura") and
|
local creatura = minetest.get_modpath("creatura") and
|
||||||
settings:get_bool("mobs_attack_creatura") == true
|
settings:get_bool("mobs_attack_creatura") == true
|
||||||
|
|
||||||
|
|
||||||
mobs.mob_class = {
|
mobs.mob_class = {
|
||||||
fly_in = "air",
|
fly_in = "air",
|
||||||
owner = "",
|
owner = "",
|
||||||
@ -345,12 +346,11 @@ function mob_class:set_velocity(v)
|
|||||||
-- set velocity
|
-- set velocity
|
||||||
local vel = self.object:get_velocity() or {x = 0, y = 0, z = 0}
|
local vel = self.object:get_velocity() or {x = 0, y = 0, z = 0}
|
||||||
|
|
||||||
local new_vel = {
|
self.object:set_velocity({
|
||||||
x = (sin(yaw) * -v) + c_x,
|
x = (sin(yaw) * -v) + c_x,
|
||||||
y = vel.y,
|
y = vel.y,
|
||||||
z = (cos(yaw) * v) + c_y}
|
z = (cos(yaw) * v) + c_y
|
||||||
|
})
|
||||||
self.object:set_velocity(new_vel)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- global version of above function
|
-- global version of above function
|
||||||
@ -725,24 +725,37 @@ local CHILD_GROW_TIME = 60 * 20 -- 20 minutes
|
|||||||
|
|
||||||
|
|
||||||
-- update nametag and infotext
|
-- update nametag and infotext
|
||||||
function mob_class:update_tag()
|
function mob_class:update_tag(newname)
|
||||||
|
|
||||||
local prop = self.object:get_properties()
|
|
||||||
local col
|
local col
|
||||||
|
local prop = self.object:get_properties()
|
||||||
local qua = prop.hp_max / 6
|
local qua = prop.hp_max / 6
|
||||||
|
|
||||||
if self.health <= qua then
|
-- backwards compatibility
|
||||||
col = "#FF0000"
|
if self.nametag and self.nametag ~= "" then
|
||||||
elseif self.health <= (qua * 2) then
|
newname = self.nametag
|
||||||
col = "#FF7A00"
|
self.nametag = nil
|
||||||
elseif self.health <= (qua * 3) then
|
end
|
||||||
col = "#FFB500"
|
|
||||||
elseif self.health <= (qua * 4) then
|
if newname or (self._nametag and self._nametag ~= "") then
|
||||||
col = "#FFFF00"
|
|
||||||
elseif self.health <= (qua * 5) then
|
self._nametag = newname or self._nametag -- adopt new name if one found
|
||||||
col = "#B4FF00"
|
|
||||||
elseif self.health > (qua * 5) then
|
if self.health <= qua then
|
||||||
col = "#00FF00"
|
col = "#FF0000"
|
||||||
|
elseif self.health <= (qua * 2) then
|
||||||
|
col = "#FF7A00"
|
||||||
|
elseif self.health <= (qua * 3) then
|
||||||
|
col = "#FFB500"
|
||||||
|
elseif self.health <= (qua * 4) then
|
||||||
|
col = "#FFFF00"
|
||||||
|
elseif self.health <= (qua * 5) then
|
||||||
|
col = "#B4FF00"
|
||||||
|
elseif self.health > (qua * 5) then
|
||||||
|
col = "#00FF00"
|
||||||
|
end
|
||||||
|
|
||||||
|
self.object:set_properties({nametag = self._nametag, nametag_color = col})
|
||||||
end
|
end
|
||||||
|
|
||||||
local text = ""
|
local text = ""
|
||||||
@ -768,9 +781,8 @@ function mob_class:update_tag()
|
|||||||
.. (self.owner == "" and "" or "\nOwner: " .. self.owner)
|
.. (self.owner == "" and "" or "\nOwner: " .. self.owner)
|
||||||
.. text
|
.. text
|
||||||
|
|
||||||
-- set changes
|
-- set infotext changes
|
||||||
self.object:set_properties({
|
self.object:set_properties({infotext = self.infotext})
|
||||||
nametag = self.nametag, nametag_color = col, infotext = self.infotext})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1074,10 +1086,10 @@ end
|
|||||||
-- environmental damage (water, lava, fire, light etc.)
|
-- environmental damage (water, lava, fire, light etc.)
|
||||||
function mob_class:do_env_damage()
|
function mob_class:do_env_damage()
|
||||||
|
|
||||||
self:update_tag()
|
|
||||||
|
|
||||||
local pos = self.object:get_pos() ; if not pos then return end
|
local pos = self.object:get_pos() ; if not pos then return end
|
||||||
|
|
||||||
|
self:update_tag()
|
||||||
|
|
||||||
self.time_of_day = minetest.get_timeofday()
|
self.time_of_day = minetest.get_timeofday()
|
||||||
|
|
||||||
-- halt mob if standing inside ignore node
|
-- halt mob if standing inside ignore node
|
||||||
@ -1383,10 +1395,9 @@ function mob_class:breed()
|
|||||||
self.on_grown(self)
|
self.on_grown(self)
|
||||||
else
|
else
|
||||||
local pos = self.object:get_pos() ; if not pos then return end
|
local pos = self.object:get_pos() ; if not pos then return end
|
||||||
local ent = self.object:get_luaentity()
|
|
||||||
local prop = self.object:get_properties()
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
pos.y = pos.y + (prop.collisionbox[2] * -1)
|
pos.y = pos.y + (prop.collisionbox[2] * -1) + 0.1
|
||||||
|
|
||||||
self.object:set_pos(pos)
|
self.object:set_pos(pos)
|
||||||
|
|
||||||
@ -1514,7 +1525,7 @@ function mob_class:breed()
|
|||||||
-- using specific child texture (if found)
|
-- using specific child texture (if found)
|
||||||
if self.child_texture then
|
if self.child_texture then
|
||||||
textures = self.child_texture[1]
|
textures = self.child_texture[1]
|
||||||
ent2.mommy_tex = self.base_texture
|
ent2.mommy_tex = self.base_texture -- when grown
|
||||||
end
|
end
|
||||||
|
|
||||||
ent2.object:set_properties({textures = textures})
|
ent2.object:set_properties({textures = textures})
|
||||||
@ -1648,6 +1659,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
local s1 = self.path.lastpos
|
local s1 = self.path.lastpos
|
||||||
local target_pos = p
|
local target_pos = p
|
||||||
|
|
||||||
|
|
||||||
-- is it becoming stuck?
|
-- is it becoming stuck?
|
||||||
if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then
|
if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then
|
||||||
self.path.stuck_timer = self.path.stuck_timer + dtime
|
self.path.stuck_timer = self.path.stuck_timer + dtime
|
||||||
@ -1719,7 +1731,9 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
end, self)
|
end, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
if abs(vsubtract(s, target_pos).y) > self.initial_properties.stepheight then
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
|
if abs(vsubtract(s, target_pos).y) > prop.stepheight then
|
||||||
|
|
||||||
if height_switcher then
|
if height_switcher then
|
||||||
use_pathfind = true
|
use_pathfind = true
|
||||||
@ -1756,7 +1770,6 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
p1.z = floor(p1.z + 0.5)
|
p1.z = floor(p1.z + 0.5)
|
||||||
|
|
||||||
local dropheight = pathfinding_max_drop
|
local dropheight = pathfinding_max_drop
|
||||||
local prop = self.object:get_properties()
|
|
||||||
|
|
||||||
if self.fear_height ~= 0 then dropheight = self.fear_height end
|
if self.fear_height ~= 0 then dropheight = self.fear_height end
|
||||||
|
|
||||||
@ -1766,7 +1779,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
jumpheight = min(ceil(
|
jumpheight = min(ceil(
|
||||||
self.jump_height / pathfinding_max_jump), pathfinding_max_jump)
|
self.jump_height / pathfinding_max_jump), pathfinding_max_jump)
|
||||||
|
|
||||||
elseif prop.stepheight > 0.5 then
|
elseif self.stepheight > 0.5 then
|
||||||
jumpheight = 1
|
jumpheight = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1896,8 +1909,7 @@ local function is_peaceful_player(player)
|
|||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
-- player priv enabled
|
-- player priv enabled
|
||||||
if player_name
|
if player_name and minetest.check_player_privs(player_name, "peaceful_player") then
|
||||||
and minetest.check_player_privs(player_name, "peaceful_player") then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2943,10 +2955,11 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
-- add healthy afterglow when hit (can cause lag with larger textures)
|
-- add healthy afterglow when hit (can cause lag with larger textures)
|
||||||
if mob_hit_effect then
|
if mob_hit_effect then
|
||||||
|
|
||||||
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
self.old_texture_mods = self.texture_mods
|
self.old_texture_mods = self.texture_mods
|
||||||
|
|
||||||
self.object:set_texture_mod(self.texture_mods
|
self.object:set_texture_mod(self.texture_mods .. prop.damage_texture_modifier)
|
||||||
.. self.initial_properties.damage_texture_modifier)
|
|
||||||
|
|
||||||
minetest.after(0.3, function()
|
minetest.after(0.3, function()
|
||||||
|
|
||||||
@ -3134,10 +3147,11 @@ function mob_class:mob_staticdata()
|
|||||||
self.serialized_cmi_components = cmi.serialize_components(self._cmi_components)
|
self.serialized_cmi_components = cmi.serialize_components(self._cmi_components)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- move existing variables to new initial_properties table for future compatibility
|
-- move existing variables to new table for future compatibility
|
||||||
if not self.initial_properties then
|
-- using self.initial_properties lost some variables when backing up?!?
|
||||||
|
if not self.backup_properties then
|
||||||
|
|
||||||
self.initial_properties = {
|
self.backup_properties = {
|
||||||
hp_max = self.hp_max,
|
hp_max = self.hp_max,
|
||||||
physical = self.physical,
|
physical = self.physical,
|
||||||
collisionbox = self.collisionbox,
|
collisionbox = self.collisionbox,
|
||||||
@ -3149,7 +3163,7 @@ function mob_class:mob_staticdata()
|
|||||||
make_footstep_sound = self.make_footstep_sound,
|
make_footstep_sound = self.make_footstep_sound,
|
||||||
stepheight = self.stepheight,
|
stepheight = self.stepheight,
|
||||||
glow = self.glow,
|
glow = self.glow,
|
||||||
nametag = self.nametag,
|
-- nametag = self.nametag,
|
||||||
damage_texture_modifier = self.damage_texture_modifier,
|
damage_texture_modifier = self.damage_texture_modifier,
|
||||||
-- infotext = self.infotext
|
-- infotext = self.infotext
|
||||||
}
|
}
|
||||||
@ -3201,18 +3215,6 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- force current model into mob
|
|
||||||
-- self.initial_properties.mesh = def.mesh
|
|
||||||
self.base_mesh = def.mesh
|
|
||||||
-- self.initial_properties.collisionbox = def.collisionbox
|
|
||||||
-- self.initial_properties.selectionbox = def.selectionbox
|
|
||||||
|
|
||||||
self.object:set_properties({
|
|
||||||
mesh = def.mesh,
|
|
||||||
collisionbox = def.collisionbox,
|
|
||||||
selectionbox = def.selectionbox,
|
|
||||||
})
|
|
||||||
|
|
||||||
local prop = self.object:get_properties()
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
-- select random texture, set model and size
|
-- select random texture, set model and size
|
||||||
@ -3223,26 +3225,18 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
def.textures = {def.textures}
|
def.textures = {def.textures}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- backup a few base settings
|
||||||
self.base_texture = def.textures and def.textures[random(#def.textures)]
|
self.base_texture = def.textures and def.textures[random(#def.textures)]
|
||||||
self.base_mesh = def.mesh
|
|
||||||
self.base_size = prop.visual_size
|
|
||||||
self.base_colbox = prop.collisionbox
|
|
||||||
self.base_selbox = prop.selectionbox
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for current mobs that dont have this set
|
-- get texture, model and size
|
||||||
if not self.base_selbox then
|
|
||||||
self.base_selbox = prop.selectionbox or self.base_colbox
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set texture, model and size
|
|
||||||
local textures = self.base_texture
|
local textures = self.base_texture
|
||||||
local mesh = self.base_mesh
|
local mesh = self.base_mesh
|
||||||
local vis_size = self.base_size
|
local vis_size = self.base_size
|
||||||
local colbox = self.base_colbox
|
local colbox = self.base_colbox
|
||||||
local selbox = self.base_selbox
|
local selbox = self.base_selbox
|
||||||
|
|
||||||
-- specific texture if gotten
|
-- is there a specific texture if gotten
|
||||||
if self.gotten == true and def.gotten_texture then
|
if self.gotten == true and def.gotten_texture then
|
||||||
textures = def.gotten_texture
|
textures = def.gotten_texture
|
||||||
end
|
end
|
||||||
@ -3272,11 +3266,12 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
self.base_selbox[5] * .5, self.base_selbox[6] * .5}
|
self.base_selbox[5] * .5, self.base_selbox[6] * .5}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set mob size and textures
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
textures = self.base_texture,
|
textures = textures,
|
||||||
collisionbox = colbox,
|
|
||||||
selectionbox = selbox,
|
|
||||||
visual_size = vis_size,
|
visual_size = vis_size,
|
||||||
|
collisionbox = colbox,
|
||||||
|
selectionbox = selbox
|
||||||
})
|
})
|
||||||
|
|
||||||
if self.health == 0 then
|
if self.health == 0 then
|
||||||
@ -3292,10 +3287,12 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
self.path.stuck_timer = 0 -- if stuck for too long search for path
|
self.path.stuck_timer = 0 -- if stuck for too long search for path
|
||||||
|
|
||||||
-- Armor groups (immortal = 1 for custom damage handling)
|
-- Armor groups (immortal = 1 for custom damage handling)
|
||||||
local armor = {fleshy = self.armor, immortal = 1}
|
local armor
|
||||||
|
|
||||||
if type(self.armor) == "table" then
|
if type(self.armor) == "table" then
|
||||||
armor = table_copy(self.armor)
|
armor = table_copy(self.armor)
|
||||||
|
else
|
||||||
|
armor = {fleshy = self.armor, immortal = 1}
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:set_armor_groups(armor)
|
self.object:set_armor_groups(armor)
|
||||||
@ -3304,19 +3301,12 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
self.old_y = self.object:get_pos().y
|
self.old_y = self.object:get_pos().y
|
||||||
self.old_health = self.health
|
self.old_health = self.health
|
||||||
self.sounds.distance = self.sounds.distance or 10
|
self.sounds.distance = self.sounds.distance or 10
|
||||||
|
self.textures = textures
|
||||||
self.standing_in = "air"
|
self.standing_in = "air"
|
||||||
self.standing_on = "air"
|
self.standing_on = "air"
|
||||||
|
|
||||||
-- check for existing nametag
|
|
||||||
-- if not prop.nametag then
|
|
||||||
-- self.object:set_properties({nametag = def.nametag})
|
|
||||||
-- end
|
|
||||||
-- self.initial_properties.nametag = self.initial_properties.nametag or def.nametag
|
|
||||||
|
|
||||||
-- set anything changed above
|
-- set anything changed above
|
||||||
self.object:set_properties(self)
|
|
||||||
self:set_yaw((random(0, 360) - 180) / 180 * pi, 6)
|
self:set_yaw((random(0, 360) - 180) / 180 * pi, 6)
|
||||||
self:update_tag()
|
|
||||||
self:set_animation("stand")
|
self:set_animation("stand")
|
||||||
|
|
||||||
-- apply any texture mods
|
-- apply any texture mods
|
||||||
@ -3325,7 +3315,6 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
-- set 5.x flag to remove monsters when map area unloaded
|
-- set 5.x flag to remove monsters when map area unloaded
|
||||||
if remove_far and self.type == "monster" and not self.tamed then
|
if remove_far and self.type == "monster" and not self.tamed then
|
||||||
self.object:set_properties({static_save = false})
|
self.object:set_properties({static_save = false})
|
||||||
-- self.initial_properties.static_save = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- run on_spawn function if found
|
-- run on_spawn function if found
|
||||||
@ -3615,42 +3604,20 @@ function mobs:register_mob(name, def)
|
|||||||
minetest.register_entity(":" .. name, setmetatable({
|
minetest.register_entity(":" .. name, setmetatable({
|
||||||
|
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
|
|
||||||
hp_max = max(1, (def.hp_max or 10) * difficulty),
|
hp_max = max(1, (def.hp_max or 10) * difficulty),
|
||||||
-- breath_max
|
|
||||||
-- zoom_fov
|
|
||||||
-- eye_height
|
|
||||||
physical = true,
|
physical = true,
|
||||||
-- collide_with_objects
|
collisionbox = collisionbox,
|
||||||
collisionbox = collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
selectionbox = def.selectionbox or collisionbox,
|
||||||
selectionbox = def.selectionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
|
||||||
-- pointable
|
|
||||||
visual = def.visual,
|
visual = def.visual,
|
||||||
visual_size = def.visual_size or {x = 1, y = 1, z = 1},
|
visual_size = def.visual_size or {x = 1, y = 1},
|
||||||
mesh = def.mesh,
|
mesh = def.mesh,
|
||||||
textures = nil,
|
textures = "",
|
||||||
-- colors
|
makes_footstep_sound = def.makes_footstep_sound,
|
||||||
-- use_texture_alpha
|
stepheight = def.stepheight,
|
||||||
-- spritediv
|
|
||||||
-- initial_sprite_basepos
|
|
||||||
-- is_visible
|
|
||||||
make_footstep_sound = def.make_footstep_sound,
|
|
||||||
-- automatic_rotate
|
|
||||||
stepheight = def.stepheight or 1.1,
|
|
||||||
-- automatic_face_movement_dir
|
|
||||||
-- automatic_face_movement_max_rotation_per_sec
|
|
||||||
-- backface_culling
|
|
||||||
glow = def.glow,
|
glow = def.glow,
|
||||||
-- nametag
|
|
||||||
-- nametag_color
|
|
||||||
-- nametag_bgcolor
|
|
||||||
-- infotext
|
|
||||||
static_save = true,
|
|
||||||
damage_texture_modifier = def.damage_texture_modifier or "^[colorize:#c9900070",
|
damage_texture_modifier = def.damage_texture_modifier or "^[colorize:#c9900070",
|
||||||
-- shaded
|
|
||||||
-- show_on_minimap
|
|
||||||
},
|
},
|
||||||
--------
|
|
||||||
name = name,
|
name = name,
|
||||||
type = def.type,
|
type = def.type,
|
||||||
attack_type = def.attack_type,
|
attack_type = def.attack_type,
|
||||||
@ -3665,6 +3632,13 @@ minetest.register_entity(":" .. name, setmetatable({
|
|||||||
rotate = rad(def.rotate or 0), -- 0=front 90=side 180=back 270=side2
|
rotate = rad(def.rotate or 0), -- 0=front 90=side 180=back 270=side2
|
||||||
lifetimer = def.lifetimer,
|
lifetimer = def.lifetimer,
|
||||||
hp_min = max(1, (def.hp_min or 5) * difficulty),
|
hp_min = max(1, (def.hp_min or 5) * difficulty),
|
||||||
|
|
||||||
|
-- backup entity model and size
|
||||||
|
base_mesh = def.mesh,
|
||||||
|
base_colbox = collisionbox,
|
||||||
|
base_selbox = def.selectionbox or collisionbox,
|
||||||
|
base_size = def.visual_size or {x = 1, y = 1},
|
||||||
|
|
||||||
view_range = def.view_range,
|
view_range = def.view_range,
|
||||||
walk_velocity = def.walk_velocity,
|
walk_velocity = def.walk_velocity,
|
||||||
run_velocity = def.run_velocity,
|
run_velocity = def.run_velocity,
|
||||||
@ -3793,9 +3767,8 @@ end
|
|||||||
-- do we have enough space to spawn mob? (thanks wuzzy)
|
-- do we have enough space to spawn mob? (thanks wuzzy)
|
||||||
local function can_spawn(pos, name)
|
local function can_spawn(pos, name)
|
||||||
|
|
||||||
local prop = self.object:get_properties()
|
|
||||||
local ent = minetest.registered_entities[name]
|
local ent = minetest.registered_entities[name]
|
||||||
local width_x = max(1, ceil(prop.collisionbox[4] - prop.collisionbox[1]))
|
local width_x = max(1, ceil(ent.base_colbox[4] - ent.base_colbox[1]))
|
||||||
local min_x, max_x
|
local min_x, max_x
|
||||||
|
|
||||||
if width_x % 2 == 0 then
|
if width_x % 2 == 0 then
|
||||||
@ -3806,7 +3779,7 @@ local function can_spawn(pos, name)
|
|||||||
min_x = -max_x
|
min_x = -max_x
|
||||||
end
|
end
|
||||||
|
|
||||||
local width_z = max(1, ceil(prop.collisionbox[6] - prop.collisionbox[3]))
|
local width_z = max(1, ceil(ent.base_colbox[6] - ent.base_colbox[3]))
|
||||||
local min_z, max_z
|
local min_z, max_z
|
||||||
|
|
||||||
if width_z % 2 == 0 then
|
if width_z % 2 == 0 then
|
||||||
@ -3817,7 +3790,7 @@ local function can_spawn(pos, name)
|
|||||||
min_z = -max_z
|
min_z = -max_z
|
||||||
end
|
end
|
||||||
|
|
||||||
local max_y = max(0, ceil(prop.collisionbox[5] - prop.collisionbox[2]) - 1)
|
local max_y = max(0, ceil(ent.base_colbox[5] - ent.base_colbox[2]) - 1)
|
||||||
local pos2
|
local pos2
|
||||||
|
|
||||||
for y = 0, max_y do
|
for y = 0, max_y do
|
||||||
@ -3950,9 +3923,7 @@ function mobs:add_mob(pos, def)
|
|||||||
def.nametag = def.nametag:sub(1, 64)
|
def.nametag = def.nametag:sub(1, 64)
|
||||||
end
|
end
|
||||||
|
|
||||||
mob:set_properties({nametag = def.nametag})
|
ent:update_tag(def.nametag)
|
||||||
|
|
||||||
ent:update_tag()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return ent
|
return ent
|
||||||
@ -4105,13 +4076,12 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
end
|
end
|
||||||
|
|
||||||
local ent = minetest.registered_entities[name]
|
local ent = minetest.registered_entities[name]
|
||||||
local prop = self.object:get_properties()
|
|
||||||
|
|
||||||
-- should we check mob area for obstructions ?
|
-- should we check mob area for obstructions ?
|
||||||
if mob_area_spawn ~= true then
|
if mob_area_spawn ~= true then
|
||||||
|
|
||||||
-- do we have enough height clearance to spawn mob?
|
-- do we have enough height clearance to spawn mob?
|
||||||
local height = max(0, prop.collisionbox[5] - prop.collisionbox[2])
|
local height = max(0, ent.base_colbox[5] - ent.base_colbox[2])
|
||||||
|
|
||||||
for n = 0, floor(height) do
|
for n = 0, floor(height) do
|
||||||
|
|
||||||
@ -4130,7 +4100,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
|
|||||||
if pos then
|
if pos then
|
||||||
|
|
||||||
-- adjust for mob collision box
|
-- adjust for mob collision box
|
||||||
pos.y = pos.y + (prop.collisionbox[2] * -1) - 0.4
|
pos.y = pos.y + (ent.base_colbox[2] * -1) - 0.4
|
||||||
|
|
||||||
local mob = minetest.add_entity(pos, name)
|
local mob = minetest.add_entity(pos, name)
|
||||||
|
|
||||||
@ -4706,7 +4676,7 @@ function mobs:protect(self, clicker)
|
|||||||
|
|
||||||
pos.y = pos.y + prop.collisionbox[2] + 0.5
|
pos.y = pos.y + prop.collisionbox[2] + 0.5
|
||||||
|
|
||||||
effect(pos, 25, "mobs_protect_particle.png", 0.5, 4, 2, 15)
|
effect(self.object:get_pos(), 25, "mobs_protect_particle.png", 0.5, 4, 2, 15)
|
||||||
|
|
||||||
self:mob_sound("mobs_spell")
|
self:mob_sound("mobs_spell")
|
||||||
|
|
||||||
@ -4733,7 +4703,6 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||||||
clicker:set_wielded_item(item)
|
clicker:set_wielded_item(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local prop = self.object:get_properties()
|
local prop = self.object:get_properties()
|
||||||
|
|
||||||
-- increase health
|
-- increase health
|
||||||
@ -4767,15 +4736,14 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||||||
if tame then
|
if tame then
|
||||||
|
|
||||||
if self.tamed == false then
|
if self.tamed == false then
|
||||||
|
|
||||||
minetest.chat_send_player(clicker:get_player_name(),
|
minetest.chat_send_player(clicker:get_player_name(),
|
||||||
S("@1 has been tamed!",
|
S("@1 has been tamed!",
|
||||||
self.name:split(":")[2]))
|
self.name:split(":")[2]))
|
||||||
end
|
end
|
||||||
|
|
||||||
self.tamed = true
|
self.tamed = true
|
||||||
|
self.static_save = true
|
||||||
self.object:set_properties({static_save = true})
|
|
||||||
-- self.static_save = true
|
|
||||||
|
|
||||||
if not self.owner or self.owner == "" then
|
if not self.owner or self.owner == "" then
|
||||||
self.owner = clicker:get_player_name()
|
self.owner = clicker:get_player_name()
|
||||||
@ -4803,7 +4771,7 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||||||
mob_sta[name] = item
|
mob_sta[name] = item
|
||||||
|
|
||||||
local prop = self.object:get_properties()
|
local prop = self.object:get_properties()
|
||||||
local tag = prop.nametag or ""
|
local tag = self._nametag or ""
|
||||||
local esc = minetest.formspec_escape
|
local esc = minetest.formspec_escape
|
||||||
|
|
||||||
minetest.show_formspec(name, "mobs_nametag", "size[8,4]"
|
minetest.show_formspec(name, "mobs_nametag", "size[8,4]"
|
||||||
@ -4858,9 +4826,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update nametag
|
-- update nametag
|
||||||
mob_obj[name].object:set_properties({nametag = fields.name})
|
mob_obj[name]:update_tag(fields.name)
|
||||||
mob_obj[name].nametag = fields.name
|
|
||||||
mob_obj[name]:update_tag()
|
|
||||||
|
|
||||||
-- if not in creative then take item
|
-- if not in creative then take item
|
||||||
if not mobs.is_creative(name) then
|
if not mobs.is_creative(name) then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user