0
0
Fork 0

Finally indent register_mob and make registered mobs global

This commit is contained in:
cora 2022-11-12 02:16:37 +01:00
parent a3415647d4
commit bc496a8682
1 changed files with 198 additions and 196 deletions

View File

@ -1,6 +1,7 @@
mcl_mobs = {} mcl_mobs = {}
mcl_mobs.mob_class = {} mcl_mobs.mob_class = {}
mcl_mobs.mob_class_meta = {__index = mcl_mobs.mob_class} mcl_mobs.mob_class_meta = {__index = mcl_mobs.mob_class}
mcl_mobs.registered_mobs = {}
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local path = minetest.get_modpath(modname) local path = minetest.get_modpath(modname)
local S = minetest.get_translator(modname) local S = minetest.get_translator(modname)
@ -111,210 +112,211 @@ mcl_mobs.spawning_mobs = {}
function mcl_mobs.register_mob(name, def) function mcl_mobs.register_mob(name, def)
mcl_mobs.spawning_mobs[name] = true mcl_mobs.spawning_mobs[name] = true
mcl_mobs.registered_mobs[name] = def
local can_despawn local can_despawn
if def.can_despawn ~= nil then if def.can_despawn ~= nil then
can_despawn = def.can_despawn can_despawn = def.can_despawn
elseif def.spawn_class == "passive" then elseif def.spawn_class == "passive" then
can_despawn = false can_despawn = false
else
can_despawn = true
end
local function scale_difficulty(value, default, min, special)
if (not value) or (value == default) or (value == special) then
return default
else else
return math.max(min, value * difficulty) can_despawn = true
end end
end
local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25} local function scale_difficulty(value, default, min, special)
-- Workaround for <https://github.com/minetest/minetest/issues/5966>: if (not value) or (value == default) or (value == special) then
-- Increase upper Y limit to avoid mobs glitching through solid nodes. return default
-- FIXME: Remove workaround if it's no longer needed. else
if collisionbox[5] < 0.79 then return math.max(min, value * difficulty)
collisionbox[5] = 0.79 end
end end
minetest.register_entity(name, setmetatable({ local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}
use_texture_alpha = def.use_texture_alpha, -- Workaround for <https://github.com/minetest/minetest/issues/5966>:
head_swivel = def.head_swivel or nil, -- bool to activate this function -- Increase upper Y limit to avoid mobs glitching through solid nodes.
head_yaw_offset = def.head_yaw_offset or 0, -- for wonkey model bones -- FIXME: Remove workaround if it's no longer needed.
head_pitch_multiplier = def.head_pitch_multiplier or 1, --for inverted pitch if collisionbox[5] < 0.79 then
bone_eye_height = def.bone_eye_height or 1.4, -- head bone offset collisionbox[5] = 0.79
head_eye_height = def.head_eye_height or def.bone_eye_height or 0, -- how hight aproximatly the mobs head is fromm the ground to tell the mob how high to look up at the player end
curiosity = def.curiosity or 1, -- how often mob will look at player on idle local final_def = {
head_yaw = def.head_yaw or "y", -- axis to rotate head on use_texture_alpha = def.use_texture_alpha,
horrizonatal_head_height = def.horrizonatal_head_height or 0, head_swivel = def.head_swivel or nil, -- bool to activate this function
wears_armor = def.wears_armor, -- a number value used to index texture slot for armor head_yaw_offset = def.head_yaw_offset or 0, -- for wonkey model bones
stepheight = def.stepheight or 0.6, head_pitch_multiplier = def.head_pitch_multiplier or 1, --for inverted pitch
name = name, bone_eye_height = def.bone_eye_height or 1.4, -- head bone offset
description = def.description, head_eye_height = def.head_eye_height or def.bone_eye_height or 0, -- how hight aproximatly the mobs head is fromm the ground to tell the mob how high to look up at the player
type = def.type, curiosity = def.curiosity or 1, -- how often mob will look at player on idle
attack_type = def.attack_type, head_yaw = def.head_yaw or "y", -- axis to rotate head on
fly = def.fly or false, horrizonatal_head_height = def.horrizonatal_head_height or 0,
fly_in = def.fly_in or {"air", "__airlike"}, wears_armor = def.wears_armor, -- a number value used to index texture slot for armor
owner = def.owner or "", stepheight = def.stepheight or 0.6,
order = def.order or "", name = name,
on_die = def.on_die, description = def.description,
spawn_small_alternative = def.spawn_small_alternative, type = def.type,
do_custom = def.do_custom, attack_type = def.attack_type,
detach_child = def.detach_child, fly = def.fly or false,
jump_height = def.jump_height or 4, -- was 6 fly_in = def.fly_in or {"air", "__airlike"},
rotate = math.rad(def.rotate or 0), -- 0=front, 90=side, 180=back, 270=side2 owner = def.owner or "",
lifetimer = def.lifetimer or 57.73, order = def.order or "",
hp_min = scale_difficulty(def.hp_min, 5, 1), on_die = def.on_die,
hp_max = scale_difficulty(def.hp_max, 10, 1), spawn_small_alternative = def.spawn_small_alternative,
xp_min = def.xp_min or 0, do_custom = def.do_custom,
xp_max = def.xp_max or 0, detach_child = def.detach_child,
xp_timestamp = 0, jump_height = def.jump_height or 4, -- was 6
breath_max = def.breath_max or 15, rotate = math.rad(def.rotate or 0), -- 0=front, 90=side, 180=back, 270=side2
breathes_in_water = def.breathes_in_water or false, lifetimer = def.lifetimer or 57.73,
physical = true, hp_min = scale_difficulty(def.hp_min, 5, 1),
collisionbox = collisionbox, hp_max = scale_difficulty(def.hp_max, 10, 1),
selectionbox = def.selectionbox or def.collisionbox, xp_min = def.xp_min or 0,
visual = def.visual, xp_max = def.xp_max or 0,
visual_size = def.visual_size or {x = 1, y = 1}, xp_timestamp = 0,
mesh = def.mesh, breath_max = def.breath_max or 15,
makes_footstep_sound = def.makes_footstep_sound or false, breathes_in_water = def.breathes_in_water or false,
view_range = def.view_range or 16, physical = true,
walk_velocity = def.walk_velocity or 1, collisionbox = collisionbox,
run_velocity = def.run_velocity or 2, selectionbox = def.selectionbox or def.collisionbox,
damage = scale_difficulty(def.damage, 0, 0), visual = def.visual,
light_damage = def.light_damage or 0, visual_size = def.visual_size or {x = 1, y = 1},
sunlight_damage = def.sunlight_damage or 0, mesh = def.mesh,
water_damage = def.water_damage or 0, makes_footstep_sound = def.makes_footstep_sound or false,
lava_damage = def.lava_damage or 8, view_range = def.view_range or 16,
fire_damage = def.fire_damage or 1, walk_velocity = def.walk_velocity or 1,
suffocation = def.suffocation or true, run_velocity = def.run_velocity or 2,
fall_damage = def.fall_damage or 1, damage = scale_difficulty(def.damage, 0, 0),
fall_speed = def.fall_speed or DEFAULT_FALL_SPEED, -- must be lower than -2 light_damage = def.light_damage or 0,
drops = def.drops or {}, sunlight_damage = def.sunlight_damage or 0,
armor = def.armor or 100, water_damage = def.water_damage or 0,
on_rightclick = create_mob_on_rightclick(def.on_rightclick), lava_damage = def.lava_damage or 8,
arrow = def.arrow, fire_damage = def.fire_damage or 1,
shoot_interval = def.shoot_interval, suffocation = def.suffocation or true,
sounds = def.sounds or {}, fall_damage = def.fall_damage or 1,
animation = def.animation or {}, fall_speed = def.fall_speed or DEFAULT_FALL_SPEED, -- must be lower than -2
follow = def.follow, drops = def.drops or {},
nofollow = def.nofollow, armor = def.armor or 100,
can_open_doors = def.can_open_doors, on_rightclick = create_mob_on_rightclick(def.on_rightclick),
jump = def.jump ~= false, arrow = def.arrow,
automatic_face_movement_max_rotation_per_sec = 300, shoot_interval = def.shoot_interval,
walk_chance = def.walk_chance or 50, sounds = def.sounds or {},
attacks_monsters = def.attacks_monsters or false, animation = def.animation or {},
group_attack = def.group_attack or false, follow = def.follow,
passive = def.passive or false, nofollow = def.nofollow,
knock_back = def.knock_back ~= false, can_open_doors = def.can_open_doors,
shoot_offset = def.shoot_offset or 0, jump = def.jump ~= false,
floats = def.floats or 1, -- floats in water by default automatic_face_movement_max_rotation_per_sec = 300,
floats_on_lava = def.floats_on_lava or 0, walk_chance = def.walk_chance or 50,
replace_rate = def.replace_rate, attacks_monsters = def.attacks_monsters or false,
replace_what = def.replace_what, group_attack = def.group_attack or false,
replace_with = def.replace_with, passive = def.passive or false,
replace_offset = def.replace_offset or 0, knock_back = def.knock_back ~= false,
on_replace = def.on_replace, shoot_offset = def.shoot_offset or 0,
timer = 0, floats = def.floats or 1, -- floats in water by default
env_damage_timer = 0, floats_on_lava = def.floats_on_lava or 0,
tamed = false, replace_rate = def.replace_rate,
pause_timer = 0, replace_what = def.replace_what,
horny = false, replace_with = def.replace_with,
hornytimer = 0, replace_offset = def.replace_offset or 0,
gotten = false, on_replace = def.on_replace,
health = 0, timer = 0,
frame_speed_multiplier = 1, env_damage_timer = 0,
reach = def.reach or 3, tamed = false,
htimer = 0, pause_timer = 0,
texture_list = def.textures, horny = false,
child_texture = def.child_texture, hornytimer = 0,
docile_by_day = def.docile_by_day or false, gotten = false,
time_of_day = 0.5, health = 0,
fear_height = def.fear_height or 0, frame_speed_multiplier = 1,
runaway = def.runaway, reach = def.reach or 3,
runaway_timer = 0, htimer = 0,
pathfinding = def.pathfinding, texture_list = def.textures,
immune_to = def.immune_to or {}, child_texture = def.child_texture,
explosion_radius = def.explosion_radius, -- LEGACY docile_by_day = def.docile_by_day or false,
explosion_damage_radius = def.explosion_damage_radius, -- LEGACY time_of_day = 0.5,
explosiontimer_reset_radius = def.explosiontimer_reset_radius, fear_height = def.fear_height or 0,
explosion_timer = def.explosion_timer or 3, runaway = def.runaway,
allow_fuse_reset = def.allow_fuse_reset ~= false, runaway_timer = 0,
stop_to_explode = def.stop_to_explode ~= false, pathfinding = def.pathfinding,
custom_attack = def.custom_attack, immune_to = def.immune_to or {},
double_melee_attack = def.double_melee_attack, explosion_radius = def.explosion_radius, -- LEGACY
dogshoot_switch = def.dogshoot_switch, explosion_damage_radius = def.explosion_damage_radius, -- LEGACY
dogshoot_count = 0, explosiontimer_reset_radius = def.explosiontimer_reset_radius,
dogshoot_count_max = def.dogshoot_count_max or 5, explosion_timer = def.explosion_timer or 3,
dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5), allow_fuse_reset = def.allow_fuse_reset ~= false,
attack_animals = def.attack_animals or false, stop_to_explode = def.stop_to_explode ~= false,
attack_npcs = def.attack_npcs or false, custom_attack = def.custom_attack,
specific_attack = def.specific_attack, double_melee_attack = def.double_melee_attack,
runaway_from = def.runaway_from, dogshoot_switch = def.dogshoot_switch,
owner_loyal = def.owner_loyal, dogshoot_count = 0,
facing_fence = false, dogshoot_count_max = def.dogshoot_count_max or 5,
is_mob = true, dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5),
pushable = def.pushable or true, attack_animals = def.attack_animals or false,
attack_npcs = def.attack_npcs or false,
specific_attack = def.specific_attack,
runaway_from = def.runaway_from,
owner_loyal = def.owner_loyal,
facing_fence = false,
is_mob = true,
pushable = def.pushable or true,
-- MCL2 extensions -- MCL2 extensions
shooter_avoid_enemy = def.shooter_avoid_enemy, shooter_avoid_enemy = def.shooter_avoid_enemy,
strafes = def.strafes, strafes = def.strafes,
avoid_distance = def.avoid_distance or 9, avoid_distance = def.avoid_distance or 9,
do_teleport = def.do_teleport, do_teleport = def.do_teleport,
spawn_class = def.spawn_class, spawn_class = def.spawn_class,
can_spawn = def.can_spawn, can_spawn = def.can_spawn,
ignores_nametag = def.ignores_nametag or false, ignores_nametag = def.ignores_nametag or false,
rain_damage = def.rain_damage or 0, rain_damage = def.rain_damage or 0,
glow = def.glow, glow = def.glow,
can_despawn = can_despawn, can_despawn = can_despawn,
child = def.child or false, child = def.child or false,
texture_mods = {}, texture_mods = {},
shoot_arrow = def.shoot_arrow, shoot_arrow = def.shoot_arrow,
sounds_child = def.sounds_child, sounds_child = def.sounds_child,
_child_animations = def.child_animations, _child_animations = def.child_animations,
pick_up = def.pick_up, pick_up = def.pick_up,
explosion_strength = def.explosion_strength, explosion_strength = def.explosion_strength,
suffocation_timer = 0, suffocation_timer = 0,
follow_velocity = def.follow_velocity or 2.4, follow_velocity = def.follow_velocity or 2.4,
instant_death = def.instant_death or false, instant_death = def.instant_death or false,
fire_resistant = def.fire_resistant or false, fire_resistant = def.fire_resistant or false,
fire_damage_resistant = def.fire_damage_resistant or false, fire_damage_resistant = def.fire_damage_resistant or false,
ignited_by_sunlight = def.ignited_by_sunlight or false, ignited_by_sunlight = def.ignited_by_sunlight or false,
spawn_in_group = def.spawn_in_group, spawn_in_group = def.spawn_in_group,
spawn_in_group_min = def.spawn_in_group_min, spawn_in_group_min = def.spawn_in_group_min,
noyaw = def.noyaw or false, noyaw = def.noyaw or false,
particlespawners = def.particlespawners, particlespawners = def.particlespawners,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,
on_blast = def.on_blast or function(self,damage) on_blast = def.on_blast or function(self,damage)
self.object:punch(self.object, 1.0, { self.object:punch(self.object, 1.0, {
full_punch_interval = 1.0, full_punch_interval = 1.0,
damage_groups = {fleshy = damage}, damage_groups = {fleshy = damage},
}, nil) }, nil)
return false, true, {} return false, true, {}
end, end,
do_punch = def.do_punch, do_punch = def.do_punch,
on_breed = def.on_breed, on_breed = def.on_breed,
on_grown = def.on_grown, on_grown = def.on_grown,
on_pick_up = def.on_pick_up, on_pick_up = def.on_pick_up,
on_activate = function(self, staticdata, dtime) on_activate = function(self, staticdata, dtime)
--this is a temporary hack so mobs stop --this is a temporary hack so mobs stop
--glitching and acting really weird with the --glitching and acting really weird with the
--default built in engine collision detection --default built in engine collision detection
self.is_mob = true self.is_mob = true
self.object:set_properties({ self.object:set_properties({
collide_with_objects = false, collide_with_objects = false,
}) })
return self:mob_activate(staticdata, def, dtime) return self:mob_activate(staticdata, def, dtime)
end, end,
harmed_by_heal = def.harmed_by_heal, harmed_by_heal = def.harmed_by_heal,
on_lightning_strike = def.on_lightning_strike on_lightning_strike = def.on_lightning_strike
},mcl_mobs.mob_class_meta)) }
minetest.register_entity(name, setmetatable(final_def,mcl_mobs.mob_class_meta))
if minetest.get_modpath("doc_identifier") ~= nil then if minetest.get_modpath("doc_identifier") ~= nil then
doc.sub.identifier.register_object(name, "basics", "mobs") doc.sub.identifier.register_object(name, "basics", "mobs")
end end
end -- END mcl_mobs.register_mob function end -- END mcl_mobs.register_mob function