1
0
Fork 0

Merge pull request 'Slime, magma cube and cow spawning fixes.' (#3162) from slime_fixes into master

Reviewed-on: MineClone2/MineClone2#3162
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
This commit is contained in:
ancientmarinerdev 2022-12-29 02:14:32 +00:00
commit 437842134e
4 changed files with 149 additions and 170 deletions

View File

@ -402,11 +402,9 @@ local two_pi = 2 * math.pi
local function get_next_mob_spawn_pos(pos) local function get_next_mob_spawn_pos(pos)
local distance = math_random(25, 32) local distance = math_random(25, 32)
local angle = math_random() * two_pi local angle = math_random() * two_pi
return { local xoff = math_round(distance * math_cos(angle))
x = math_round(pos.x + distance * math_cos(angle)), local yoff = math_round(distance * math_sin(angle))
y = pos.y, return vector.offset(pos, xoff, 0, yoff)
z = math_round(pos.z + distance * math_sin(angle))
}
end end
local function decypher_limits(posy) local function decypher_limits(posy)
@ -559,7 +557,7 @@ local S = minetest.get_translator("mcl_mobs")
minetest.register_chatcommand("spawn_mob",{ minetest.register_chatcommand("spawn_mob",{
privs = { debug = true }, privs = { debug = true },
description=S("spawn_mob is a chatcommand that allows you to type in the name of a mob without 'typing mobs_mc:' all the time like so; 'spawn_mob spider'. however, there is more you can do with this special command, currently you can edit any number, boolian, and string variable you choose with this format: spawn_mob 'any_mob:var<mobs_variable=variable_value>:'. any_mob being your mob of choice, mobs_variable being the variable, and variable value being the value of the chosen variable. and example of this format: \n spawn_mob skeleton:var<passive=true>:\n this would spawn a skeleton that wouldn't attack you. REMEMBER-THIS> when changing a number value always prefix it with 'NUM', example: \n spawn_mob skeleton:var<jump_height=NUM10>:\n this setting the skelly's jump height to 10. if you want to make multiple changes to a mob, you can, example: \n spawn_mob skeleton:var<passive=true>::var<jump_height=NUM10>::var<fly_in=air>::var<fly=true>:\n etc."), description=S("spawn_mob is a chatcommand that allows you to type in the name of a mob without 'typing mobs_mc:' all the time like so; 'spawn_mob spider'. however, there is more you can do with this special command, currently you can edit any number, boolean, and string variable you choose with this format: spawn_mob 'any_mob:var<mobs_variable=variable_value>:'. any_mob being your mob of choice, mobs_variable being the variable, and variable value being the value of the chosen variable. and example of this format: \n spawn_mob skeleton:var<passive=true>:\n this would spawn a skeleton that wouldn't attack you. REMEMBER-THIS> when changing a number value always prefix it with 'NUM', example: \n spawn_mob skeleton:var<jump_height=NUM10>:\n this setting the skelly's jump height to 10. if you want to make multiple changes to a mob, you can, example: \n spawn_mob skeleton:var<passive=true>::var<jump_height=NUM10>::var<fly_in=air>::var<fly=true>:\n etc."),
func = function(n,param) func = function(n,param)
local pos = minetest.get_player_by_name(n):get_pos() local pos = minetest.get_player_by_name(n):get_pos()
@ -579,15 +577,14 @@ minetest.register_chatcommand("spawn_mob",{
local mob = mcl_mobs.spawn(pos,mobname) local mob = mcl_mobs.spawn(pos,mobname)
for c=1, #modifiers do if mob then
modifs = modifiers[c] for c=1, #modifiers do
modifs = modifiers[c]
local mod1 = string.find(modifs, ":") local mod1 = string.find(modifs, ":")
local mod_start = string.find(modifs, "<") local mod_start = string.find(modifs, "<")
local mod_vals = string.find(modifs, "=") local mod_vals = string.find(modifs, "=")
local mod_end = string.find(modifs, ">") local mod_end = string.find(modifs, ">")
local mod_end = string.find(modifs, ">")
if mob then
local mob_entity = mob:get_luaentity() local mob_entity = mob:get_luaentity()
if string.sub(modifs, mod1+1, mod1+3) == "var" then if string.sub(modifs, mod1+1, mod1+3) == "var" then
if mod1 and mod_start and mod_vals and mod_end then if mod1 and mod_start and mod_vals and mod_end then
@ -618,14 +615,12 @@ minetest.register_chatcommand("spawn_mob",{
minetest.log("warning", n.." couldn't modify "..mobname.." at "..minetest.pos_to_string(pos).. ", missing modification type") minetest.log("warning", n.." couldn't modify "..mobname.." at "..minetest.pos_to_string(pos).. ", missing modification type")
end end
end end
end
if mob then
return true, mobname.." spawned at "..minetest.pos_to_string(pos),
minetest.log("action", n.." spawned "..mobname.." at "..minetest.pos_to_string(pos)) minetest.log("action", n.." spawned "..mobname.." at "..minetest.pos_to_string(pos))
return true, mobname.." spawned at "..minetest.pos_to_string(pos)
else
return false, "Couldn't spawn "..mobname
end end
return false, "Couldn't spawn "..mobname
end end
}) })

View File

@ -12,7 +12,7 @@ local cow_def = {
xp_min = 1, xp_min = 1,
xp_max = 3, xp_max = 3,
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.39, 0.45}, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.39, 0.45},
spawn_in_group = 8, spawn_in_group = 4,
spawn_in_group_min = 3, spawn_in_group_min = 3,
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_cow.b3d", mesh = "mobs_mc_cow.b3d",

View File

@ -2,4 +2,4 @@ name = mobs_mc
author = maikerumine author = maikerumine
description = Adds Minecraft-like monsters and animals. description = Adds Minecraft-like monsters and animals.
depends = mcl_init, mcl_particles, mcl_mobs, mcl_wip, mcl_core, mcl_util depends = mcl_init, mcl_particles, mcl_mobs, mcl_wip, mcl_core, mcl_util
optional_depends = default, mcl_tnt, mcl_bows, mcl_throwing, mcl_fishing, bones, mesecons_materials, mobs_mc_gameconfig, doc_items optional_depends = default, mcl_tnt, mcl_bows, mcl_throwing, mcl_fishing, bones, mesecons_materials, doc_items

View File

@ -1,5 +1,8 @@
--License for code WTFPL and otherwise stated in readmes --License for code WTFPL and otherwise stated in readmes
-- FIXME: Slimes should spawn only in "slime chunks" which make up only
-- 10% of the map.
--
local S = minetest.get_translator("mobs_mc") local S = minetest.get_translator("mobs_mc")
-- Returns a function that spawns children in a circle around pos. -- Returns a function that spawns children in a circle around pos.
@ -7,46 +10,47 @@ local S = minetest.get_translator("mobs_mc")
-- self: mob reference -- self: mob reference
-- pos: position of "mother" mob -- pos: position of "mother" mob
-- child_mod: Mob to spawn -- child_mod: Mob to spawn
-- children_count: Number of children to spawn
-- spawn_distance: Spawn distance from "mother" mob -- spawn_distance: Spawn distance from "mother" mob
-- eject_speed: Initial speed of child mob away from "mother" mob -- eject_speed: Initial speed of child mob away from "mother" mob
local spawn_children_on_die = function(child_mob, children_count, spawn_distance, eject_speed) local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed)
return function(self, pos) return function(self, pos)
local angle, posadd, newpos, dir local posadd, newpos, dir
if not eject_speed then if not eject_speed then
eject_speed = 1 eject_speed = 1
end end
local mndef = minetest.registered_nodes[minetest.get_node(pos).name] local mndef = minetest.registered_nodes[minetest.get_node(pos).name]
local mother_stuck = mndef and mndef.walkable local mother_stuck = mndef and mndef.walkable
angle = math.random(0, math.pi*2) local angle = math.random(0, math.pi*2)
local children = {} local children = {}
for i=1,children_count do local spawn_count = math.random(2, 4)
dir = {x=math.cos(angle),y=0,z=math.sin(angle)} for i = 1, spawn_count do
posadd = vector.multiply(vector.normalize(dir), spawn_distance) dir = vector.new(math.cos(angle), 0, math.sin(angle))
newpos = vector.add(pos, posadd) posadd = vector.normalize(dir) * spawn_distance
newpos = pos + posadd
-- If child would end up in a wall, use position of the "mother", unless -- If child would end up in a wall, use position of the "mother", unless
-- the "mother" was stuck as well -- the "mother" was stuck as well
local speed_penalty = 1 if not mother_stuck then
local cndef = minetest.registered_nodes[minetest.get_node(newpos).name] local cndef = minetest.registered_nodes[minetest.get_node(newpos).name]
if (not mother_stuck) and cndef and cndef.walkable then if cndef and cndef.walkable then
newpos = pos newpos = pos
speed_penalty = 0.5 eject_speed = eject_speed * 0.5
end
end end
local mob = minetest.add_entity(newpos, child_mob) local mob = minetest.add_entity(newpos, child_mob)
if (not mother_stuck) then if not mother_stuck then
mob:set_velocity(vector.multiply(dir, eject_speed * speed_penalty)) mob:set_velocity(dir * eject_speed)
end end
mob:set_yaw(angle - math.pi/2) mob:set_yaw(angle - math.pi/2)
table.insert(children, mob) table.insert(children, mob)
angle = angle + (math.pi*2)/children_count angle = angle + (math.pi*2) / spawn_count
end end
-- If mother was murdered, children attack the killer after 1 second -- If mother was murdered, children attack the killer after 1 second
if self.state == "attack" then if self.state == "attack" then
minetest.after(1.0, function(children, enemy) minetest.after(1.0, function(children, enemy)
for c=1, #children do local le
local child = children[c] for c = 1, #children do
local le = child:get_luaentity() le = children[c]:get_luaentity()
if le ~= nil then if le then
le.state = "attack" le.state = "attack"
le.attack = enemy le.attack = enemy
end end
@ -106,7 +110,7 @@ local slime_big = {
jump_height = 5.2, jump_height = 5.2,
fear_height = 0, fear_height = 0,
spawn_small_alternative = "mobs_mc:slime_small", spawn_small_alternative = "mobs_mc:slime_small",
on_die = spawn_children_on_die("mobs_mc:slime_small", 4, 1.0, 1.5), on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5),
use_texture_alpha = true, use_texture_alpha = true,
} }
mcl_mobs.register_mob("mobs_mc:slime_big", slime_big) mcl_mobs.register_mob("mobs_mc:slime_big", slime_big)
@ -125,7 +129,7 @@ slime_small.walk_velocity = 1.3
slime_small.run_velocity = 1.3 slime_small.run_velocity = 1.3
slime_small.jump_height = 4.3 slime_small.jump_height = 4.3
slime_small.spawn_small_alternative = "mobs_mc:slime_tiny" slime_small.spawn_small_alternative = "mobs_mc:slime_tiny"
slime_small.on_die = spawn_children_on_die("mobs_mc:slime_tiny", 4, 0.6, 1.0) slime_small.on_die = spawn_children_on_die("mobs_mc:slime_tiny", 0.6, 1.0)
mcl_mobs.register_mob("mobs_mc:slime_small", slime_small) mcl_mobs.register_mob("mobs_mc:slime_small", slime_small)
local slime_tiny = table.copy(slime_big) local slime_tiny = table.copy(slime_big)
@ -153,140 +157,127 @@ slime_tiny.on_die = nil
mcl_mobs.register_mob("mobs_mc:slime_tiny", slime_tiny) mcl_mobs.register_mob("mobs_mc:slime_tiny", slime_tiny)
local smin = mcl_vars.mg_overworld_min local water_level = mobs_mc.water_level
local smax = mobs_mc.water_level - 23
local cave_biomes = {
"FlowerForest_underground",
"JungleEdge_underground",
"StoneBeach_underground",
"MesaBryce_underground",
"Mesa_underground",
"RoofedForest_underground",
"Jungle_underground",
"Swampland_underground",
"MushroomIsland_underground",
"BirchForest_underground",
"Plains_underground",
"MesaPlateauF_underground",
"ExtremeHills_underground",
"MegaSpruceTaiga_underground",
"BirchForestM_underground",
"SavannaM_underground",
"MesaPlateauFM_underground",
"Desert_underground",
"Savanna_underground",
"Forest_underground",
"SunflowerPlains_underground",
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"ExtremeHills+_underground",
"JungleM_underground",
"ExtremeHillsM_underground",
"JungleEdgeM_underground",
"MangroveSwamp_underground"
}
local cave_min = mcl_vars.mg_overworld_min
local cave_max = water_level - 23
local swampy_biomes = {"Swampland", "MangroveSwamp"}
local swamp_light_max = 7
local swamp_min = water_level
local swamp_max = water_level + 27
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_tiny", "mobs_mc:slime_tiny",
"overworld", "overworld",
"ground", "ground",
{ cave_biomes,
"FlowerForest_underground",
"JungleEdge_underground",
"StoneBeach_underground",
"MesaBryce_underground",
"Mesa_underground",
"RoofedForest_underground",
"Jungle_underground",
"Swampland_underground",
"MushroomIsland_underground",
"BirchForest_underground",
"Plains_underground",
"MesaPlateauF_underground",
"ExtremeHills_underground",
"MegaSpruceTaiga_underground",
"BirchForestM_underground",
"SavannaM_underground",
"MesaPlateauFM_underground",
"Desert_underground",
"Savanna_underground",
"Forest_underground",
"SunflowerPlains_underground",
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"ExtremeHills+_underground",
"JungleM_underground",
"ExtremeHillsM_underground",
"JungleEdgeM_underground",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
12000, 12000,
4, 4,
smin, cave_min,
smax) cave_max)
mcl_mobs:spawn_specific(
"mobs_mc:slime_tiny",
"overworld",
"ground",
swampy_biomes,
0,
swamp_light_max,
30,
12000,
4,
swamp_min,
swamp_max)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_small", "mobs_mc:slime_small",
"overworld", "overworld",
"ground", "ground",
{ cave_biomes,
"FlowerForest_underground",
"JungleEdge_underground",
"StoneBeach_underground",
"MesaBryce_underground",
"Mesa_underground",
"RoofedForest_underground",
"Jungle_underground",
"Swampland_underground",
"MushroomIsland_underground",
"BirchForest_underground",
"Plains_underground",
"MesaPlateauF_underground",
"ExtremeHills_underground",
"MegaSpruceTaiga_underground",
"BirchForestM_underground",
"SavannaM_underground",
"MesaPlateauFM_underground",
"Desert_underground",
"Savanna_underground",
"Forest_underground",
"SunflowerPlains_underground",
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"ExtremeHills+_underground",
"JungleM_underground",
"ExtremeHillsM_underground",
"JungleEdgeM_underground",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
8500, 8500,
4, 4,
smin, cave_min,
smax) cave_max)
mcl_mobs:spawn_specific(
"mobs_mc:slime_small",
"overworld",
"ground",
swampy_biomes,
0,
swamp_light_max,
30,
8500,
4,
swamp_min,
swamp_max)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_big", "mobs_mc:slime_big",
"overworld", "overworld",
"ground", "ground",
{ cave_biomes,
"FlowerForest_underground",
"JungleEdge_underground",
"StoneBeach_underground",
"MesaBryce_underground",
"Mesa_underground",
"RoofedForest_underground",
"Jungle_underground",
"Swampland_underground",
"MushroomIsland_underground",
"BirchForest_underground",
"Plains_underground",
"MesaPlateauF_underground",
"ExtremeHills_underground",
"MegaSpruceTaiga_underground",
"BirchForestM_underground",
"SavannaM_underground",
"MesaPlateauFM_underground",
"Desert_underground",
"Savanna_underground",
"Forest_underground",
"SunflowerPlains_underground",
"ColdTaiga_underground",
"IcePlains_underground",
"IcePlainsSpikes_underground",
"MegaTaiga_underground",
"Taiga_underground",
"ExtremeHills+_underground",
"JungleM_underground",
"ExtremeHillsM_underground",
"JungleEdgeM_underground",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
10000, 10000,
4, 4,
smin, cave_min,
smax) cave_max)
mcl_mobs:spawn_specific(
"mobs_mc:slime_big",
"overworld",
"ground",
swampy_biomes,
0,
swamp_light_max,
30,
10000,
4,
swamp_min,
swamp_max)
-- Magma cube -- Magma cube
local magma_cube_big = { local magma_cube_big = {
@ -345,7 +336,7 @@ local magma_cube_big = {
walk_chance = 0, walk_chance = 0,
fear_height = 0, fear_height = 0,
spawn_small_alternative = "mobs_mc:magma_cube_small", spawn_small_alternative = "mobs_mc:magma_cube_small",
on_die = spawn_children_on_die("mobs_mc:magma_cube_small", 3, 0.8, 1.5), on_die = spawn_children_on_die("mobs_mc:magma_cube_small", 0.8, 1.5),
fire_resistant = true, fire_resistant = true,
} }
mcl_mobs.register_mob("mobs_mc:magma_cube_big", magma_cube_big) mcl_mobs.register_mob("mobs_mc:magma_cube_big", magma_cube_big)
@ -368,7 +359,7 @@ magma_cube_small.damage = 4
magma_cube_small.reach = 2.75 magma_cube_small.reach = 2.75
magma_cube_small.armor = 66 magma_cube_small.armor = 66
magma_cube_small.spawn_small_alternative = "mobs_mc:magma_cube_tiny" magma_cube_small.spawn_small_alternative = "mobs_mc:magma_cube_tiny"
magma_cube_small.on_die = spawn_children_on_die("mobs_mc:magma_cube_tiny", 4, 0.6, 1.0) magma_cube_small.on_die = spawn_children_on_die("mobs_mc:magma_cube_tiny", 0.6, 1.0)
mcl_mobs.register_mob("mobs_mc:magma_cube_small", magma_cube_small) mcl_mobs.register_mob("mobs_mc:magma_cube_small", magma_cube_small)
local magma_cube_tiny = table.copy(magma_cube_big) local magma_cube_tiny = table.copy(magma_cube_big)
@ -394,59 +385,52 @@ magma_cube_tiny.on_die = nil
mcl_mobs.register_mob("mobs_mc:magma_cube_tiny", magma_cube_tiny) mcl_mobs.register_mob("mobs_mc:magma_cube_tiny", magma_cube_tiny)
local mmin = mcl_vars.mg_nether_min local magma_cube_biomes = {"Nether", "BasaltDelta"}
local mmax = mcl_vars.mg_nether_max local nether_min = mcl_vars.mg_nether_min
local nether_max = mcl_vars.mg_nether_max
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:magma_cube_tiny", "mobs_mc:magma_cube_tiny",
"nether", "nether",
"ground", "ground",
{ magma_cube_biomes,
"Nether",
"BasaltDelta",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
15000, 15000,
4, 4,
mmin, nether_min,
mmax) nether_max)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:magma_cube_small", "mobs_mc:magma_cube_small",
"nether", "nether",
"ground", "ground",
{ magma_cube_biomes,
"Nether",
"BasaltDelta",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
15500, 15500,
4, 4,
mmin, nether_min,
mmax) nether_max)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:magma_cube_big", "mobs_mc:magma_cube_big",
"nether", "nether",
"ground", "ground",
{ magma_cube_biomes,
"Nether",
"BasaltDelta",
},
0, 0,
minetest.LIGHT_MAX+1, minetest.LIGHT_MAX+1,
30, 30,
16000, 16000,
4, 4,
mmin, nether_min,
mmax) nether_max)
-- spawn eggs -- spawn eggs
mcl_mobs.register_egg("mobs_mc:magma_cube_big", S("Magma Cube"), "#350000", "#fcfc00") mcl_mobs.register_egg("mobs_mc:magma_cube_big", S("Magma Cube"), "#350000", "#fcfc00")
mcl_mobs.register_egg("mobs_mc:slime_big", S("Slime"), "#52a03e", "#7ebf6d") mcl_mobs.register_egg("mobs_mc:slime_big", S("Slime"), "#52a03e", "#7ebf6d")
-- FIXME: add spawn eggs for small and tiny slimes and magma cubes