From cc72eaca806fabae4d4604a42b0becf0956b9643 Mon Sep 17 00:00:00 2001 From: DylanDoe21 Date: Tue, 5 Mar 2024 23:20:40 -0500 Subject: [PATCH] Fixes so far (I have not tested them yet) --- World/UndergroundShrines.cs | 2 +- World/VernalPass.cs | 42 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/World/UndergroundShrines.cs b/World/UndergroundShrines.cs index 56e2d98ce4..d109e2340b 100644 --- a/World/UndergroundShrines.cs +++ b/World/UndergroundShrines.cs @@ -357,7 +357,7 @@ namespace CalamityMod.World for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) { Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); - if (ShouldAvoidLocation(new Point(x, y))) + if (ShouldAvoidLocation(new Point(x, y), false)) canGenerateInLocation = false; //The granite geode is supposed to fully float in free air. No tile replacements diff --git a/World/VernalPass.cs b/World/VernalPass.cs index 302a9ea44f..e2659b77ec 100644 --- a/World/VernalPass.cs +++ b/World/VernalPass.cs @@ -18,7 +18,30 @@ namespace CalamityMod.World var schematic = TileMaps[mapKey]; int placementPositionX = WorldGen.genRand.Next(GenVars.tLeft, GenVars.tRight); - int placementPositionY = GenVars.tTop < Main.rockLayer - 10 ? GenVars.tBottom + 120 : GenVars.tTop - 120; + + //initialPlacementPositionY is the exact same variable as placementPositionY, but it is used to store the original starting position of the vernal pass + //this is to prevent any cases of infinite looping in the loop below when the vernal pass y-position is increased/decreased to move away from the temple and find a valid position + int initialPlacementPositionY = GenVars.tTop < Main.maxTilesY / 2 ? GenVars.tBottom + 150 : GenVars.tTop - 150; + int placementPositionY = GenVars.tTop < Main.maxTilesY / 2 ? GenVars.tBottom + 150 : GenVars.tTop - 150; + + //attempt to find a valid position for the biome to place in + bool foundValidPosition = false; + int attempts = 0; + + //continously place up/down until it is far enough from the temple to not destroy it + while (!foundValidPosition && attempts++ < 100000) + { + while (!NoTempleNearby(startPosX, startPosY)) + { + //increase the actual y-position the vernal pass will place at based on the starting location, if the jungle temple is too close to the initial starting location + placementPositionY += (initialPlacementPositionY < (Main.maxTilesX / 2) ? -10 : 10); + } + if (NoTempleNearby(startPosX, startPosY)) + { + foundValidPosition = true; + } + } + Point placementPoint = new Point(placementPositionX, placementPositionY); Vector2 schematicSize = new Vector2(schematic.GetLength(0), schematic.GetLength(1)); @@ -65,5 +88,22 @@ namespace CalamityMod.World chest.item[i].stack = contents[i].Stack; } } + + //determine if theres no snow blocks nearby so the biome doesnt place in the snow biome + public static bool NoTempleNearby(int X, int Y) + { + for (int i = X - 200; i < X + 200; i++) + { + for (int j = Y - 200; j < Y + 200; j++) + { + if (Main.tile[i, j].HasTile && Main.tile[i, j].TileType == TileID.LihzahrdBrick) + { + return false; + } + } + } + + return true; + } } }