Make ShiftExistingBiomes available via API

Fixes bug with wrong new_y_min when shifting a biome below the nether floor, and makes the ShiftExistingBiomes function available to other mods via the nether global, since it's not a simple function and biomes would also need to be shifted if another mod wants to add a second nether layer.
This commit is contained in:
Treer 2021-02-13 17:30:04 +11:00
parent 54613d673a
commit db68df3596
1 changed files with 10 additions and 9 deletions

View File

@ -81,7 +81,8 @@ local math_max, math_min, math_abs, math_floor = math.max, math.min, math.abs, m
-- Inject nether_caverns biome
local function override_underground_biomes()
-- Move any existing biomes out of the y-range specified by 'floor' and 'ceiling'
mapgen.ShiftExistingBiomes = function(floor, ceiling)
-- https://forum.minetest.net/viewtopic.php?p=257522#p257522
-- Q: Is there a way to override an already-registered biome so I can get it out of the
-- way of my own underground biomes without disturbing the other biomes registered by
@ -124,21 +125,21 @@ local function override_underground_biomes()
if type(new_biome_def.y_min) == 'number' then biome_y_min = new_biome_def.y_min end
if type(new_biome_def.y_max) == 'number' then biome_y_max = new_biome_def.y_max end
if biome_y_max > NETHER_FLOOR and biome_y_min < NETHER_CEILING then
if biome_y_max > floor and biome_y_min < ceiling then
-- This biome occupies some or all of the depth of the Nether, shift/crop it.
local new_y_min, new_y_max
local spaceOccupiedAbove = biome_y_max - NETHER_CEILING
local spaceOccupiedBelow = NETHER_FLOOR - biome_y_min
local spaceOccupiedAbove = biome_y_max - ceiling
local spaceOccupiedBelow = floor - biome_y_min
if spaceOccupiedAbove >= spaceOccupiedBelow or biome_y_min <= -30000 then
-- place the biome above the Nether
-- We also shift biomes which extend to the bottom of the map above the Nether, since they
-- likely only extend that deep as a catch-all, and probably have a role nearer the surface.
new_y_min = NETHER_CEILING + 1
new_y_max = math_max(biome_y_max, NETHER_CEILING + 2)
new_y_min = ceiling + 1
new_y_max = math_max(biome_y_max, ceiling + 2)
else
-- shift the biome to below the Nether
new_y_max = NETHER_FLOOR - 1
new_y_min = math_min(biome_y_min, NETHER_CEILING - 2)
new_y_max = floor - 1
new_y_min = math_min(biome_y_min, floor - 2)
end
debugf("Moving biome \"%s\" from %s..%s to %s..%s", new_biome_def.name, new_biome_def.y_min, new_biome_def.y_max, new_y_min, new_y_max)
@ -162,7 +163,7 @@ local function override_underground_biomes()
end
-- Shift any overlapping biomes out of the way before we create the Nether biomes
override_underground_biomes()
mapgen.ShiftExistingBiomes(NETHER_FLOOR, NETHER_CEILING)
-- nether:native_mapgen is used to prevent ores and decorations being generated according
-- to landforms created by the native mapgen.