From b8b47e55e18f18606bcb05de3023a4bee4a9afc5 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 16 Mar 2023 18:04:56 +0000 Subject: [PATCH 1/4] Add in slime chunks --- mods/ENTITIES/mobs_mc/slime+magma_cube.lua | 187 ++++++++++++++++++++- 1 file changed, 184 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua index e9fa340e3..780367167 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -60,6 +60,182 @@ local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed) end end +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 + + +local seed = minetest.get_mapgen_setting("seed") +--local chunk_size = minetest.get_mapgen_setting("chunksize") + +local slime_chunk_match +local x_modifier +local z_modifier + +--Seed: "16002933932875202103" +--Seed: "1807191622654296300" == cheese +--Seed: "1" = 1 +local function process_seed (seed) + --minetest.log("chunk_size: " .. chunk_size) + minetest.log("seed: " .. seed) + + local split_chars = split_by_char(tostring(seed), nil, 10) + minetest.log("Number of chars: " .. tostring(#split_chars)) + + 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)) + -- floor(x_or_z / chunk_size) + modifier +end +local processed = process_seed (seed) +--process_seed (seed) + + +-- Seed numbers are 0 - 9. Adding 1, and doubling it converts this to 2 - 20 (even numbers). +-- This averages at roughly 10, so 1 in 10 chunks, or 10% is how frequent slime chunks are +-- We then multiply by chunk_size * 1.8 (8) to map to co-ords, because if the lowest value is 2, then multiplied by 8 gives a chunk size of 16 +-- 2 * 8 = 16 +-- 4 * 8 = 32 +-- 6 * 8 = 48 +local function convert_to_chunk_value_old (input) + local total = 0 + + if input then + for _, v in pairs(input) do + v = (v + 1) * 2 * chunk_size * 1.8 + total = total + v + minetest.log("v: " .. tostring(v)) + end + end + + minetest.log("total: " .. tostring(total)) + minetest.log("average: " .. tostring(total/10)) +end + +local MAPBLOCK_SIZE = 16 +--local MAPBLOCK_SIZE = 3 * chunk_size + +local function convert_to_chunk_value (co_ord, modifier) + local converted = math.floor(math.abs(co_ord) / MAPBLOCK_SIZE) + --minetest.log("co_ord: " .. co_ord) + + if modifier then + converted = (converted + modifier) % 10 + minetest.log("with modifier: " .. converted) + else + minetest.log("converted: " .. converted) + end + + converted = converted % 10 + minetest.log("converted: " .. converted) + return converted +end + +--assert(convert_to_chunk_value(-17) == 2, "Incorrect convert_to_chunk_value result") +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") + +-- 0, -1, -15 +-- convert_to_chunk_value_2(0) +--[[ +convert_to_chunk_value(-16) +convert_to_chunk_value(-15) +convert_to_chunk_value(-14) +convert_to_chunk_value(-1) +convert_to_chunk_value(0) +convert_to_chunk_value(1) +convert_to_chunk_value(14) +convert_to_chunk_value(15) +convert_to_chunk_value(16) +convert_to_chunk_value(29) +convert_to_chunk_value(30) +convert_to_chunk_value(31) +convert_to_chunk_value(1500,9) +convert_to_chunk_value(1501,9) +convert_to_chunk_value(1516,9) +convert_to_chunk_value(1531,9) +convert_to_chunk_value(1649,9) +]]-- + + +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 + minetest.log("chunk_val: " .. tostring(chunk_val)) + 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") +--calculate_chunk_value(vector.new(0,0,16)) +--calculate_chunk_value(vector.new(15,0,31)) +--calculate_chunk_value(vector.new(32,0,32)) +--calculate_chunk_value(vector.new(15,0,15)) + + +local function is_slime_chunk(pos) + if not pos then return end + + minetest.log("x: " ..pos.x .. ", z:" .. pos.z) + + local chunk_val = calculate_chunk_value (pos, x_modifier, z_modifier) + + local slime_chunk = chunk_val == slime_chunk_match + minetest.log("Is slime chunk: " .. tostring(slime_chunk)) + return slime_chunk +end + +is_slime_chunk(vector.new(64,0,16)) +is_slime_chunk(vector.new(16,0,64)) +is_slime_chunk(vector.new(0,0,16)) +is_slime_chunk(vector.new(15,0,31)) +is_slime_chunk(vector.new(32,0,32)) +is_slime_chunk(vector.new(15,0,15)) +is_slime_chunk(vector.new(0,0,0)) +is_slime_chunk(vector.new(-150,0,-150)) + +local check_position = function (pos) + minetest.log("Trying to spawn slime at pos: " .. dump(pos)) + + local slime_chunk = is_slime_chunk(pos) + minetest.log("spawn_position check: " .. dump(slime_chunk)) + + return slime_chunk +end + -- Slime local slime_big = { description = S("Slime"), @@ -112,6 +288,7 @@ local slime_big = { spawn_small_alternative = "mobs_mc:slime_small", on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5), use_texture_alpha = true, + check_position = check_position, } mcl_mobs.register_mob("mobs_mc:slime_big", slime_big) @@ -212,7 +389,8 @@ minetest.LIGHT_MAX+1, 12000, 4, cave_min, -cave_max) +cave_max, + nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_tiny", @@ -238,7 +416,8 @@ minetest.LIGHT_MAX+1, 8500, 4, cave_min, -cave_max) +cave_max, + nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_small", @@ -264,7 +443,8 @@ minetest.LIGHT_MAX+1, 10000, 4, cave_min, -cave_max) +cave_max, + nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_big", @@ -278,6 +458,7 @@ swamp_light_max, 4, swamp_min, swamp_max) + -- Magma cube local magma_cube_big = { description = S("Magma Cube"), From e7449a65d87bb6dd97b77ed8a55318db475c8c8a Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 16 Mar 2023 19:32:43 +0000 Subject: [PATCH 2/4] Fix check_position and change spawn check to stages --- mods/ENTITIES/mcl_mobs/spawning.lua | 52 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 9182fdf9c..33b06e48c 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -535,14 +535,14 @@ end function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light) table.insert(non_spawn_dictionary, mob_name) - non_spawn_dictionary[mob_name] = { - [dimension] = { + non_spawn_dictionary[mob_name] = { + [dimension] = { min_light = min_light , max_light = max_light } } 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? 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]["max_height"] = max_height spawn_dictionary[key]["day_toggle"] = day_toggle + spawn_dictionary[key]["check_position"] = check_position summary_chance = summary_chance + chance end @@ -653,7 +654,8 @@ end 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 local dimension = mcl_worlds.pos_to_dimension(pos) local mob_def = minetest.registered_entities[spawn_def.name] @@ -676,23 +678,31 @@ local function spawn_check(pos, spawn_def) local is_bedrock = gotten_node == "mcl_core:bedrock" local is_grass = minetest.get_item_group(gotten_node,"grass_block") ~= 0 - if pos and spawn_def - and pos.y >= spawn_def.min_height - and pos.y <= spawn_def.max_height - and spawn_def.dimension == dimension - and biome_check(spawn_def.biomes, gotten_biome) - and (is_ground or spawn_def.type_of_spawning ~= "ground") - and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) - and has_room(mob_def,pos) - and (spawn_def.check_position and spawn_def.check_position(pos) or true) - and (not is_farm_animal(spawn_def.name) or is_grass) - and (spawn_def.type_of_spawning ~= "water" or is_water) - and ( not spawn_protected or not minetest.is_protected(pos, "") ) - and not is_bedrock then - --only need to poll for node light if everything else worked - local gotten_light = get_node_light(pos) - if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then - return true + if pos.y >= spawn_def.min_height + and pos.y <= spawn_def.max_height + and spawn_def.dimension == dimension + and biome_check(spawn_def.biomes, gotten_biome) then + + --minetest.log("Level 1 spawn check passed") + + minetest.log("Mob: " .. mob_def.name) + if (is_ground or spawn_def.type_of_spawning ~= "ground") + and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) + and has_room(mob_def,pos) + and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil) + and (not is_farm_animal(spawn_def.name) or is_grass) + and (spawn_def.type_of_spawning ~= "water" or is_water) + and ( not spawn_protected or not minetest.is_protected(pos, "") ) + and not is_bedrock then + + minetest.log("Level 2 spawn check passed") + + --only need to poll for node light if everything else worked + local gotten_light = get_node_light(pos) + if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then + minetest.log("Level 3 spawn check passed") + return true + end end end return false From bd579314ba3db9a06afb7d62ee0ec4dcd0dde782 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 16 Mar 2023 20:22:52 +0000 Subject: [PATCH 3/4] Remove logging and clean up --- mods/ENTITIES/mcl_mobs/spawning.lua | 27 +++--- mods/ENTITIES/mobs_mc/slime+magma_cube.lua | 100 +++++++-------------- 2 files changed, 49 insertions(+), 78 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 33b06e48c..be8e1028e 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -662,7 +662,9 @@ local function spawn_check(pos, spawn_def) local mob_type = mob_def.type local gotten_node = get_node(pos).name local gotten_biome = minetest.get_biome_data(pos) + 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 local is_ground = minetest.get_item_group(gotten_node,"solid") ~= 0 @@ -683,27 +685,32 @@ local function spawn_check(pos, spawn_def) and spawn_def.dimension == dimension and biome_check(spawn_def.biomes, gotten_biome) then - --minetest.log("Level 1 spawn check passed") + --mcl_log("Level 1 spawn check passed") + --minetest.log("Mob: " .. mob_def.name) - minetest.log("Mob: " .. mob_def.name) if (is_ground or spawn_def.type_of_spawning ~= "ground") and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) - and has_room(mob_def,pos) - and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil) and (not is_farm_animal(spawn_def.name) or is_grass) and (spawn_def.type_of_spawning ~= "water" or is_water) - and ( not spawn_protected or not minetest.is_protected(pos, "") ) - and not is_bedrock then + and not is_bedrock + and has_room(mob_def,pos) + and (spawn_def.check_position and spawn_def.check_position(pos) or spawn_def.check_position == nil) + and ( not spawn_protected or not minetest.is_protected(pos, "") ) then - minetest.log("Level 2 spawn check passed") + --mcl_log("Level 2 spawn check passed") - --only need to poll for node light if everything else worked local gotten_light = get_node_light(pos) if gotten_light >= spawn_def.min_light and gotten_light <= spawn_def.max_light then - minetest.log("Level 3 spawn check passed") + --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 + else + mcl_log("Spawn check level 1 failed") end return false end @@ -1024,7 +1031,7 @@ if mobs_spawn then end end else - mcl_log("Spawn check failed") + --mcl_log("Spawn check failed") end else mcl_log("Cap space full") diff --git a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua index 780367167..7c6eb85a8 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -81,57 +81,33 @@ end local seed = minetest.get_mapgen_setting("seed") --local chunk_size = minetest.get_mapgen_setting("chunksize") +local MAPBLOCK_SIZE = 16 +--local MAPBLOCK_SIZE = 3 * chunk_size + local slime_chunk_match local x_modifier local z_modifier ---Seed: "16002933932875202103" +--Seed: "16002933932875202103" == random seed --Seed: "1807191622654296300" == cheese --Seed: "1" = 1 local function process_seed (seed) --minetest.log("chunk_size: " .. chunk_size) - minetest.log("seed: " .. seed) + --minetest.log("seed: " .. seed) local split_chars = split_by_char(tostring(seed), nil, 10) - minetest.log("Number of chars: " .. tostring(#split_chars)) + --minetest.log("Number of chars: " .. tostring(#split_chars)) 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)) - -- floor(x_or_z / chunk_size) + modifier + --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) ---process_seed (seed) - - --- Seed numbers are 0 - 9. Adding 1, and doubling it converts this to 2 - 20 (even numbers). --- This averages at roughly 10, so 1 in 10 chunks, or 10% is how frequent slime chunks are --- We then multiply by chunk_size * 1.8 (8) to map to co-ords, because if the lowest value is 2, then multiplied by 8 gives a chunk size of 16 --- 2 * 8 = 16 --- 4 * 8 = 32 --- 6 * 8 = 48 -local function convert_to_chunk_value_old (input) - local total = 0 - - if input then - for _, v in pairs(input) do - v = (v + 1) * 2 * chunk_size * 1.8 - total = total + v - minetest.log("v: " .. tostring(v)) - end - end - - minetest.log("total: " .. tostring(total)) - minetest.log("average: " .. tostring(total/10)) -end - -local MAPBLOCK_SIZE = 16 ---local MAPBLOCK_SIZE = 3 * chunk_size local function convert_to_chunk_value (co_ord, modifier) local converted = math.floor(math.abs(co_ord) / MAPBLOCK_SIZE) @@ -139,13 +115,13 @@ local function convert_to_chunk_value (co_ord, modifier) if modifier then converted = (converted + modifier) % 10 - minetest.log("with modifier: " .. converted) + --minetest.log("with modifier: " .. converted) else - minetest.log("converted: " .. converted) + --minetest.log("converted: " .. converted) end converted = converted % 10 - minetest.log("converted: " .. converted) + --minetest.log("converted: " .. converted) return converted end @@ -164,22 +140,9 @@ assert(convert_to_chunk_value(1600) == 0, "Incorrect convert_to_chunk_value resu 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") --- 0, -1, -15 --- convert_to_chunk_value_2(0) --[[ -convert_to_chunk_value(-16) -convert_to_chunk_value(-15) -convert_to_chunk_value(-14) -convert_to_chunk_value(-1) -convert_to_chunk_value(0) -convert_to_chunk_value(1) -convert_to_chunk_value(14) -convert_to_chunk_value(15) -convert_to_chunk_value(16) -convert_to_chunk_value(29) -convert_to_chunk_value(30) -convert_to_chunk_value(31) convert_to_chunk_value(1500,9) convert_to_chunk_value(1501,9) convert_to_chunk_value(1516,9) @@ -190,7 +153,6 @@ convert_to_chunk_value(1649,9) 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 - minetest.log("chunk_val: " .. tostring(chunk_val)) return chunk_val end @@ -209,29 +171,31 @@ assert(calculate_chunk_value(vector.new(-160,0,-160)) == 0, "calculate_chunk_val local function is_slime_chunk(pos) if not pos then return end - minetest.log("x: " ..pos.x .. ", z:" .. pos.z) + --minetest.log("x: " ..pos.x .. ", z:" .. pos.z) local chunk_val = calculate_chunk_value (pos, x_modifier, z_modifier) - local slime_chunk = chunk_val == slime_chunk_match - minetest.log("Is slime chunk: " .. tostring(slime_chunk)) + + --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 -is_slime_chunk(vector.new(64,0,16)) -is_slime_chunk(vector.new(16,0,64)) -is_slime_chunk(vector.new(0,0,16)) -is_slime_chunk(vector.new(15,0,31)) -is_slime_chunk(vector.new(32,0,32)) -is_slime_chunk(vector.new(15,0,15)) -is_slime_chunk(vector.new(0,0,0)) -is_slime_chunk(vector.new(-150,0,-150)) +--is_slime_chunk(vector.new(64,0,16)) +--is_slime_chunk(vector.new(16,0,64)) +--is_slime_chunk(vector.new(0,0,16)) +--is_slime_chunk(vector.new(15,0,31)) +--is_slime_chunk(vector.new(32,0,32)) +--is_slime_chunk(vector.new(15,0,15)) +--is_slime_chunk(vector.new(0,0,0)) +--is_slime_chunk(vector.new(-150,0,-150)) local check_position = function (pos) - minetest.log("Trying to spawn slime at pos: " .. dump(pos)) + --minetest.log("Trying to spawn slime at pos: " .. dump(pos)) local slime_chunk = is_slime_chunk(pos) - minetest.log("spawn_position check: " .. dump(slime_chunk)) + --minetest.log("Slime spawn_position check: " .. dump(slime_chunk)) return slime_chunk end @@ -390,7 +354,7 @@ minetest.LIGHT_MAX+1, 4, cave_min, cave_max, - nil, nil, check_position) +nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_tiny", @@ -417,7 +381,7 @@ minetest.LIGHT_MAX+1, 4, cave_min, cave_max, - nil, nil, check_position) +nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_small", @@ -444,7 +408,7 @@ minetest.LIGHT_MAX+1, 4, cave_min, cave_max, - nil, nil, check_position) +nil, nil, check_position) mcl_mobs:spawn_specific( "mobs_mc:slime_big", From 81a258d33be284c9500b1937d255c3961bbbcff9 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 16 Mar 2023 21:38:27 +0000 Subject: [PATCH 4/4] Clean up and reorder code --- mods/ENTITIES/mobs_mc/slime+magma_cube.lua | 250 +++++++++------------ 1 file changed, 105 insertions(+), 145 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua index 7c6eb85a8..85f1d36c8 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -1,10 +1,111 @@ --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 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. -- To be used as on_die callback. -- self: mob reference @@ -60,146 +161,6 @@ local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed) end end -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 - - -local seed = minetest.get_mapgen_setting("seed") ---local chunk_size = minetest.get_mapgen_setting("chunksize") - -local MAPBLOCK_SIZE = 16 ---local MAPBLOCK_SIZE = 3 * chunk_size - -local slime_chunk_match -local x_modifier -local z_modifier - ---Seed: "16002933932875202103" == random seed ---Seed: "1807191622654296300" == cheese ---Seed: "1" = 1 -local function process_seed (seed) - --minetest.log("chunk_size: " .. chunk_size) - --minetest.log("seed: " .. seed) - - local split_chars = split_by_char(tostring(seed), nil, 10) - --minetest.log("Number of chars: " .. tostring(#split_chars)) - - 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) - --minetest.log("co_ord: " .. co_ord) - - if modifier then - converted = (converted + modifier) % 10 - --minetest.log("with modifier: " .. converted) - else - --minetest.log("converted: " .. converted) - end - - converted = converted % 10 - --minetest.log("converted: " .. converted) - return converted -end - ---assert(convert_to_chunk_value(-17) == 2, "Incorrect convert_to_chunk_value result") -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") - ---[[ -convert_to_chunk_value(1500,9) -convert_to_chunk_value(1501,9) -convert_to_chunk_value(1516,9) -convert_to_chunk_value(1531,9) -convert_to_chunk_value(1649,9) -]]-- - - -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") ---calculate_chunk_value(vector.new(0,0,16)) ---calculate_chunk_value(vector.new(15,0,31)) ---calculate_chunk_value(vector.new(32,0,32)) ---calculate_chunk_value(vector.new(15,0,15)) - - -local function is_slime_chunk(pos) - if not pos then return end - - --minetest.log("x: " ..pos.x .. ", z:" .. pos.z) - - local chunk_val = calculate_chunk_value (pos, x_modifier, z_modifier) - local slime_chunk = chunk_val == slime_chunk_match - - --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 - ---is_slime_chunk(vector.new(64,0,16)) ---is_slime_chunk(vector.new(16,0,64)) ---is_slime_chunk(vector.new(0,0,16)) ---is_slime_chunk(vector.new(15,0,31)) ---is_slime_chunk(vector.new(32,0,32)) ---is_slime_chunk(vector.new(15,0,15)) ---is_slime_chunk(vector.new(0,0,0)) ---is_slime_chunk(vector.new(-150,0,-150)) - -local check_position = function (pos) - --minetest.log("Trying to spawn slime at pos: " .. dump(pos)) - - local slime_chunk = is_slime_chunk(pos) - --minetest.log("Slime spawn_position check: " .. dump(slime_chunk)) - - return slime_chunk -end - -- Slime local slime_big = { description = S("Slime"), @@ -252,7 +213,6 @@ local slime_big = { spawn_small_alternative = "mobs_mc:slime_small", on_die = spawn_children_on_die("mobs_mc:slime_small", 1.0, 1.5), use_texture_alpha = true, - check_position = check_position, } mcl_mobs.register_mob("mobs_mc:slime_big", slime_big)