From 0834858812d7f9245bdf720d119c3d7fd11379b7 Mon Sep 17 00:00:00 2001 From: sunny-raindrops Date: Mon, 27 Apr 2026 17:10:21 -0700 Subject: [PATCH 1/7] Return pot functionality, non-functional teleport --- CalPlayer/CalamityPlayer.cs | 37 +++++++ Items/Potions/TheElixir.cs | 101 ++++++++++++++++++ Items/Potions/TheElixir.png | Bin 0 -> 933 bytes .../Mods.CalamityMod.Items.Potions.hjson | 9 ++ 4 files changed, 147 insertions(+) create mode 100644 Items/Potions/TheElixir.cs create mode 100644 Items/Potions/TheElixir.png diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 5c8b19da0f..730b375af2 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -69,6 +69,7 @@ using CalamityMod.Systems; using CalamityMod.Systems.Collections; using CalamityMod.Systems.Mechanic; using CalamityMod.Utilities; +using CalamityMod.Waters; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -4280,6 +4281,42 @@ namespace CalamityMod.CalPlayer return null; } + public static Vector2? GetAbyssPosition(Player player) + { + bool canSpawn = false; + int x = Main.maxTilesX; + int genLimit = x / 2; + int halfWorldXTiles = Abyss.AtLeftSideOfWorld ? genLimit - (genLimit - 135) + 35 : genLimit + (genLimit - 135) - 35; + int largerCheckRadius = 100; + int smallerCheckRadius = 50; + int y = Main.maxTilesY; + int teleportStartY = Main.remixWorld ? SulphurousSea.YStart : y - 250; + int teleportRangeY = 80; + Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings + { + mostlySolidFloor = true, + avoidAnyLiquid = false, + avoidLava = true, + avoidHurtTiles = true, + avoidWalls = false, + attemptsBeforeGivingUp = 1000, + maximumFallDistanceFromOrignalPoint = 30 + }; + + Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles - smallerCheckRadius, largerCheckRadius, teleportStartY, teleportRangeY, settings); + if (!canSpawn) + vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles - largerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings); + + if (!canSpawn) + vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles + smallerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings); + + if (canSpawn) + { + return (Vector2?)vector; + } + return null; + } + public static void ModTeleport(Player player, Vector2 pos, bool playSound = true, int style = TeleportationStyleID.RecallPotion) { bool postImmune = player.immune; diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs new file mode 100644 index 0000000000..1e5d3d3c38 --- /dev/null +++ b/Items/Potions/TheElixir.cs @@ -0,0 +1,101 @@ +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Potions +{ + public class TheElixir : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Potions"; + + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 20; + ItemID.Sets.DrinkParticleColors[Type] = new Color[3] { + new Color(159, 67, 199), + new Color(176, 147, 243), + new Color(84, 50, 185) + }; + } + + public override void SetDefaults() + { + Item.value = Item.sellPrice(silver: 2); + Item.rare = ItemRarityID.Blue; + Item.DefaultToFood(28, 51, 0, 0, true); + } + + //The player can't use The Elixir if they have Chaos State. + //This is to ensure if that it fails, they can't simply drink another to escape + public override bool CanUseItem(Player player) + { + //if (player.HasBuff(BuffID.ChaosState)) + //return false; + return base.CanUseItem(player); + } + + public override bool? UseItem(Player player) + { + if (player.whoAmI == Main.myPlayer) + { + if (Main.rand.NextBool(2)) + { + //If it fails, inflict the player with 5 seconds of Chaos State + player.AddBuff(BuffID.ChaosState, 300, true); + Vector2? abyss = CalamityPlayer.GetAbyssPosition(player); + if (!abyss.HasValue) + return false; + CalamityPlayer.ModTeleport(player, abyss.Value, false, TeleportationStyleID.TeleportationPotion); + } + //If it doesn't fail, just act like a Potion of Return + else + { + player.DoPotionOfReturnTeleportationAndSetTheComebackPoint(); + } + //Dust and Teleport sounds happen regardless of if it fails or not + Rectangle rect = player.getRect(); + int dustAmt = rect.Width * rect.Height / 5; + for (int k = 0; k < dustAmt; k++) + { + Dust dust = Dust.NewDustDirect(new Vector2(rect.X, rect.Y), rect.Width, rect.Height, DustID.TeleportationPotion); + dust.scale = Main.rand.NextFloat(0.2f, 0.7f); + if (k < 10) + dust.scale += 0.25f; + if (k < 5) + dust.scale += 0.25f; + } + for (int k = 0; k < 70; k++) + { + Dust dust = Dust.NewDustDirect(new Vector2(rect.X, rect.Y), rect.Width, rect.Height, DustID.DungeonSpirit); + dust.noGravity = true; + for (int i = 0; i < 5; i++) + { + if (Main.rand.NextBool(3)) + dust.velocity *= 0.75f; + } + if (Main.rand.NextBool(3)) + { + dust.velocity *= 2f; + dust.scale *= 1.2f; + } + if (Main.rand.NextBool(3)) + { + dust.velocity *= 2f; + dust.scale *= 1.2f; + } + if (Main.rand.NextBool()) + { + dust.fadeIn = Main.rand.NextFloat(0.75f, 1f); + dust.scale = Main.rand.NextFloat(0.25f, 0.75f); + } + dust.scale *= 0.8f; + } + SoundEngine.PlaySound(SoundID.Item6, player.Center); + } + return true; + } + } +} diff --git a/Items/Potions/TheElixir.png b/Items/Potions/TheElixir.png new file mode 100644 index 0000000000000000000000000000000000000000..1d25a72177184400560dc095f8ebccec5f0e7811 GIT binary patch literal 933 zcmV;W16urvP)Px#1ZP1_K>z@;j|==^1poj8Pf0{UR9HvdmrqDkQ543{R1jp=D#Jj~P;(K4n2Ruw zEX=_|QXJg`1xjjyS&-b^v9fpGy`d&BJE5iC1}iOkxhR#)in1z z_dNB2Iu`VveQ^2R^WK~H=6mOy``)8J)!TQGh#ERvwbp6=bGbBQR&mKmxIFAGLHx9* z6YT1|v#N7B-?2EYs%b==k&y)VWG6Rp~zI6Y%|v%iA-^nW*VE%FC`@}#s72)Z7E_BodO?vE5; z0}cNGCi^yksd*gJUXG=j+i4IKU7&4XQs6yExn0bJ+symjK+wZ?z&^*Cs6Ivi&>_U) zP-Hsorn_JvodByS2izUqqqH#)4~p~P_9DlXP`!*_Y!q^5GvpX|2Wv>0@ykY~X&DK9{(ePJvBy3zYqH z4O|N=<=TG7;}LdjIyIfiO7)U{fv=)7C8_G8R0)RK^h#IGpiOl^Fn$_zP*rP*Q>or& zUA>RUuV6V9iBma#M_n0?50x)o<3-MKELABv6{n%Val~E^=T;>BJD+2He7FfQeQRSH zvfr_}LP_<8E*=BDp8cTYR#q@^n$>m&3?=fNS<0!%HpkY}$?E4JuFjF{?_dJ)x6udU zZzi*P6G>OEt^u0S&*4P9M!S;$>0jHQPD@@`ITg1`607I08p^2}q1iZ6gI<5(5u@zO zv6b7|VQi2!)v8K)o{F0-y-d;PeCDprOnKKb<&?F0-f@`wQJhw8F9k)``?2Xr?vR!^ z5*37#^^9e|V@<1%MH5tG?NeI#-Lss`uf-mEu;_O-_c76L#U)A*GG+0400000NkvXX Hu0mjfV$#Ik literal 0 HcmV?d00001 diff --git a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson index 61bc96f190..8d6bec0c9e 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson @@ -369,6 +369,15 @@ TequilaSunrise: { ''' } +TheElixir: { + DisplayName: The Elixir + Tooltip: + ''' + Functions as a Potion of Return + Occasionally sends you... [c/AA23C4:somewhere else] + ''' +} + Vodka: { DisplayName: Vodka Tooltip: From 53e1f51c56fbe1b462170b71a1a5f71dde20edf1 Mon Sep 17 00:00:00 2001 From: Nathanael Overton Date: Tue, 28 Apr 2026 23:27:41 -0400 Subject: [PATCH 2/7] ough --- CalPlayer/CalamityPlayer.cs | 25 ++++++++++--------------- Items/Potions/TheElixir.cs | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 98f9dd93c3..dc5c607f5e 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4300,34 +4300,29 @@ namespace CalamityMod.CalPlayer bool canSpawn = false; int x = Main.maxTilesX; int genLimit = x / 2; - int halfWorldXTiles = Abyss.AtLeftSideOfWorld ? genLimit - (genLimit - 135) + 35 : genLimit + (genLimit - 135) - 35; - int largerCheckRadius = 100; - int smallerCheckRadius = 50; - int y = Main.maxTilesY; - int teleportStartY = Main.remixWorld ? SulphurousSea.YStart : y - 250; + + int abyssStartX = Abyss.AtLeftSideOfWorld ? genLimit - (genLimit - 135) + 35 : genLimit + (genLimit - 135) - 35; + int abyssXRange = 50; + + int teleportStartY = Main.remixWorld ? SulphurousSea.YStart - (int)(Main.UnderworldLayer * 0.6f) : Main.maxTilesY - 300; int teleportRangeY = 80; + Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings { - mostlySolidFloor = true, + mostlySolidFloor = false, avoidAnyLiquid = false, avoidLava = true, avoidHurtTiles = true, avoidWalls = false, attemptsBeforeGivingUp = 1000, - maximumFallDistanceFromOrignalPoint = 30 + maximumFallDistanceFromOrignalPoint = 10 }; - Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles - smallerCheckRadius, largerCheckRadius, teleportStartY, teleportRangeY, settings); - if (!canSpawn) - vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles - largerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings); - - if (!canSpawn) - vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles + smallerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings); + Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, abyssStartX, abyssXRange, teleportStartY, teleportRangeY, settings); if (canSpawn) - { return (Vector2?)vector; - } + return null; } diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index 1e5d3d3c38..5024c09e1a 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -48,7 +48,7 @@ namespace CalamityMod.Items.Potions Vector2? abyss = CalamityPlayer.GetAbyssPosition(player); if (!abyss.HasValue) return false; - CalamityPlayer.ModTeleport(player, abyss.Value, false, TeleportationStyleID.TeleportationPotion); + CalamityPlayer.ModTeleport(player, abyss.Value, false, TeleportationStyleID.RodOfDiscord); } //If it doesn't fail, just act like a Potion of Return else From 7fe67be7566d992b0fceb7380d5f5294ca8aa207 Mon Sep 17 00:00:00 2001 From: Nathanael Overton Date: Wed, 29 Apr 2026 19:15:09 -0400 Subject: [PATCH 3/7] Add dungeon tp logic --- CalPlayer/CalamityPlayer.cs | 28 +++++++++++++++++++++++ Items/Potions/TheElixir.cs | 22 ++++++++++++------ Systems/World/WorldgenManagementSystem.cs | 19 +++++++++++++++ World/DungeonArchive.cs | 3 +++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index dc5c607f5e..09d6b06b2c 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4325,6 +4325,34 @@ namespace CalamityMod.CalPlayer return null; } + public static Vector2? GetDungeonArchivePosition(Player player) + { + if (WorldgenManagementSystem.DungeonArchivePos == Point.Zero) + return null; + + bool canSpawn = false; + + // Define an area around the center to search for a valid spot to tp + int rangeX = 10; + int rangeY = 30; + int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X - rangeX; + int teleportStartY = WorldgenManagementSystem.DungeonArchivePos.Y; + + Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings + { + mostlySolidFloor = true, + avoidAnyLiquid = true, + avoidLava = true, + avoidHurtTiles = true, + avoidWalls = false, + attemptsBeforeGivingUp = 1000, + maximumFallDistanceFromOrignalPoint = 30 + }; + + Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, teleportStartX, rangeX, teleportStartY, rangeY, settings); + + return canSpawn ? vector : null; + } public static void ModTeleport(Player player, Vector2 pos, bool playSound = true, int style = TeleportationStyleID.RecallPotion) { diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index 5024c09e1a..52306d855f 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -1,4 +1,5 @@ using CalamityMod.CalPlayer; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -41,20 +42,27 @@ namespace CalamityMod.Items.Potions { if (player.whoAmI == Main.myPlayer) { - if (Main.rand.NextBool(2)) + if (Main.rand.NextBool(1)) { - //If it fails, inflict the player with 5 seconds of Chaos State player.AddBuff(BuffID.ChaosState, 300, true); - Vector2? abyss = CalamityPlayer.GetAbyssPosition(player); - if (!abyss.HasValue) + + Vector2? location; + + bool archiveStoredPositionExists = WorldgenManagementSystem.DungeonArchivePos != Point.Zero; + if (archiveStoredPositionExists && Main.rand.NextBool()) + location = CalamityPlayer.GetDungeonArchivePosition(player); + else + location = CalamityPlayer.GetAbyssPosition(player); + + if (!location.HasValue) return false; - CalamityPlayer.ModTeleport(player, abyss.Value, false, TeleportationStyleID.RodOfDiscord); + + CalamityPlayer.ModTeleport(player, location.Value, false, TeleportationStyleID.RecallPotion); } //If it doesn't fail, just act like a Potion of Return else - { player.DoPotionOfReturnTeleportationAndSetTheComebackPoint(); - } + //Dust and Teleport sounds happen regardless of if it fails or not Rectangle rect = player.getRect(); int dustAmt = rect.Width * rect.Height / 5; diff --git a/Systems/World/WorldgenManagementSystem.cs b/Systems/World/WorldgenManagementSystem.cs index 5399d037a4..0ccd7c76dc 100644 --- a/Systems/World/WorldgenManagementSystem.cs +++ b/Systems/World/WorldgenManagementSystem.cs @@ -12,6 +12,7 @@ using Terraria.GameContent.Generation; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; +using Terraria.ModLoader.IO; using Terraria.WorldBuilding; using static CalamityMod.World.CalamityWorld; @@ -19,10 +20,28 @@ namespace CalamityMod.Systems { public class WorldgenManagementSystem : ModSystem { + #region StructurePosStoring + public static Point DungeonArchivePos = Point.Zero; + + public override void SaveWorldData(TagCompound tag) + { + tag["DungeonArchivePos"] = DungeonArchivePos; + } + + public override void LoadWorldData(TagCompound tag) + { + if (tag.ContainsKey("DungeonArchivePos")) + DungeonArchivePos = tag.Get("DungeonArchivePos"); + else + DungeonArchivePos = Point.Zero; + } + #endregion + #region PreWorldGen public override void PreWorldGen() { Abyss.TotalPlacedIslandsSoFar = 0; + DungeonArchivePos = Point.Zero; //roxShrinePlaced = false; // This will only be applied at world-gen time to new worlds. diff --git a/World/DungeonArchive.cs b/World/DungeonArchive.cs index a1958e2331..59fd429795 100644 --- a/World/DungeonArchive.cs +++ b/World/DungeonArchive.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using CalamityMod.Schematics; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -72,6 +73,8 @@ namespace CalamityMod.World if (placedArchive) { + WorldgenManagementSystem.DungeonArchivePos = new Point(i, j); + bool firstItem = false; if (dungeonArchiveColor == 0) From 55fb65c39922542f48baae72825e04eee7b5b2ff Mon Sep 17 00:00:00 2001 From: Nathanael Overton Date: Wed, 29 Apr 2026 22:55:59 -0400 Subject: [PATCH 4/7] Add temple teleport logic --- CalPlayer/CalamityPlayer.cs | 42 +++++++++++++++++++++++++++++++++++-- Items/Potions/TheElixir.cs | 29 +++++++++++++++++++------ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 09d6b06b2c..f7664911f6 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4289,12 +4289,50 @@ namespace CalamityMod.CalPlayer vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles + smallerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings); if (canSpawn) - { return (Vector2?)vector; - } + return null; } + public static Vector2? GetTemplePosition(Player player) + { + int foundX = -1; + int foundY = -1; + for (int i = 0; i < Main.maxTilesX; i += 2) + { + for (int j = Main.maxTilesY - 100; j > (int)Main.worldSurface; j--) + { + Tile tile = Framing.GetTileSafely(i, j); + if (tile.HasTile && tile.TileType == TileID.LihzahrdAltar) + { + foundX = i; + foundY = j; + break; + } + } + if (foundX != -1) + break; + } + + if (foundX == -1) + return null; + + Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings + { + mostlySolidFloor = true, + avoidAnyLiquid = false, + avoidLava = true, + avoidHurtTiles = true, + avoidWalls = false, + attemptsBeforeGivingUp = 1000, + maximumFallDistanceFromOrignalPoint = 5 + }; + + // Lastly, convert to world coordinates to circumvent Vanilla preventing teleporting to the Temple + Point worldCoords = new(foundX, foundY - 3); // Offset as it spawns you in the bottom left of the tile by default + return worldCoords.ToWorldCoordinates(); + + } public static Vector2? GetAbyssPosition(Player player) { bool canSpawn = false; diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index 52306d855f..a3cdd88962 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -42,17 +42,34 @@ namespace CalamityMod.Items.Potions { if (player.whoAmI == Main.myPlayer) { - if (Main.rand.NextBool(1)) + if (Main.rand.NextBool(4)) { player.AddBuff(BuffID.ChaosState, 300, true); - Vector2? location; + Vector2? location = null; + bool archiveExists = WorldgenManagementSystem.DungeonArchivePos != Point.Zero; - bool archiveStoredPositionExists = WorldgenManagementSystem.DungeonArchivePos != Point.Zero; - if (archiveStoredPositionExists && Main.rand.NextBool()) - location = CalamityPlayer.GetDungeonArchivePosition(player); + // If archive has a valid position stored: 0 = Archive, 1 = Abyss, 2 = Temple + // Otherwise 0 = Abyss, 1 = Temple + int choices = archiveExists ? 3 : 2; + int roll = Main.rand.Next(choices); + + if (archiveExists) + { + if (roll == 0) + location = CalamityPlayer.GetDungeonArchivePosition(player); + else if (roll == 1) + location = CalamityPlayer.GetAbyssPosition(player); + else + location = CalamityPlayer.GetTemplePosition(player); + } else - location = CalamityPlayer.GetAbyssPosition(player); + { + if (roll == 0) + location = CalamityPlayer.GetAbyssPosition(player); + else + location = CalamityPlayer.GetTemplePosition(player); + } if (!location.HasValue) return false; From 5d0338b324e15ec414fa4c4388a4e387d8fc5c18 Mon Sep 17 00:00:00 2001 From: fryzahh Date: Thu, 30 Apr 2026 01:31:46 -0400 Subject: [PATCH 5/7] Cleanup, adjustments and fixes * Updated GetDungeonArchivesPosition to search for the archives manually on worlds where DungeonArchivesPos isn't saved. Subsequently updated The Elixir item itself to allow the archives to be searched on any world. * the Elixir now teleports the player to any random position in the Lihzhard Temple instead of just at the Lihzhard Altar. * Cleaned up some code in the new CalamityPlayer methods and TheElixir. --- CalPlayer/CalamityPlayer.cs | 195 +++++++++++++++++++++++++++--------- Items/Potions/TheElixir.cs | 42 +++----- 2 files changed, 160 insertions(+), 77 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index f7664911f6..b071c077dd 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4293,53 +4293,92 @@ namespace CalamityMod.CalPlayer return null; } + + // For The Elixir random teleportation mechanic. + // Same applies for GetDungeonArchivesPosition and GetAbyssPosition. public static Vector2? GetTemplePosition(Player player) { int foundX = -1; int foundY = -1; + bool dungeonOnRightSide = Main.dungeonX > Main.spawnTileX; + int xSearchEnd = dungeonOnRightSide ? 20 : Main.maxTilesX - 20; - for (int i = 0; i < Main.maxTilesX; i += 2) + if (dungeonOnRightSide) { - for (int j = Main.maxTilesY - 100; j > (int)Main.worldSurface; j--) + for (int i = Main.spawnTileX; i >= xSearchEnd; i -= 2) { - Tile tile = Framing.GetTileSafely(i, j); - if (tile.HasTile && tile.TileType == TileID.LihzahrdAltar) + for (int j = (int)Main.worldSurface; j < Main.maxTilesY - 210; j++) { - foundX = i; - foundY = j; - break; + Tile tile = Framing.GetTileSafely(i, j); + if (tile.HasTile && tile.TileType == TileID.LihzahrdAltar) + { + foundX = i; + foundY = j; + break; + } } + if (foundX != -1) + break; + } + } + else + { + for (int i = Main.spawnTileX; i <= xSearchEnd; i += 2) + { + for (int j = (int)Main.worldSurface; j < Main.maxTilesY - 210; j++) + { + Tile tile = Framing.GetTileSafely(i, j); + if (tile.WallType == WallID.LihzahrdBrickUnsafe) + { + foundX = i; + foundY = j; + break; + } + } + if (foundX != -1) + break; } - if (foundX != -1) - break; } if (foundX == -1) return null; - Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings + int attempts = 25; + int rangeX = 300; + int rangeY = 300; + int randomFluff = 500; + Point finalTeleportPoint = Point.Zero; + for (int i = 0; i < attempts; i++) { - mostlySolidFloor = true, - avoidAnyLiquid = false, - avoidLava = true, - avoidHurtTiles = true, - avoidWalls = false, - attemptsBeforeGivingUp = 1000, - maximumFallDistanceFromOrignalPoint = 5 - }; + for (int x = 0; x <= rangeX; x++) + { + for (int y = 0; y <= rangeY; y++) + { + int teleportPosX = foundX + x + Main.rand.Next(-randomFluff, randomFluff); + int teleportPosY = foundY + y + Main.rand.Next(-randomFluff, randomFluff); + Tile tile = Framing.GetTileSafely(teleportPosX, teleportPosY); + Tile tileAbove = Framing.GetTileSafely(teleportPosX, teleportPosY - 1); + Tile tileBelow = Framing.GetTileSafely(teleportPosX, teleportPosY + 1); - // Lastly, convert to world coordinates to circumvent Vanilla preventing teleporting to the Temple - Point worldCoords = new(foundX, foundY - 3); // Offset as it spawns you in the bottom left of the tile by default - return worldCoords.ToWorldCoordinates(); + if (!tileAbove.HasTile && tileBelow.HasTile && tile.WallType == WallID.LihzahrdBrickUnsafe) + { + finalTeleportPoint = new(tile.X(), tile.Y()); + if (!Collision.SolidCollision(finalTeleportPoint.ToWorldCoordinates(), player.width, player.height)) + break; + } + } + } + } + return finalTeleportPoint.ToWorldCoordinates() - new Vector2(player.width, player.height); } + public static Vector2? GetAbyssPosition(Player player) { bool canSpawn = false; - int x = Main.maxTilesX; - int genLimit = x / 2; + int halfWorldWidth = Main.maxTilesX / 2; - int abyssStartX = Abyss.AtLeftSideOfWorld ? genLimit - (genLimit - 135) + 35 : genLimit + (genLimit - 135) - 35; + int abyssStartX = Abyss.AtLeftSideOfWorld ? halfWorldWidth - (halfWorldWidth - 135) + 35 : halfWorldWidth + (halfWorldWidth - 135) - 35; int abyssXRange = 50; int teleportStartY = Main.remixWorld ? SulphurousSea.YStart - (int)(Main.UnderworldLayer * 0.6f) : Main.maxTilesY - 300; @@ -4356,40 +4395,98 @@ namespace CalamityMod.CalPlayer maximumFallDistanceFromOrignalPoint = 10 }; - Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, abyssStartX, abyssXRange, teleportStartY, teleportRangeY, settings); - - if (canSpawn) - return (Vector2?)vector; - - return null; + Vector2 teleportPosition = player.CheckForGoodTeleportationSpot(ref canSpawn, abyssStartX, abyssXRange, teleportStartY, teleportRangeY, settings); + return canSpawn ? teleportPosition : null; } + public static Vector2? GetDungeonArchivePosition(Player player) { - if (WorldgenManagementSystem.DungeonArchivePos == Point.Zero) - return null; - - bool canSpawn = false; - // Define an area around the center to search for a valid spot to tp - int rangeX = 10; - int rangeY = 30; - int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X - rangeX; + int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X; int teleportStartY = WorldgenManagementSystem.DungeonArchivePos.Y; - Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings + // Manually search for the Archives from the bottom of the world if the Archive position isn't saved. + if (WorldgenManagementSystem.DungeonArchivePos == Point.Zero) { - mostlySolidFloor = true, - avoidAnyLiquid = true, - avoidLava = true, - avoidHurtTiles = true, - avoidWalls = false, - attemptsBeforeGivingUp = 1000, - maximumFallDistanceFromOrignalPoint = 30 - }; + int foundX = -1; + int foundY = -1; + bool dungeonOnRightSide = Main.dungeonX > Main.spawnTileX; + int xSearchStart = dungeonOnRightSide ? Main.maxTilesX - 20 : 20; - Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, teleportStartX, rangeX, teleportStartY, rangeY, settings); + if (dungeonOnRightSide) + { + for (int y = Main.UnderworldLayer; y > (int)Main.rockLayer; y--) + { + for (int x = xSearchStart; x >= Main.maxTilesX / 2; x -= 2) + { + Tile tile = Framing.GetTileSafely(x, y); + if (Main.wallDungeon[tile.WallType] && Main.tileDungeon[tile.TileType]) + { + foundX = x; + foundY = y; + break; + } + } - return canSpawn ? vector : null; + if (foundY != -1) + break; + } + } + else + { + for (int y = Main.UnderworldLayer; y > (int)Main.rockLayer; y--) + { + for (int x = xSearchStart; x <= Main.maxTilesX / 2; x += 2) + { + Tile tile = Framing.GetTileSafely(x, y); + if (Main.wallDungeon[tile.WallType] && Main.tileDungeon[tile.TileType]) + { + foundX = x; + foundY = y; + break; + } + } + + if (foundY != -1) + break; + } + } + + if (foundY == -1) + return null; + + teleportStartX = foundX; + teleportStartY = foundY; + } + + int attempts = 25; + int rangeX = 100; + int rangeY = 200; + int randomFluff = 60; + Point finalTeleportPoint = Point.Zero; + for (int i = 0; i < attempts; i++) + { + for (int x = -rangeX; x <= rangeX; x++) + { + for (int y = 0; y <= rangeY; y++) + { + int teleportPosX = teleportStartX + x + Main.rand.Next(-randomFluff, randomFluff); + int teleportPosY = teleportStartY + y + Main.rand.Next(-randomFluff, randomFluff); + Tile tile = Framing.GetTileSafely(teleportPosX, teleportPosY); + Tile tileAbove = Framing.GetTileSafely(teleportPosX, teleportPosY - 1); + Tile tileBelow = Framing.GetTileSafely(teleportPosX, teleportPosY + 1); + + if (!tileAbove.HasTile && tileBelow.HasUnactuatedTile && Main.wallDungeon[tile.WallType]) + { + finalTeleportPoint = new(tile.X(), tile.Y()); + if (!Collision.SolidCollision(finalTeleportPoint.ToWorldCoordinates(), player.width, player.height)) + break; + } + } + } + } + + return finalTeleportPoint.ToWorldCoordinates() - new Vector2(player.width, player.height); } public static void ModTeleport(Player player, Vector2 pos, bool playSound = true, int style = TeleportationStyleID.RecallPotion) diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index a3cdd88962..0a8d49d0da 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -29,12 +29,14 @@ namespace CalamityMod.Items.Potions Item.DefaultToFood(28, 51, 0, 0, true); } - //The player can't use The Elixir if they have Chaos State. - //This is to ensure if that it fails, they can't simply drink another to escape + // Player is unable to use the item when Chaos State is enabled to prevent spamming the item. + // Even though the item also inflicts Cursed, this is kept as a failsafe in the event the player has something equipped that + // provides immunity to Cursed. (i.e Countercurse Mantra or Nazar) public override bool CanUseItem(Player player) { - //if (player.HasBuff(BuffID.ChaosState)) - //return false; + if (player.HasBuff(BuffID.ChaosState)) + return false; + return base.CanUseItem(player); } @@ -44,32 +46,16 @@ namespace CalamityMod.Items.Potions { if (Main.rand.NextBool(4)) { - player.AddBuff(BuffID.ChaosState, 300, true); + player.AddBuff(BuffID.ChaosState, 300); + player.AddBuff(BuffID.Cursed, 300); - Vector2? location = null; - bool archiveExists = WorldgenManagementSystem.DungeonArchivePos != Point.Zero; - - // If archive has a valid position stored: 0 = Archive, 1 = Abyss, 2 = Temple - // Otherwise 0 = Abyss, 1 = Temple - int choices = archiveExists ? 3 : 2; - int roll = Main.rand.Next(choices); - - if (archiveExists) + int roll = Main.rand.Next(3); + Vector2? location = roll switch { - if (roll == 0) - location = CalamityPlayer.GetDungeonArchivePosition(player); - else if (roll == 1) - location = CalamityPlayer.GetAbyssPosition(player); - else - location = CalamityPlayer.GetTemplePosition(player); - } - else - { - if (roll == 0) - location = CalamityPlayer.GetAbyssPosition(player); - else - location = CalamityPlayer.GetTemplePosition(player); - } + 1 => CalamityPlayer.GetAbyssPosition(player), + 2 => CalamityPlayer.GetTemplePosition(player), + _ => CalamityPlayer.GetDungeonArchivePosition(player) + }; if (!location.HasValue) return false; From e5b46c813ddf46d25f95e8fcac302456abd5ec74 Mon Sep 17 00:00:00 2001 From: fryzahh Date: Thu, 30 Apr 2026 18:35:58 -0400 Subject: [PATCH 6/7] Lihzhard temple check fix * Changed a check when searching for the Lihzhard Temple on the left side of the world that was erroneously checking if the tile at a specified coordinate was the Lihzhard Altar rather than just Unsafe Lihzhard Brick Wall --- CalPlayer/CalamityPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index b071c077dd..adad2c1b86 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4310,7 +4310,7 @@ namespace CalamityMod.CalPlayer for (int j = (int)Main.worldSurface; j < Main.maxTilesY - 210; j++) { Tile tile = Framing.GetTileSafely(i, j); - if (tile.HasTile && tile.TileType == TileID.LihzahrdAltar) + if (tile.WallType == WallID.LihzahrdBrickUnsafe) { foundX = i; foundY = j; From 923e7541e342b2059c950de9fb8db9aca6a5db95 Mon Sep 17 00:00:00 2001 From: fryzahh Date: Thu, 30 Apr 2026 19:14:47 -0400 Subject: [PATCH 7/7] Debuff application fix and better documentation * Cursed and Chaos State will no longer be applied if The Elixir fails to find a suitable location to teleport the player to. * Renamed GetAbyssPosition, GetDungeonArchivePosition and GetTemplePosition to GetAbyssVoidTeleportPosition, GetDungeonArchivesTeleportPosition and GetTempleTeleportPosition respectively. * Added documentation comments to each of the teleport functions. --- CalPlayer/CalamityPlayer.cs | 21 ++++++++++++++++----- Items/Potions/TheElixir.cs | 11 +++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index adad2c1b86..6180468703 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4294,9 +4294,11 @@ namespace CalamityMod.CalPlayer return null; } - // For The Elixir random teleportation mechanic. - // Same applies for GetDungeonArchivesPosition and GetAbyssPosition. - public static Vector2? GetTemplePosition(Player player) + /// + /// Returns a random position in the Lihzhard Temple to teleport the player to.

+ /// Used primarily for . + ///
+ public static Vector2? GetTempleTeleportPosition(Player player) { int foundX = -1; int foundY = -1; @@ -4335,6 +4337,7 @@ namespace CalamityMod.CalPlayer break; } } + if (foundX != -1) break; } @@ -4373,7 +4376,11 @@ namespace CalamityMod.CalPlayer return finalTeleportPoint.ToWorldCoordinates() - new Vector2(player.width, player.height); } - public static Vector2? GetAbyssPosition(Player player) + /// + /// Returns a random position in the Void (Abyss Layer 4) to teleport the player to.

