Add in slime chunks
This commit is contained in:
parent
1182ce349a
commit
b8b47e55e1
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue