1
0
Fork 0

Merge pull request 'Implementing slime mapblocks!' (#3551) from slime_chunk into master

Reviewed-on: MineClone2/MineClone2#3551
Reviewed-by: Nicu <kneekoo@noreply.git.minetest.land>
This commit is contained in:
ancientmarinerdev 2023-03-19 02:57:41 +00:00
commit 23f0c9a83e
2 changed files with 151 additions and 29 deletions

View File

@ -535,14 +535,14 @@ end
function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light) function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)
table.insert(non_spawn_dictionary, mob_name) table.insert(non_spawn_dictionary, mob_name)
non_spawn_dictionary[mob_name] = { non_spawn_dictionary[mob_name] = {
[dimension] = { [dimension] = {
min_light = min_light , max_light = max_light min_light = min_light , max_light = max_light
} }
} }
end end
function mcl_mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_light, max_light, interval, chance, aoc, min_height, max_height, day_toggle, on_spawn) function mcl_mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_light, max_light, interval, chance, aoc, min_height, max_height, day_toggle, on_spawn, check_position)
-- Do mobs spawn at all? -- Do mobs spawn at all?
if not mobs_spawn then if not mobs_spawn then
@ -579,6 +579,7 @@ function mcl_mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_
spawn_dictionary[key]["min_height"] = min_height spawn_dictionary[key]["min_height"] = min_height
spawn_dictionary[key]["max_height"] = max_height spawn_dictionary[key]["max_height"] = max_height
spawn_dictionary[key]["day_toggle"] = day_toggle spawn_dictionary[key]["day_toggle"] = day_toggle
spawn_dictionary[key]["check_position"] = check_position
summary_chance = summary_chance + chance summary_chance = summary_chance + chance
end end
@ -653,14 +654,17 @@ end
local function spawn_check(pos, spawn_def) local function spawn_check(pos, spawn_def)
if not spawn_def then return end if not spawn_def or not pos then return end
dbg_spawn_attempts = dbg_spawn_attempts + 1 dbg_spawn_attempts = dbg_spawn_attempts + 1
local dimension = mcl_worlds.pos_to_dimension(pos) local dimension = mcl_worlds.pos_to_dimension(pos)
local mob_def = minetest.registered_entities[spawn_def.name] local mob_def = minetest.registered_entities[spawn_def.name]
local mob_type = mob_def.type local mob_type = mob_def.type
local gotten_node = get_node(pos).name local gotten_node = get_node(pos).name
local gotten_biome = minetest.get_biome_data(pos) local gotten_biome = minetest.get_biome_data(pos)
if not gotten_node or not gotten_biome then return end if not gotten_node or not gotten_biome then return end
gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with
local is_ground = minetest.get_item_group(gotten_node,"solid") ~= 0 local is_ground = minetest.get_item_group(gotten_node,"solid") ~= 0
@ -676,24 +680,37 @@ local function spawn_check(pos, spawn_def)
local is_bedrock = gotten_node == "mcl_core:bedrock" local is_bedrock = gotten_node == "mcl_core:bedrock"
local is_grass = minetest.get_item_group(gotten_node,"grass_block") ~= 0 local is_grass = minetest.get_item_group(gotten_node,"grass_block") ~= 0
if pos and spawn_def if pos.y >= spawn_def.min_height
and pos.y >= spawn_def.min_height and pos.y <= spawn_def.max_height
and pos.y <= spawn_def.max_height and spawn_def.dimension == dimension
and spawn_def.dimension == dimension and biome_check(spawn_def.biomes, gotten_biome) then
and biome_check(spawn_def.biomes, gotten_biome)
and (is_ground or spawn_def.type_of_spawning ~= "ground") --mcl_log("Level 1 spawn check passed")
and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) --minetest.log("Mob: " .. mob_def.name)
and has_room(mob_def,pos)
and (spawn_def.check_position and spawn_def.check_position(pos) or true) if (is_ground or spawn_def.type_of_spawning ~= "ground")
and (not is_farm_animal(spawn_def.name) or is_grass) and (spawn_def.type_of_spawning ~= "ground" or not is_leaf)
and (spawn_def.type_of_spawning ~= "water" or is_water) and (not is_farm_animal(spawn_def.name) or is_grass)
and ( not spawn_protected or not minetest.is_protected(pos, "") ) and (spawn_def.type_of_spawning ~= "water" or is_water)
and not is_bedrock then and not is_bedrock
--only need to poll for node light if everything else worked and has_room(mob_def,pos)
local gotten_light = get_node_light(pos) and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil)
if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then and ( not spawn_protected or not minetest.is_protected(pos, "") ) then
return true
--mcl_log("Level 2 spawn check passed")
local gotten_light = get_node_light(pos)
if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then
--mcl_log("Level 3 spawn check passed")
return true
else
mcl_log("Spawn check level 3 failed")
end
else
mcl_log("Spawn check level 2 failed")
end end
else
mcl_log("Spawn check level 1 failed")
end end
return false return false
end end
@ -1014,7 +1031,7 @@ if mobs_spawn then
end end
end end
else else
mcl_log("Spawn check failed") --mcl_log("Spawn check failed")
end end
else else
mcl_log("Cap space full") mcl_log("Cap space full")