+ /// Used primarily for . + ///
+ public static Vector2? GetAbyssVoidTeleportPosition(Player player) { bool canSpawn = false; int halfWorldWidth = Main.maxTilesX / 2; @@ -4399,7 +4406,11 @@ namespace CalamityMod.CalPlayer return canSpawn ? teleportPosition : null; } - public static Vector2? GetDungeonArchivePosition(Player player) + /// + /// Returns a random position in the Forsaken Archives to teleport the player to.

+ /// Used primarily for . + ///
+ public static Vector2? GetDungeonArchivesTeleportPosition(Player player) { // Define an area around the center to search for a valid spot to tp int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X; diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index 0a8d49d0da..9a18138074 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -46,20 +46,19 @@ namespace CalamityMod.Items.Potions { if (Main.rand.NextBool(4)) { - player.AddBuff(BuffID.ChaosState, 300); - player.AddBuff(BuffID.Cursed, 300); - int roll = Main.rand.Next(3); Vector2? location = roll switch { - 1 => CalamityPlayer.GetAbyssPosition(player), - 2 => CalamityPlayer.GetTemplePosition(player), - _ => CalamityPlayer.GetDungeonArchivePosition(player) + 1 => CalamityPlayer.GetAbyssVoidTeleportPosition(player), + 2 => CalamityPlayer.GetTempleTeleportPosition(player), + _ => CalamityPlayer.GetDungeonArchivesTeleportPosition(player) }; if (!location.HasValue) return false; + player.AddBuff(BuffID.ChaosState, 300, false); + player.AddBuff(BuffID.Cursed, 300, false); CalamityPlayer.ModTeleport(player, location.Value, false, TeleportationStyleID.RecallPotion); } //If it doesn't fail, just act like a Potion of Return