204 lines
5.2 KiB
Lua

PyuTest.register_world = function (options)
local default_options = {}
local conf = {}
for k, v in pairs(options) do
conf[k] = v
end
for k, v in pairs(default_options) do
if conf[k] == nil then
conf[k] = v
end
end
if conf.y_max == nil or conf.y_min == nil then
error("Please supply 'y_max' and 'y_min' to the options table!")
end
if conf.name == nil then
error("Please supply 'name' in the options table!")
end
local World = {
name = conf.name,
y_max = conf.y_max,
y_min = conf.y_min,
biome_names = {}
}
function World:register_biome(o)
local name = conf.name .. "-" .. o.name
local cfg = PyuTest.util.tablecopy(o)
cfg.node_stone = cfg.node_stone or conf.node_stone -- Defaults to nil
cfg.node_water = cfg.node_water or "air"
minetest.register_biome(PyuTest.util.tableconcat(cfg, {
name = name,
depth_top = 0,
depth_filler = 0,
y_max = conf.y_max,
y_min = conf.y_min,
node_river_water = cfg.node_water,
node_cave_liquid = cfg.node_water,
}))
self.biome_names[#self.biome_names+1] = name
return name
end
function World:register_ore(o)
minetest.register_ore(PyuTest.util.tableconcat(o, {
y_max = conf.y_max,
y_min = conf.y_min,
}))
end
function World:register_decoration(o)
minetest.register_decoration(PyuTest.util.tableconcat(o, {
y_max = conf.y_max,
y_min = conf.y_min
}))
end
function World:create_token(name, world, color)
local average = (conf.y_max + conf.y_min) / 2
PyuTest.make_item(name, world .. " Token", {
world_token = 1
}, "pyutest-world-token.png", {
color = color,
stack_max = 16,
on_use = function (itemstack, user, pointed_thing)
local pos = user:get_pos()
local npos = vector.new(pos.x, average, pos.y)
minetest.do_item_eat(0, "", itemstack, user, pointed_thing)
local range = 1
user:set_pos(npos)
minetest.sound_play({name = "spellbook_action", gain = 1}, {pos = npos})
-- Spent hours trying to get this to work using mapblocks, just resorted to waiting a second.
minetest.after(1.2, function ()
local upos = user:get_pos()
PyuTest.dorange(upos, range, function (p)
minetest.remove_node(p)
end)
for dx = -range, range do
for dz = -range, range do
minetest.set_node(upos + vector.new(dx, -2, dz), {
name = "pyutest_blocks:obsidian_block"
})
end
end
minetest.set_node(upos + vector.new(0, -1, 0), {
name = "pyutest_blocks:light"
})
end)
end
})
end
return World
end
PyuTest.IceWorld = PyuTest.register_world({
name = "ice_world",
y_max = -1000,
y_min = -2000
})
PyuTest.IceWorld:create_token("pyutest_mapgen:ice_world_token", "Ice World", "#cbdbfc")
local icy_cavern = PyuTest.IceWorld:register_biome({
name = "icy_cavern",
node_stone = "pyutest_blocks:ice_block",
heat_point = 0,
humidity_point = 0
})
PyuTest.IceWorld:register_ore({
ore_type = "blob",
ore = "pyutest_blocks:snow_block",
wherein = "pyutest_blocks:ice_block",
clust_scarcity = 3 * 3 * 3,
clust_num_ores = 35,
clust_size = 5,
biomes = {icy_cavern},
noise_params = PyuTest.SPECIALSTONE_NOISE_PARAMS
})
PyuTest.IceWorld:register_ore({
ore_type = "blob",
ore = "pyutest_blocks:crystal_lantern_block",
wherein = "pyutest_blocks:ice_block",
clust_scarcity = 4.5 * 4.5 * 4.5,
clust_num_ores = 6,
clust_size = 5,
biomes = {icy_cavern},
noise_params = PyuTest.SPECIALSTONE_NOISE_PARAMS
})
PyuTest.SlimeWorld = PyuTest.register_world({
name = "slime_world",
y_max = -2001,
y_min = -3001
})
PyuTest.SlimeWorld:create_token("pyutest_mapgen:slime_world_token", "Slime World", "#7dbd3f")
local slimey_cavern = PyuTest.SlimeWorld:register_biome({
name = "slimey_cavern",
node_stone = "pyutest_blocks:slime_block",
heat_point = 45,
humidity_point = 0
})
PyuTest.SlimeWorld:register_ore({
ore_type = "blob",
ore = "pyutest_blocks:glowslime_block",
wherein = "pyutest_blocks:slime_block",
clust_scarcity = 4.5 * 4.5 * 4.5,
clust_num_ores = 6,
clust_size = 5,
biomes = {slimey_cavern},
noise_params = PyuTest.SPECIALSTONE_NOISE_PARAMS
})
PyuTest.LavaWorld = PyuTest.register_world({
name = "lava_world",
y_max = -3002,
y_min = -4002
})
PyuTest.LavaWorld:create_token("pyutest_mapgen:lava_world_token", "Lava World", "#511e1e")
local lava_cavern = PyuTest.LavaWorld:register_biome({
name = "lava_cavern",
node_stone = "pyutest_blocks:molten_rock_block",
heat_point = 100,
humidity_point = 0,
})
PyuTest.LavaWorld:register_ore({
ore_type = "blob",
ore = "pyutest_blocks:magma",
wherein = "pyutest_blocks:molten_rock_block",
clust_scarcity = 4.5 * 4.5 * 4.5,
clust_num_ores = 6,
clust_size = 5,
biomes = {lava_cavern},
noise_params = PyuTest.SPECIALSTONE_NOISE_PARAMS
})
PyuTest.LavaWorld:register_decoration({
deco_type = "simple",
sidelen = 16,
fill_ratio = 0.00063,
decoration = {"pyutest_blocks:lava_source"},
place_on = {"pyutest_blocks:molten_rock_block", "pyutest_blocks:magma"},
biomes = {lava_cavern},
flags = "all_ceilings"
})