Base stuff. Very unpolished

This commit is contained in:
Dominic authored and Ozzatron committed 2023-02-25 15:34:34 -05:00
1 parent 9994d62bd3
commit 48b40b9e1c
26 files changed
+1030 -2

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Backgrounds
{
public class FloralParadiseBGStyle : ModUgBgStyle
{
public override bool ChooseBgStyle() => Main.LocalPlayer.InFloralParadise();
public override void FillTextureArray(int[] textureSlots)
{
// Corresponds to underground jungle backgrounds. Something custom could probably be made, but for what it is it works sufficiently for the minibiome.
for (int i = 0; i <= 3; i++)
textureSlots[i] = i + 153;
}
}
}
+1
View File
@@ -1021,6 +1021,7 @@ namespace CalamityMod.CalPlayer
public bool ZoneAbyssLayer2 => Player.InModBiome(ModContent.GetInstance<AbyssLayer2Biome>());
public bool ZoneAbyssLayer3 => Player.InModBiome(ModContent.GetInstance<AbyssLayer3Biome>());
public bool ZoneAbyssLayer4 => Player.InModBiome(ModContent.GetInstance<AbyssLayer4Biome>());
public bool ZoneFloralParadise = false;
public bool abyssDeath = false;
public int abyssBreathCD;
public float caveDarkness = 0f;
+65
View File
@@ -0,0 +1,65 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Environment
{
public class WaterAlgae : ModProjectile
{
public ref float Direction => ref projectile.ai[0];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Algae");
Main.projFrames[projectile.type] = 3;
ProjectileID.Sets.CanDistortWater[projectile.type] = false;
}
public override void SetDefaults()
{
projectile.width = 12;
projectile.height = 12;
projectile.ignoreWater = true;
projectile.timeLeft = 720;
projectile.penetrate = 1;
projectile.scale = Main.rand?.NextFloat(0.4f, 0.75f) ?? 1f;
projectile.hide = true;
}
public override void AI()
{
projectile.Opacity = Utils.InverseLerp(0f, 120f, projectile.timeLeft, true) * Utils.InverseLerp(720f, 660f, projectile.timeLeft, true);
projectile.hide = projectile.Opacity < 0.2f;
if (projectile.localAI[0] == 0f)
{
projectile.frame = Main.rand.Next(Main.projFrames[projectile.type]);
projectile.localAI[0] = 1f;
}
if (Collision.WetCollision(projectile.position, projectile.width, projectile.height))
{
if (Direction == 0f)
Direction = projectile.identity % 2;
if (Collision.SolidCollision(projectile.Center + Vector2.UnitX * Direction * 100f, 1, 1))
Direction *= -1f;
projectile.velocity.X = MathHelper.Lerp(projectile.velocity.X, Direction * MathHelper.Lerp(0.3f, 0.7f, projectile.identity % 9f / 9f), 0.025f);
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y - 0.008f, -0.4f, 0.4f);
}
else
{
projectile.velocity.X *= 0.985f;
projectile.velocity.Y = MathHelper.Clamp(projectile.velocity.Y + 0.1f, -1f, 5f);
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
projectile.velocity.X *= 0.5f;
if (projectile.timeLeft > 210)
projectile.timeLeft = 210;
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

+42
View File
@@ -0,0 +1,42 @@
using CalamityMod.Items.PermanentBoosters;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace CalamityMod.Tiles.FloralParadise
{
public class BloodOrangePlant : ModTile
{
public override void SetDefaults()
{
Main.tileFrameImportant[Type] = true;
Main.tileNoFail[Type] = true;
Main.tileObsidianKill[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style3x3);
TileObjectData.addTile(Type);
dustType = 6;
AddMapEntry(new Color(250, 142, 4));
base.SetDefaults();
}
public override void KillMultiTile(int i, int j, int frameX, int frameY)
{
Item.NewItem(i * 16, j * 16, 16, 16, ModContent.ItemType<BloodOrange>());
}
public override void SetDrawPositions(int i, int j, ref int width, ref int offsetY, ref int height)
{
offsetY = 2;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 4;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

+114
View File
@@ -0,0 +1,114 @@
using CalamityMod.Projectiles.Environment;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Tiles.FloralParadise
{
public class FloralGrass : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileBlockLight[Type] = true;
Main.tileBrick[Type] = true;
TileID.Sets.Grass[Type] = true;
TileID.Sets.NeedsGrassFraming[Type] = true;
TileID.Sets.NeedsGrassFramingDirt[Type] = ModContent.TileType<RichDirt>();
TileID.Sets.Conversion.Grass[Type] = true;
CalamityUtils.SetMerge(Type, TileID.Dirt);
CalamityUtils.SetMerge(Type, TileID.Grass);
CalamityUtils.SetMerge(Type, TileID.CorruptGrass);
CalamityUtils.SetMerge(Type, TileID.HallowedGrass);
CalamityUtils.SetMerge(Type, TileID.FleshGrass);
CalamityUtils.SetMerge(Type, ModContent.TileType<RichDirt>());
CalamityUtils.SetMerge(Type, ModContent.TileType<FloralStone>());
dustType = 39;
drop = ItemID.DirtBlock;
AddMapEntry(new Color(31, 99, 31));
}
public override void NumDust(int i, int j, bool fail, ref int Type)
{
Type = fail ? 1 : 3;
}
public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
{
if (fail && !effectOnly)
Main.tile[i, j].type = (ushort)ModContent.TileType<RichDirt>();
}
public override void NearbyEffects(int i, int j, bool closer)
{
if (WorldGen.genRand.NextBool(60) && !Main.gamePaused && CalamityUtils.ParanoidTileRetrieval(i, j - 1).liquid >= 200)
{
Vector2 algaeVelocity = -Vector2.UnitY.RotatedByRandom(0.91f) * Main.rand.NextFloat(0.85f, 1.6f);
Projectile.NewProjectile(new Vector2(i + 0.5f, j - 0.5f) * 16f, algaeVelocity, ModContent.ProjectileType<WaterAlgae>(), 0, 0f);
}
}
public override void RandomUpdate(int i, int j)
{
int num8 = WorldGen.genRand.Next((int)Main.rockLayer, (int)(Main.rockLayer + (double)Main.maxTilesY * 0.143));
int nearbyVineCount = 0;
for (int x = i - 15; x <= i + 15; x++)
{
for (int y = j - 15; y <= j + 15; y++)
{
if (WorldGen.InWorld(x, y))
{
if (CalamityUtils.ParanoidTileRetrieval(x, y).active() &&
CalamityUtils.ParanoidTileRetrieval(x, y).type == (ushort)ModContent.TileType<SmallVines>())
{
nearbyVineCount++;
}
}
}
}
if (Main.tile[i, j + 1] != null && nearbyVineCount < 5)
{
if (!Main.tile[i, j + 1].active() && Main.tile[i, j + 1].type != (ushort)ModContent.TileType<SmallVines>())
{
if (Main.tile[i, j + 1].liquid == 255 &&
!Main.tile[i, j + 1].lava())
{
bool flag13 = false;
for (int y = num8; y > num8 - 10; y--)
{
if (Main.tile[i, y].bottomSlope())
{
flag13 = false;
break;
}
if (Main.tile[i, y].active() && !Main.tile[i, y].bottomSlope())
{
flag13 = true;
break;
}
}
if (flag13)
{
int num53 = i;
int num54 = j + 1;
Main.tile[num53, num54].type = (ushort)ModContent.TileType<SmallVines>();
Main.tile[num53, num54].active(true);
WorldGen.SquareTileFrame(num53, num54, true);
if (Main.netMode == NetmodeID.Server)
{
NetMessage.SendTileSquare(-1, num53, num54, 3, TileChangeType.None);
}
}
Main.tile[i, j].slope(0);
Main.tile[i, j].halfBrick(false);
}
}
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

+41
View File
@@ -0,0 +1,41 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace CalamityMod.Tiles.FloralParadise
{
public class FloralPlants : ModTile
{
public override void SetDefaults()
{
Main.tileFrameImportant[Type] = true;
Main.tileNoFail[Type] = true;
Main.tileObsidianKill[Type] = true;
TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1);
TileObjectData.addTile(Type);
dustType = 2;
AddMapEntry(new Color(28, 216, 94));
base.SetDefaults();
}
public override void SetDrawPositions(int i, int j, ref int width, ref int offsetY, ref int height)
{
offsetY = 2;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 4;
}
public override void NearbyEffects(int i, int j, bool closer)
{
if (CalamityUtils.ParanoidTileRetrieval(i, j).liquid > 64)
WorldGen.KillTile(i, j);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

+42
View File
@@ -0,0 +1,42 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Tiles.FloralParadise
{
public class FloralStone : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileBlockLight[Type] = true;
Main.tileBrick[Type] = true;
TileID.Sets.Stone[Type] = true;
TileID.Sets.Conversion.Stone[Type] = true;
TileID.Sets.CanBeClearedDuringOreRunner[Type] = false;
CalamityUtils.MergeWithGeneral(Type);
CalamityUtils.MergeWithOres(Type);
CalamityUtils.SetMerge(Type, ModContent.TileType<RichDirt>());
dustType = 78;
// drop = ModContent.ItemType<FloralStoneItem>();
soundType = SoundID.Tink;
AddMapEntry(new Color(26, 73, 31));
}
public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak)
{
TileFraming.CustomMergeFrame(i, j, Type, TileID.Dirt);
return false;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 3;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

+60
View File
@@ -0,0 +1,60 @@
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Tiles.FloralParadise
{
public class RichDirt : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileBlockLight[Type] = true;
CalamityUtils.MergeWithGeneral(Type);
CalamityUtils.MergeAstralTiles(Type);
CalamityUtils.MergeWithOres(Type);
CalamityUtils.SetMerge(Type, TileID.Grass);
CalamityUtils.SetMerge(Type, TileID.CorruptGrass);
CalamityUtils.SetMerge(Type, TileID.HallowedGrass);
CalamityUtils.SetMerge(Type, TileID.FleshGrass);
CalamityUtils.SetMerge(Type, ModContent.TileType<FloralGrass>());
dustType = 38;
// drop = ModContent.ItemType<RichDirtItem>();
AddMapEntry(new Color(140, 81, 56));
TileID.Sets.ChecksForMerge[Type] = true;
TileID.Sets.CanBeClearedDuringOreRunner[Type] = true;
}
public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak)
{
TileFraming.CustomMergeFrame(i, j, Type, TileID.Dirt);
return false;
}
public override void RandomUpdate(int i, int j)
{
Tile up = Main.tile[i, j - 1];
Tile down = Main.tile[i, j + 1];
Tile left = Main.tile[i - 1, j];
Tile right = Main.tile[i + 1, j];
if (WorldGen.genRand.NextBool(3) && (up.type == ModContent.TileType<FloralGrass>() ||
down.type == ModContent.TileType<FloralGrass>() ||
left.type == ModContent.TileType<FloralGrass>() ||
right.type == ModContent.TileType<FloralGrass>()))
{
WorldGen.SpreadGrass(i, j, Type, ModContent.TileType<FloralGrass>(), false);
}
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 3;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

+94
View File
@@ -0,0 +1,94 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Tiles.FloralParadise
{
public class SmallVines : ModTile
{
public override void SetDefaults()
{
Main.tileCut[Type] = true;
Main.tileBlockLight[Type] = true;
Main.tileLavaDeath[Type] = true;
Main.tileNoFail[Type] = true;
ModTranslation name = CreateMapEntryName();
name.SetDefault("Vines");
AddMapEntry(new Color(100, 151, 31), name);
soundType = SoundID.Grass;
dustType = 2;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 3;
}
public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
{
if (WorldGen.genRand.NextBool(2) && Main.player[(int)Player.FindClosest(new Vector2((float)(i * 16), (float)(j * 16)), 16, 16)].cordage)
Item.NewItem(new Vector2(i * 16 + 8f, j * 16 + 8f), ItemID.VineRope);
if (Main.tile[i, j + 1] != null)
{
if (Main.tile[i, j + 1].active())
{
if (Main.tile[i, j + 1].type == ModContent.TileType<SmallVines>())
{
WorldGen.KillTile(i, j + 1, false, false, false);
if (!Main.tile[i, j + 1].active() && Main.netMode != NetmodeID.SinglePlayer)
{
NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)i, (float)j + 1, 0f, 0, 0, 0);
}
}
}
}
}
public override void RandomUpdate(int i, int j)
{
if (Main.tile[i, j + 1] != null)
{
if (!Main.tile[i, j + 1].active() && Main.tile[i, j + 1].type != (ushort)ModContent.TileType<SmallVines>())
{
if (Main.tile[i, j + 1].liquid >= 128 && !Main.tile[i, j + 1].lava())
{
bool flag13 = false;
for (int num52 = j; num52 > j - 10; j--)
{
if (Main.tile[i, num52].bottomSlope())
{
flag13 = false;
break;
}
if (Main.tile[i, num52].active() && !Main.tile[i, num52].bottomSlope())
{
flag13 = true;
break;
}
}
if (flag13)
{
int num53 = i;
int num54 = j + 1;
Main.tile[num53, num54].type = (ushort)ModContent.TileType<SmallVines>();
Main.tile[num53, num54].frameX = (short)(WorldGen.genRand.Next(8) * 18);
Main.tile[num53, num54].frameY = (short)(4 * 18);
Main.tile[num53, num54 - 1].frameX = (short)(WorldGen.genRand.Next(12) * 18);
Main.tile[num53, num54 - 1].frameY = (short)(WorldGen.genRand.Next(4) * 18);
Main.tile[num53, num54].active(true);
WorldGen.SquareTileFrame(num53, num54, true);
WorldGen.SquareTileFrame(num53, num54 - 1, true);
if (Main.netMode == NetmodeID.Server)
{
NetMessage.SendTileSquare(-1, num53, num54, 3, TileChangeType.None);
NetMessage.SendTileSquare(-1, num53, num54 - 1, 3, TileChangeType.None);
}
}
}
}
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

+87
View File
@@ -0,0 +1,87 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.Enums;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace CalamityMod.Tiles.FloralParadise
{
public class VigorousVines : ModTile
{
public override void SetDefaults()
{
Main.tileCut[Type] = true;
Main.tileLavaDeath[Type] = true;
Main.tileNoFail[Type] = true;
Main.tileFrameImportant[Type] = true;
ModTranslation name = CreateMapEntryName();
name.SetDefault("Vigorous Vines");
AddMapEntry(new Color(145, 203, 102), name);
TileObjectData.newTile.Width = 2;
TileObjectData.newTile.Height = 2;
TileObjectData.newTile.Origin = Point16.Zero;
TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0);
TileObjectData.newTile.UsesCustomCanPlace = true;
TileObjectData.newTile.CoordinateHeights = new[] { 16, 16 };
TileObjectData.newTile.CoordinateWidth = 16;
TileObjectData.newTile.CoordinatePadding = 2;
TileObjectData.newTile.AnchorValidTiles = new[] { ModContent.TileType<FloralGrass>() };
TileObjectData.newTile.LavaDeath = true;
TileObjectData.newTile.StyleHorizontal = true;
TileObjectData.newTile.RandomStyleRange = 2;
TileObjectData.addTile(Type);
soundType = SoundID.Grass;
dustType = 2;
}
public override void NumDust(int i, int j, bool fail, ref int num)
{
num = fail ? 1 : 3;
}
public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
{
Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j);
if (tile.frameX % 36 != 0 || tile.frameY % 36 != 0)
{
WorldGen.KillTile(i - tile.frameX % 36 / 18, j - tile.frameY % 36 / 18);
if (CalamityUtils.ParanoidTileRetrieval(i - tile.frameX % 36 / 18, j - tile.frameY % 36 / 18 - 1).type == Type)
WorldGen.KillTile(i - tile.frameX % 36 / 18, j - tile.frameY % 36 / 18 - 1);
return;
}
else if (WorldGen.genRand.NextBool(2) && Main.player[Player.FindClosest(new Vector2(i, j) * 16f, 16, 16)].cordage)
{
Item.NewItem(new Vector2(i * 16 + 24f, j * 16 + 24f), ItemID.VineRope);
}
}
public override bool PreDraw(int i, int j, SpriteBatch spriteBatch)
{
Tile t = Main.tile[i, j];
int frameX = t.frameX;
int frameY = t.frameY;
Texture2D tex = Main.tileTexture[Type];
Vector2 drawOffset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange);
Vector2 drawPosition = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + drawOffset;
Color drawColor = Lighting.GetColor(i, j);
if (!t.halfBrick() && t.slope() == 0)
spriteBatch.Draw(tex, drawPosition, new Rectangle(frameX, frameY, 18, 18), drawColor, 0f, Vector2.Zero, 1f, 0, 0f);
else if (t.halfBrick())
spriteBatch.Draw(tex, drawPosition + new Vector2(0f, 8f), new Rectangle(frameX, frameY, 18, 8), drawColor, 0f, Vector2.Zero, 1f, 0, 0f);
return false;
}
public override void RandomUpdate(int i, int j)
{
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

+5 -2
View File
@@ -1,10 +1,10 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using CalamityMod.Tiles.FloralParadise;
using System;
namespace CalamityMod.Tiles.Ores
@@ -25,6 +25,9 @@ namespace CalamityMod.Tiles.Ores
Main.tileShine2[Type] = true;
CalamityUtils.MergeWithGeneral(Type);
CalamityUtils.SetMerge(Type, ModContent.TileType<FloralGrass>());
CalamityUtils.SetMerge(Type, ModContent.TileType<FloralStone>());
CalamityUtils.SetMerge(Type, ModContent.TileType<RichDirt>());
TileID.Sets.Ore[Type] = true;
TileID.Sets.OreMergesWithMud[Type] = true;
+1
View File
@@ -294,6 +294,7 @@ namespace CalamityMod
public static bool InCalamity(this Player player) => player.Calamity().ZoneCalamity;
public static bool InSunkenSea(this Player player) => player.Calamity().ZoneSunkenSea;
public static bool InSulphur(this Player player) => player.Calamity().ZoneSulphur;
public static bool InFloralParadise(this Player player) => player.Calamity().ZoneFloralParadise;
public static bool InAstral(this Player player, int biome = 0) //1 is above ground, 2 is underground, 3 is desert
{
switch (biome)
+36
View File
@@ -0,0 +1,36 @@
using CalamityMod.CalPlayer;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Waters
{
public class FloralParadiseWater : ModWaterStyle
{
public override bool ChooseWaterStyle()
{
CalamityPlayer modPlayer = Main.LocalPlayer.Calamity();
return modPlayer.ZoneFloralParadise;
}
public override int ChooseWaterfallStyle()
{
return mod.GetWaterfallStyleSlot("FloralParadiseWaterflow");
}
public override int GetSplashDust()
{
return 33;
}
public override int GetDropletGore()
{
return 713;
}
public override Color BiomeHairColor()
{
return Color.PaleTurquoise;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

+9
View File
@@ -0,0 +1,9 @@
using Terraria.ModLoader;
namespace CalamityMod.Waters
{
public class FloralParadiseWaterflow : ModWaterfallStyle
{
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

+416
View File
@@ -0,0 +1,416 @@
using CalamityMod.Tiles.DraedonStructures;
using CalamityMod.Tiles.FloralParadise;
using CalamityMod.Tiles.SunkenSea;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.GameContent.Generation;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
namespace CalamityMod.World.Minibiomes
{
public class FloralParadiseMinibiome
{
public const int MaxHorizontalDistanceFromWorldCenter = 1250;
public const int MinSurfaceDepth = 250;
public const int MaxSurfaceDepth = 550;
public static void GenerateInstances()
{
float worldSize = Main.maxTilesX / 4200f;
int totalCaves = (int)(worldSize * 5f);
int[] blacklistedTiles = new int[]
{
TileID.Sand,
TileID.Sandstone,
TileID.HardenedSand,
TileID.DesertFossil,
TileID.SnowBlock,
TileID.IceBlock,
ModContent.TileType<LaboratoryPanels>(),
ModContent.TileType<LaboratoryPipePlating>(),
ModContent.TileType<LaboratoryPlating>(),
ModContent.TileType<HazardChevronPanels>(),
ModContent.TileType<RustedPlating>(),
ModContent.TileType<RustedPipes>(),
ModContent.TileType<Navystone>(),
ModContent.TileType<EutrophicSand>(),
};
List<Rectangle> existingCaves = new List<Rectangle>();
for (int i = 0; i < totalCaves; i++)
{
int x = Main.maxTilesX / 2 + WorldGen.genRand.Next(-MaxHorizontalDistanceFromWorldCenter, MaxHorizontalDistanceFromWorldCenter);
int y = (int)WorldGen.worldSurface + WorldGen.genRand.Next(MinSurfaceDepth, MaxSurfaceDepth);
int width = (int)(WorldGen.genRand.Next(80, 100) * worldSize);
int height = (int)(WorldGen.genRand.Next(70, 95) * worldSize);
Rectangle caveArea = Utils.CenteredRectangle(new Vector2(x, y), new Vector2(width, height));
// Try again if this selected location is near blacklisted tiles.
// This is done to prevent logical consistencies/intrusion on unrelated biomes.
bool needsToTryAgain = false;
for (int dx = -40; dx < 40; dx++)
{
for (int dy = -40; dy < 40; dy++)
{
if (!needsToTryAgain)
{
Tile tile = CalamityUtils.ParanoidTileRetrieval(x + dx, y + dy);
needsToTryAgain = tile.active() && blacklistedTiles.Contains(tile.type);
}
else
break;
}
}
if (!needsToTryAgain)
needsToTryAgain = existingCaves.Any(c => caveArea.Intersects(c));
if (needsToTryAgain)
{
i--;
continue;
}
Place(new Vector2(x, y), width, height);
existingCaves.Add(caveArea);
}
}
public static void Place(Vector2 placementCenter, int width, int height)
{
int seed = WorldGen.genRand.Next();
bool[,] caveState = new bool[width, height];
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
float noise = CalamityUtils.PerlinNoise2D(i / 180f, j / 180f, 3, seed) * 0.5f + 0.5f;
caveState[i, j] = noise >= 0.48f && noise < 0.64f;
if (WorldGen.genRand.NextBool(3))
caveState[i, j] = WorldGen.genRand.NextBool();
}
}
// Repeatedly smoothen out caves with celluar automata.
for (int i = 0; i < 12; i++)
caveState = SimulateCelluarAutomata(caveState);
// Reset tile states based on the above results.
ushort grassID = (ushort)ModContent.TileType<FloralGrass>();
ushort dirtID = (ushort)ModContent.TileType<RichDirt>();
ushort stoneID = (ushort)ModContent.TileType<FloralStone>();
bool[,] grassDirtMap = new bool[width, height];
for (int x = (int)placementCenter.X; x < (int)placementCenter.X + width; x++)
{
for (int y = (int)placementCenter.Y; y < (int)placementCenter.Y + height; y++)
{
// Don't attempt to change tile data if a tile is outside of the world for some reason.
if (!WorldGen.InWorld(x, y, 1))
continue;
int arrayRelativeX = x - (int)placementCenter.X;
int arrayRelativeY = y - (int)placementCenter.Y;
float distanceFromCenter = Vector2.Distance(new Vector2(arrayRelativeX / (float)width, arrayRelativeY / (float)height), Vector2.One * 0.5f) * 1.75f;
if (distanceFromCenter > 1f)
distanceFromCenter = 1f;
float ditherChance = Utils.InverseLerp(0.97f, 0.72f, distanceFromCenter, true);
Main.tile[x, y].wall = WallID.None;
if (WorldGen.genRand.NextFloat() < ditherChance)
{
if (!caveState[arrayRelativeX, arrayRelativeY] && distanceFromCenter < 0.7f)
Main.tile[x, y] = new Tile();
else
{
bool useGrass = CountCellsAtPosition(caveState, arrayRelativeX, arrayRelativeY, false) >= 1;
grassDirtMap[arrayRelativeX, arrayRelativeY] = useGrass;
Main.tile[x, y] = new Tile();
Main.tile[x, y].ResetToType(useGrass ? grassID : stoneID);
WorldGen.SquareTileFrame(x, y);
}
}
}
}
// Perform secondary passes that overlay dirt behind grass.
for (int i = 0; i < 2; i++)
{
for (int x = (int)placementCenter.X; x < (int)placementCenter.X + width; x++)
{
for (int y = (int)placementCenter.Y; y < (int)placementCenter.Y + height; y++)
{
int arrayRelativeX = x - (int)placementCenter.X;
int arrayRelativeY = y - (int)placementCenter.Y;
bool nearbyGrassOrDirt = false;
if (arrayRelativeX - 1 >= 0 && grassDirtMap[arrayRelativeX - 1, arrayRelativeY])
nearbyGrassOrDirt = true;
else if (arrayRelativeX + 1 < width && grassDirtMap[arrayRelativeX + 1, arrayRelativeY])
nearbyGrassOrDirt = true;
else if (arrayRelativeY - 1 >= 0 && grassDirtMap[arrayRelativeX, arrayRelativeY - 1])
nearbyGrassOrDirt = true;
else if (arrayRelativeY + 1 < height && grassDirtMap[arrayRelativeX, arrayRelativeY + 1])
nearbyGrassOrDirt = true;
bool canPerformPlacement = i == 0 || WorldGen.genRand.NextBool();
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
if (canPerformPlacement && tile.active() && tile.type == stoneID && nearbyGrassOrDirt)
Main.tile[x, y].type = dirtID;
}
}
// Reset the dirt/grass map for successive passes.
for (int x = (int)placementCenter.X; x < (int)placementCenter.X + width; x++)
{
for (int y = (int)placementCenter.Y; y < (int)placementCenter.Y + height; y++)
{
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
int arrayRelativeX = x - (int)placementCenter.X;
int arrayRelativeY = y - (int)placementCenter.Y;
grassDirtMap[arrayRelativeX, arrayRelativeY] = tile.type == grassID || tile.type == dirtID;
}
}
}
// Create walls.
for (int x = (int)placementCenter.X; x < (int)placementCenter.X + width; x++)
{
for (int y = (int)placementCenter.Y; y < (int)placementCenter.Y + height; y++)
{
float noise = CalamityUtils.PerlinNoise2D(x / 160f, y / 160f, 3, unchecked(seed - 13)) * 0.5f + 0.5f;
if (noise >= 0.42f && noise < 0.69f)
Main.tile[x, y].wall = WorldGen.genRand.NextBool(4) ? WallID.GrassUnsafe : WallID.FlowerUnsafe;
}
}
// Place big vines.
int bigVineCount = WorldGen.genRand.Next(20, 30);
for (int i = 0; i < bigVineCount; i++)
{
int x = (int)placementCenter.X + WorldGen.genRand.Next(24, width - 24);
int y = (int)placementCenter.Y + WorldGen.genRand.Next(18, height - 18);
if (!GenerateVigorousVines(x, y, WorldGen.genRand.Next(3, 12)))
{
i--;
continue;
}
}
// Place small vines.
int smallVineCount = WorldGen.genRand.Next(35, 50);
for (int i = 0; i < smallVineCount; i++)
{
int x = (int)placementCenter.X + WorldGen.genRand.Next(24, width - 24);
int y = (int)placementCenter.Y + WorldGen.genRand.Next(18, height - 18);
if (CalamityUtils.ParanoidTileRetrieval(x, y).active() || !WorldGen.SolidTile(x, y - 1))
{
i--;
continue;
}
int vineLength = WorldGen.genRand.Next(5, 12);
bool neeedsToTryAgain = false;
for (int dy = 0; dy < vineLength + 4; dy++)
{
if (CalamityUtils.ParanoidTileRetrieval(x, y + dy).active())
{
neeedsToTryAgain = true;
break;
}
}
if (neeedsToTryAgain)
{
i--;
continue;
}
for (int dy = 0; dy < vineLength; dy++)
{
Main.tile[x, y + dy].type = (ushort)ModContent.TileType<SmallVines>();
if (dy == vineLength - 1)
{
Main.tile[x, y + dy].frameX = (short)(WorldGen.genRand.Next(8) * 18);
Main.tile[x, y + dy].frameY = 72;
}
else
{
Main.tile[x, y + dy].frameX = (short)(WorldGen.genRand.Next(12) * 18);
Main.tile[x, y + dy].frameY = (short)(WorldGen.genRand.Next(4) * 18);
}
Main.tile[x, y + dy].active(true);
WorldGen.SquareTileFrame(x, y, true);
}
}
// Place small flowers everywhere.
int smallFlowerCount = WorldGen.genRand.Next(150, 200);
for (int i = 0; i < smallFlowerCount; i++)
{
int x = (int)placementCenter.X + WorldGen.genRand.Next(16, width - 16);
int y = (int)placementCenter.Y + WorldGen.genRand.Next(12, height - 12);
if (CalamityUtils.ParanoidTileRetrieval(x, y).active() || !WorldGen.SolidTile(x, y + 1))
{
i--;
continue;
}
Main.tile[x, y].type = (ushort)ModContent.TileType<FloralPlants>();
Main.tile[x, y].frameX = (short)(Utils.SelectRandom(WorldGen.genRand, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44) * 18);
Main.tile[x, y].frameY = 0;
Main.tile[x, y].active(true);
}
// Place ponds.
int pondCount = WorldGen.genRand.Next(3);
for (int i = 0; i < pondCount; i++)
{
int x = (int)placementCenter.X + WorldGen.genRand.Next(24, width - 24);
int y = (int)placementCenter.Y + WorldGen.genRand.Next(24, height - 24);
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
if (tile.active() || tile.liquid > 0)
{
i--;
continue;
}
// Go upward once an open area is found. This is where water will be created and then settled.
Point waterSpawnPoint = new Point(x, y);
for (int dy = 0; dy < 100; dy++)
{
if (CalamityUtils.ParanoidTileRetrieval(x, y - dy).active())
{
waterSpawnPoint.Y -= dy - 1;
break;
}
}
int increment = 0;
int waterCount = WorldGen.genRand.Next(180, 200);
RecursivelyFillAreaWithWater(x, y, waterCount, ref increment);
}
// Place a blood orange. THIS IS FOR TESTING PURPOSES.
for (int i = 0; i < 1; i++)
{
int x = (int)placementCenter.X + WorldGen.genRand.Next(24, width - 24);
int y = (int)placementCenter.Y + WorldGen.genRand.Next(18, height - 18);
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
if (!WorldGen.SolidTile(x, y + 1) || !WorldGen.SolidTile(x + 1, y + 1) || tile.active() || tile.liquid > 0)
{
i--;
continue;
}
for (int dx = 0; dx < 3; dx++)
{
for (int dy = 0; dy < 3; dy++)
{
Main.tile[x + dx, y + dy].type = (ushort)ModContent.TileType<BloodOrangePlant>();
Main.tile[x + dx, y + dy].frameX = (short)(dx * 18);
Main.tile[x + dx, y + dy].frameY = (short)(dy * 18);
Main.tile[x + dx, y + dy].active(true);
}
}
}
}
public static int CountCellsAtPosition(bool[,] originalMap, int x, int y, bool checkForActiveCells)
{
int count = 0;
for (int dx = -1; dx <= 1; dx++)
{
for (int dy = -1; dy <= 1; dy++)
{
// Ignore the center position.
if (dx == 0 && dy == 0)
continue;
// Ignore cells outside of the range of the map.
if (x + dx < 0 || x + dx >= originalMap.GetLength(0) || y + dy < 0 || y + dy >= originalMap.GetLength(1))
continue;
if ((originalMap[x + dx, y + dy] && checkForActiveCells) || (!originalMap[x + dx, y + dy] && !checkForActiveCells))
count++;
}
}
return count;
}
public static bool[,] SimulateCelluarAutomata(bool[,] originalMap)
{
bool[,] newMap = (bool[,])originalMap.Clone();
for (int x = 0; x < originalMap.GetLength(0); x++)
{
for (int y = 0; y < originalMap.GetLength(1); y++)
{
if (originalMap[x, y] && CountCellsAtPosition(originalMap, x, y, true) < 4)
newMap[x, y] = false;
else if (!originalMap[x, y] && CountCellsAtPosition(originalMap, x, y, true) >= 5)
newMap[x, y] = true;
}
}
return newMap;
}
public static bool GenerateVigorousVines(int x, int y, int length)
{
// Don't bother placing vines if there's no solid ground above for them to hang from.
if (!WorldGen.SolidTile(x, y - 1) || !WorldGen.SolidTile(x + 1, y - 1))
return false;
// Don't bother placing vines if there's anything obstructing their placement.
for (int dx = 0; dx < 2; dx++)
{
for (int dy = 0; dy < length * 2; dy++)
{
if (CalamityUtils.ParanoidTileRetrieval(x + dx, y + dy).active())
return false;
}
}
int xFrame = 0;
ushort vineID = (ushort)ModContent.TileType<VigorousVines>();
for (int dx = 0; dx < 2; dx++)
{
for (int dy = 0; dy < length * 2; dy++)
{
int yFrame = dy >= length * 2 - 2 ? 36 : 0;
if (dx == 0 && dy % 2 == 0)
xFrame = WorldGen.genRand.NextBool(yFrame > 0 ? 2 : 5) ? 36 : 0;
Main.tile[x + dx, y + dy].active(true);
Main.tile[x + dx, y + dy].frameX = (short)(xFrame + dx * 18);
Main.tile[x + dx, y + dy].frameY = (short)(yFrame + dy % 2 * 18);
Main.tile[x + dx, y + dy].type = vineID;
}
}
return true;
}
public static void RecursivelyFillAreaWithWater(int x, int y, int limit, ref int increment)
{
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
if (tile.active() || tile.liquid > 127)
return;
increment++;
if (increment >= limit)
return;
Main.tile[x, y].liquid = 255;
RecursivelyFillAreaWithWater(x + 1, y, limit, ref increment);
RecursivelyFillAreaWithWater(x - 1, y, limit, ref increment);
RecursivelyFillAreaWithWater(x, y + 1, limit, ref increment);
RecursivelyFillAreaWithWater(x, y - 1, limit, ref increment);
}
}
}