View File

@ -1,10 +1,111 @@
--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")
local MAPBLOCK_SIZE = 16
local seed = minetest.get_mapgen_setting("seed")
local slime_chunk_match
local x_modifier
local z_modifier
local function split_by_char (inputstr, sep, limit)
if sep == nil then
sep = "%d"
end
local t = {}
local i = 0
for str in string.gmatch(inputstr, "(["..sep.."])") do
i = i --+ 1
table.insert(t, tonumber(str))
if limit and i >= limit then
break
end
end
return t
end
--Seed: "16002933932875202103" == random seed
--Seed: "1807191622654296300" == cheese
--Seed: "1" = 1
local function process_seed (seed)
--minetest.log("seed: " .. seed)
local split_chars = split_by_char(tostring(seed), nil, 10)
slime_chunk_match = split_chars[1]
x_modifier = split_chars[2]
z_modifier = split_chars[3]
--minetest.log("x_modifier: " .. tostring(x_modifier))
--minetest.log("z_modifier: " .. tostring(z_modifier))
--minetest.log("slime_chunk_match: " .. tostring(slime_chunk_match))
end
local processed = process_seed (seed)
local function convert_to_chunk_value (co_ord, modifier)
local converted = math.floor(math.abs(co_ord) / MAPBLOCK_SIZE)
if modifier then
converted = (converted + modifier)
end
converted = converted % 10
--minetest.log("co_ord: " .. co_ord)
--minetest.log("converted: " .. converted)
return converted
end
assert(convert_to_chunk_value(-16) == 1, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(-15) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(-1) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(0) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(1) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(15) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(16) == 1, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(31) == 1, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(32) == 2, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(1599) == 9, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(1600) == 0, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(0,9) == 9, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(16,5) == 6, "Incorrect convert_to_chunk_value result")
assert(convert_to_chunk_value(1599,4) == 3, "Incorrect convert_to_chunk_value result")
local function calculate_chunk_value (pos, x_mod, z_mod)
local chunk_val = math.abs(convert_to_chunk_value(pos.x, x_mod) - convert_to_chunk_value(pos.z, z_mod)) % 10
return chunk_val
end
assert(calculate_chunk_value(vector.new(0,0,0)) == 0, "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(0,0,0), 1, 1) == 0, "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(0,0,0), 2, 1) == 1, "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(64,0,16)) == (4-1), "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(16,0,64)) == (3), "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(-160,0,-160)) == 0, "calculate_chunk_value failed")
local function is_slime_chunk(pos)
if not pos then return end
local chunk_val = calculate_chunk_value (pos, x_modifier, z_modifier)
local slime_chunk = chunk_val == slime_chunk_match
--minetest.log("x: " ..pos.x .. ", z:" .. pos.z)
--minetest.log("seed slime_chunk_match: " .. tostring(slime_chunk_match))
--minetest.log("chunk_val: " .. tostring(chunk_val))
--minetest.log("Is slime chunk: " .. tostring(slime_chunk))
return slime_chunk
end
local check_position = function (pos)
return is_slime_chunk(pos)
end
-- Returns a function that spawns children in a circle around pos. -- Returns a function that spawns children in a circle around pos.
-- To be used as on_die callback. -- To be used as on_die callback.
-- self: mob reference -- self: mob reference
@ -212,7 +313,8 @@ minetest.LIGHT_MAX+1,
12000, 12000,
4, 4,
cave_min, cave_min,
cave_max) cave_max,
nil, nil, check_position)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_tiny", "mobs_mc:slime_tiny",
@ -238,7 +340,8 @@ minetest.LIGHT_MAX+1,
8500, 8500,
4, 4,
cave_min, cave_min,
cave_max) cave_max,
nil, nil, check_position)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_small", "mobs_mc:slime_small",
@ -264,7 +367,8 @@ minetest.LIGHT_MAX+1,
10000, 10000,
4, 4,
cave_min, cave_min,
cave_max) cave_max,
nil, nil, check_position)
mcl_mobs:spawn_specific( mcl_mobs:spawn_specific(
"mobs_mc:slime_big", "mobs_mc:slime_big",
@ -278,6 +382,7 @@ swamp_light_max,
4, 4,
swamp_min, swamp_min,
swamp_max) swamp_max)
-- Magma cube -- Magma cube
local magma_cube_big = { local magma_cube_big = {
description = S("Magma Cube"), description = S("Magma Cube"),