1
0
Fork 0

Spawn smaller slime/magmacube if it doesn't fit

This commit is contained in:
Wuzzy 2019-02-05 19:12:28 +01:00
parent b7a2fba1ce
commit cfd5615548
3 changed files with 30 additions and 11 deletions

View File

@ -2975,6 +2975,7 @@ minetest.register_entity(name, {
owner = def.owner or "",
order = def.order or "",
on_die = def.on_die,
spawn_small_alternative = def.spawn_small_alternative,
do_custom = def.do_custom,
jump_height = def.jump_height or 4, -- was 6
drawtype = def.drawtype, -- DEPRECATED, use rotate instead
@ -3162,17 +3163,10 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
end
minetest.register_abm({
label = name .. " spawning",
nodenames = nodes,
neighbors = neighbors,
interval = interval,
chance = max(1, (chance * mob_chance_multiplier)),
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
local spawn_action
spawn_action = function(pos, node, active_object_count, active_object_count_wider, name)
local orig_pos = table.copy(pos)
-- is mob actually registered?
if not mobs.spawning_mobs[name]
or not minetest.registered_entities[name] then
@ -3285,6 +3279,10 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
if minetest.registered_nodes[node_ok(pos2).name].walkable == true then
-- inside block
minetest.log("info", "Mob spawn of "..name.." at "..minetest.pos_to_string(pos).." failed, too little space!")
if ent.spawn_small_alternative ~= nil and (not minetest.registered_nodes[node_ok(pos).name].walkable) then
minetest.log("info", "Trying to spawn smaller alternative mob: "..ent.spawn_small_alternative)
spawn_action(orig_pos, node, active_object_count, active_object_count_wider, ent.spawn_small_alternative)
end
return
end
end
@ -3309,7 +3307,20 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
on_spawn(ent, pos)
end
end
end
local function spawn_abm_action(pos, node, active_object_count, active_object_count_wider)
spawn_action(pos, node, active_object_count, active_object_count_wider, name)
end
minetest.register_abm({
label = name .. " spawning",
nodenames = nodes,
neighbors = neighbors,
interval = interval,
chance = max(1, (chance * mob_chance_multiplier)),
catch_up = false,
action = spawn_abm_action,
})
end

View File

@ -213,6 +213,8 @@ functions needed for the mob to work properly which contains the following:
'rain_damage' damage per second if mob is standing in rain (default: 0)
'sunlight_damage' holds the damage per second inflicted to mobs when they
are in direct sunlight
'spawn_small_alternative': name of a smaller mob to use as replacement if
spawning fails due to space requirements
Node Replacement
----------------

View File

@ -58,6 +58,7 @@ local slime_big = {
jump_height = 5.2,
jump_chance = 100,
fear_height = 60,
spawn_small_alternative = "mobs_mc:slime_small",
on_die = function(self, pos)
local angle, posadd
angle = math.random(0, math.pi*2)
@ -83,6 +84,7 @@ slime_small.reach = 2.75
slime_small.walk_velocity = 1.3
slime_small.run_velocity = 1.3
slime_small.jump_height = 4.3
slime_small.spawn_small_alternative = "mobs_mc:slime_tiny"
slime_small.on_die = function(self, pos)
local angle, posadd, dir
angle = math.random(0, math.pi*2)
@ -114,6 +116,7 @@ slime_tiny.drops = {
slime_tiny.walk_velocity = 0.7
slime_tiny.run_velocity = 0.7
slime_tiny.jump_height = 3
slime_tiny.spawn_small_alternative = nil
slime_tiny.on_die = nil
mobs:register_mob("mobs_mc:slime_tiny", slime_tiny)
@ -181,6 +184,7 @@ local magma_cube_big = {
walk_chance = 0,
jump_chance = 100,
fear_height = 100000,
spawn_small_alternative = "mobs_mc:magma_cube_small",
on_die = function(self, pos)
local angle, posadd
angle = math.random(0, math.pi*2)
@ -211,6 +215,7 @@ magma_cube_small.jump_height = 6
magma_cube_small.damage = 4
magma_cube_small.reach = 2.75
magma_cube_small.armor = 70
magma_cube_small.spawn_small_alternative = "mobs_mc:magma_cube_tiny"
magma_cube_small.on_die = function(self, pos)
local angle, posadd, dir
angle = math.random(0, math.pi*2)
@ -239,6 +244,7 @@ magma_cube_tiny.damage = 3
magma_cube_tiny.reach = 2.5
magma_cube_tiny.armor = 85
magma_cube_tiny.drops = {}
magma_cube_tiny.spawn_small_alternative = nil
magma_cube_tiny.on_die = nil
mobs:register_mob("mobs_mc:magma_cube_tiny", magma_cube_tiny)