From 3bbcd774dd0fa4be3018187fcdfde9a5aa7a3c42 Mon Sep 17 00:00:00 2001 From: Mortis3 <53282720+DylanDoe21@users.noreply.github.com> Date: Thu, 19 Jan 2023 22:36:30 -0500 Subject: [PATCH] spine trees in real life for more info about the system, ive left lots of margins in the code for the spine trees :) --- Tiles/Crags/Tree/SpineBottom.png | Bin 0 -> 274 bytes Tiles/Crags/Tree/SpineRibLeft.png | Bin 0 -> 651 bytes Tiles/Crags/Tree/SpineRibRight.png | Bin 0 -> 672 bytes Tiles/Crags/Tree/SpineSegments.png | Bin 0 -> 543 bytes Tiles/Crags/Tree/SpineTop.png | Bin 0 -> 450 bytes Tiles/Crags/Tree/SpineTree.cs | 376 +++++++++++++++++++++++++++++ Tiles/Crags/Tree/SpineTree.png | Bin 0 -> 327 bytes World/AstralBiome.cs | 8 +- World/BrimstoneCrag.cs | 23 +- 9 files changed, 403 insertions(+), 4 deletions(-) create mode 100644 Tiles/Crags/Tree/SpineBottom.png create mode 100644 Tiles/Crags/Tree/SpineRibLeft.png create mode 100644 Tiles/Crags/Tree/SpineRibRight.png create mode 100644 Tiles/Crags/Tree/SpineSegments.png create mode 100644 Tiles/Crags/Tree/SpineTop.png create mode 100644 Tiles/Crags/Tree/SpineTree.cs create mode 100644 Tiles/Crags/Tree/SpineTree.png diff --git a/Tiles/Crags/Tree/SpineBottom.png b/Tiles/Crags/Tree/SpineBottom.png new file mode 100644 index 0000000000000000000000000000000000000000..de8e09d927c22ada19533d1e6438ed109e333d08 GIT binary patch literal 274 zcmV+t0qy>YP)uHO!nwZZ50mNTr+#X!|E`&C`TC+Py_aWX(+SsS1b$D?_w zuHnlUz*aGetp>&RpWysj{d@tQ<({RU5X7TL2Ht!DUi;yjAmAZkYd2cmt<807*qoM6N<$f{d(kYybcN literal 0 HcmV?d00001 diff --git a/Tiles/Crags/Tree/SpineRibLeft.png b/Tiles/Crags/Tree/SpineRibLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..92403cf0e78c9e4550f24c16a891bdb088828ade GIT binary patch literal 651 zcmV;60(AX}P)Px%L`g(JRCr$Po6AbWKoo|}R=j|?uvpzG?nDqlK~QijeFfjqM-UW5ErN>Z(w1&i zsFiLNMouu3+i8+H^CvxSLL|wY`M&u(={N>6!auXK^FRNa9FIqVa0#_)j>}6NBDb(w z(RNrYmzS7GDyY4<5b1Vr_+`#DnbFZODK8c2FimA1?Omk(Q9zxslW2ExT9a87ugViy zRbgdDbDi$3idSKgX$5Sz*D^VNjE0GGB>l3fbERuuDpDxEFe2?j$|f(3UsDn(&5NB# z>B5A9;;b2IUb!MSTdQUzW@lq7vD4kx=gc{eOR6bJ^uaz`5TIyjM3(Bb|;qzg|E zkLEn@?bGgeQxccv(>JfwMEWj_8335eeDjKl%q!@=_m&8+>4__vL@8b>vSg-F27V}# zUYE~0ok-WZw|C~8M%J_@&-RVROGOq;B&Lg8Ilc_~xr+v3^Z*({<)tDg931c>X$9x|{Zr@047v8# z4HRBsB2^?Wnza$Bb7QtpTOO8oB@KEKUxzK@?spvg81P6Px%SV=@dRCr$Po6SlCF%*T{ZLt=to6@>eLTaICKlP=ieb`P8G6sP1t}RM zf%dJTYa8o{q0cWbG9@$g=uS!|?ZUOXDw9ZnoLyl524q&yn}a3SRht0m`$Dh#W)iI~ zfCR|UnzP-G5w*tH6~ zR)Dk_G*K0=_{W!t>qAeh$4aE63yJicwNerRQmlQO4XE~lT}Y%SkpO8k zXu+yt{|mWvXinGpT8%_9=KwOe=FzYW2aw1zT#Yd153aH9GH(RxsQ>@~07*qoM6N<$ Gf&c)ZLpBls literal 0 HcmV?d00001 diff --git a/Tiles/Crags/Tree/SpineSegments.png b/Tiles/Crags/Tree/SpineSegments.png new file mode 100644 index 0000000000000000000000000000000000000000..d447eedca5278b239a7e009d3a1476201045062d GIT binary patch literal 543 zcmV+)0^t3LP)Px$*GWV{RA@u(S;0yJF%Y%aVlAi#h3ZZ4CjS3Nh&RET7WAM(t@Ns}WyHMp`DT-J zx7z7t+1+IJW!}7*Njlggzu|E7`SaCcF(0t8>z%v> zsw8GIK1i@0jmEzU=XE|y-cM)m&3#+NAu(Oyz<|QV*22M@XnqP}z(aqI7*opm$!W8c z{o})ANgpq7&HcmkQ*$-tv{ejqj74fG4vbV(vVH$*a+VCmOpuGijAG`wojxX+#jTiJ zAVEwTsI7^?NVNzx$6~~?9EnOnJ2sEi92T)Q&+L0^9UF%citAxGY+kNEP>Br3w_<{r zl$xz0hUHeJ9HtbNOI3Ty6vrYKahQFy|(VK?`8&9&_YljZhZ!x6+d!wuW!O$Vx*n68dwlwx)T zM-Y>#m`w+W{8ths>^-9@tu0>VFu&%WZY!R;@<$M(m>}I*?jfeySjv4&OT00>vInGM hDt|A`IX&Px$dr3q=RA@u(nK5s|Fc5{46%~+Zha#XOYZugi!LRMVs90D#77z?=B?@9Kl9h*) z2bXg!gg7`BjYjjoYRGQ4$+bCR`mO1xi?+5PZIjNm9?>`m^xLh< zdzr8QLVqfGR(0Gs!Xg%gBjcEW$7VZB{qo!`NqnuAq5ZR2hyPeXOk!QfjVpGtE(oG= zul+%Zw1=loiMZ|eZ)ihsI-k{wbs)~FjvH6tP#1)p(=)OtVjE%@+Q5#lbF9NSWZPTQ zapQ^|t_#A!IK&zz3T=rvsh?vW$299YZX6L83&J5e@VN@-GLCsn3XjvybGM@7#u0I` zAc)5ikQGZDXVJ<6H_I|D%SvQli;f#75T|XBmt5yAx%d(FBEKAbMB>Jyw=j}xRE}LJ zRo*8bNwum~9XF0hhy}rm{L~_!A3f`@doHye@zwdT+Y4W}xJKn0Lvj4MT&N#@PMz(n s>bP;Vo3S7yQKD4^_t5XgCGPSb5eO(); + } + + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) + { + resetFrame = false; + noBreak = true; + return false; + } + + public static bool SolidTile(int i, int j) + { + return Framing.GetTileSafely(i, j).HasTile && Main.tileSolid[Framing.GetTileSafely(i, j).TileType]; + } + + public static bool SolidTopTile(int i, int j) + { + return Framing.GetTileSafely(i, j).HasTile && (Main.tileSolidTop[Framing.GetTileSafely(i, j).TileType] || + Main.tileSolid[Framing.GetTileSafely(i, j).TileType]); + } + + public static bool Spawn(int i, int j, int type = -1, int minSize = 5, int maxSize = 18, bool leaves = false, int leavesType = -1, bool saplingExists = false) + { + //set this tree to the type + //TODO: left over from my other tree system, but this can probably just be changed to an int inside this method + //too lazy right now so im leaving it as is + if (type == -1) + { + type = ModContent.TileType(); + } + + //if this tree grew from a sapling, then kill the sapling its growing from + if (saplingExists) + { + WorldGen.KillTile(i, j, false, false, true); + WorldGen.KillTile(i, j - 1, false, false, true); + } + + //set the minimum and maximum height the tree can grow to + int height = Main.rand.Next(minSize, maxSize); + for (int k = 1; k < height; ++k) + { + if (SolidTile(i, j - k)) + { + height = k - 2; + break; + } + } + + if (height < 4 || height < minSize) + { + return false; + } + + //this places the base, probably a bit weird looking here but it works + //problem is messing around with this completely broke the hell out of the tree so i refuse to modify it for now + //if someone else by some miracle can figure out how to change it, please let me know :) + bool[] extraPlaces = new bool[5]; + for (int k = -2; k <= 2; k++) + { + extraPlaces[k + 2] = false; + + if ((SolidTopTile(i + k, j + 1) || SolidTile(i + k, j + 1)) && !Framing.GetTileSafely(i + k, j).HasTile) + { + extraPlaces[k + 2] = true; + } + } + + if (!extraPlaces[1]) extraPlaces[0] = false; + if (!extraPlaces[3]) extraPlaces[4] = false; + + if (!extraPlaces[2]) + { + return false; + } + + extraPlaces = new bool[5] { false, false, true, false, false }; + + //place the actual base + for (int k = -2; k <= 2; k++) + { + if (extraPlaces[k + 2]) + { + WorldGen.PlaceTile(i + k, j, type, true); + } + else + { + continue; + } + + //always place the bottom segment on the first frame since it doesnt have variants + Framing.GetTileSafely(i + k, j).TileFrameX = 0; + Framing.GetTileSafely(i + k, j).TileFrameY = 0; + + if (!extraPlaces[1] && !extraPlaces[3] && k == 0) + { + Framing.GetTileSafely(i + k, j).TileFrameX = 0; + } + } + + int branchSegmentDelay = 0; + + for (int k = 1; k < height; k++) + { + WorldGen.PlaceTile(i, j - k, type, true); + + if (branchSegmentDelay > 0) + { + branchSegmentDelay--; + } + + //chance to place a branch segment + //also dont place branches below a certain threshold + if (Main.rand.Next(3) == 0 && branchSegmentDelay == 0 && k > 5) + { + Framing.GetTileSafely(i, j - k).TileFrameX = 3 * 18; + Framing.GetTileSafely(i, j - k).TileFrameY = (short)(Main.rand.Next(3) * 18); + branchSegmentDelay = 3; + } + //otherwise place a normal segment + else + { + Framing.GetTileSafely(i, j - k).TileFrameX = 18; + Framing.GetTileSafely(i, j - k).TileFrameY = (short)(Main.rand.Next(3) * 18); + } + + //once the top is reached, place the top segment + if (k == height - 1) + { + Framing.GetTileSafely(i, j - k).TileFrameX = 2 * 18; + Framing.GetTileSafely(i, j - k).TileFrameY = (short)(Main.rand.Next(3) * 18); + } + } + + return true; + } + + public override void NearbyEffects(int i, int j, bool closer) + { + //kill the tree tiles if there are no tiles below it + if (!Framing.GetTileSafely(i, j + 1).HasTile) + { + WorldGen.KillTile(i, j, false, false, false); + } + } + + /* + public override bool Drop(int i, int j) + { + if (Framing.GetTileSafely(i, j).TileFrameX == 36) + { + //drop the custom seeds for this tree + int totalSeeds = Main.rand.Next(1, 3); + for (int numSeed = 0; numSeed < totalSeeds; numSeed++) + { + Item.NewItem(new EntitySource_TileBreak(i, j), (new Vector2(i, j) * 16) + new Vector2(Main.rand.Next(-46, 46), + Main.rand.Next(-40, 40) - 66), ModContent.ItemType(), Main.rand.Next(1, 5)); + } + } + + return true; + } + */ + + //this checks the entire tree from bottom to top + private void CheckEntireTree(ref int x, ref int y) + { + while (Main.tile[x, y].TileType == Type) + { + y--; + } + + y++; + + if (Main.tile[x, y].TileFrameX == 16) + { + for (int k = 0; k < WorldGen.numTreeShakes; k++) + { + if (WorldGen.treeShakeX[k] == x && WorldGen.treeShakeY[k] == y) + { + return; + } + } + + WorldGen.treeShakeX[WorldGen.numTreeShakes] = x; + WorldGen.treeShakeY[WorldGen.numTreeShakes] = y; + WorldGen.numTreeShakes++; + + //this is where you can make stuff happen when the tree is shaken like in vanilla + //for example, when trees drop a fruit when you begin to break it + } + } + + public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) + { + Tile tile = Framing.GetTileSafely(i, j); + + if (fail && !effectOnly && !noItem) + { + (int x, int y) = (i, j); + CheckEntireTree(ref x, ref y); + } + + if (fail) + { + return; + } + + int belowFrame = Framing.GetTileSafely(i, j + 1).TileFrameX; + + /* + //if theres any remaining segments below the segment you broke, turn it into a stub top segment + //probably not needed for this custom tree but ill keep it here just incase + + if (belowFrame == 0 || belowFrame == 16) + { + Framing.GetTileSafely(i, j + 1).TileFrameX = 36; + } + */ + + SoundEngine.PlaySound(SoundID.DD2_SkeletonHurt, (new Vector2(i, j) * 16)); + + //here is where you can make effects happen when the tree segments break, like adding dust, dropping gore, ect + + /* + //TODO: save this since this tree will also produce bone gores when broken + Gore.NewGore(new EntitySource_TileInteraction(Main.LocalPlayer, i, j), (new Vector2(i, j - 2) * 16), + new Vector2(Main.rand.Next(-3, 3), Main.rand.Next(-3, 3)), ModContent.Find("CalamityMod/WhateverGore").Type); + */ + } + + public static Vector2 TileOffset => Lighting.LegacyEngine.Mode > 1 ? Vector2.Zero : Vector2.One * 12; + + public static Vector2 TileCustomPosition(int i, int j, Vector2? off = null) + { + return ((new Vector2(i, j) + TileOffset) * 16) - Main.screenPosition - (off ?? new Vector2(0, -2)); + } + + internal static void DrawTreeSegments(int i, int j, Texture2D tex, Rectangle? source, Vector2? offset = null, Vector2? origin = null, bool Glow = false) + { + Tile tile = Main.tile[i, j]; + Vector2 drawPos = new Vector2(i, j).ToWorldCoordinates() - Main.screenPosition + (offset ?? new Vector2(0, -2)); + Color color = Lighting.GetColor(i, j); + + Main.spriteBatch.Draw(tex, drawPos, source, Glow ? Color.White : color, 0, origin ?? source.Value.Size() / 3f, 1f, SpriteEffects.None, 0f); + } + + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) + { + Tile tile = Framing.GetTileSafely(i, j); + Color col = Lighting.GetColor(i, j); + float xOff = (float)Math.Sin((j * 19) * 0.04f) * 1.2f; + + if (xOff == 1 && (j / 4f) == 0) + { + xOff = 0; + } + + int frameSizeX = 16; + int frameSizeY = 16; + int frameOff = 0; + + Vector2 offset = new((xOff * 2) - (frameOff / 2), 0); + Vector2 pos = TileCustomPosition(i, j) - offset; + + Vector2 treeSegmentOffset = new Vector2((xOff * 2) - (frameOff / 2) + 25, 14); + Vector2 topSegmentOffset = new Vector2((xOff * 2) - (frameOff / 2) + 20, 16); + + //draw the base of the tree + if (Framing.GetTileSafely(i, j).TileFrameX == 0) + { + Texture2D segmentTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineBottom").Value; + + Vector2 actualPosition = pos - new Vector2(8, 0); + + spriteBatch.Draw(segmentTex, actualPosition, new Rectangle(tile.TileFrameX, tile.TileFrameY, frameSizeX + 16, frameSizeY + 4), + new Color(col.R, col.G, col.B, 255), 0f, new Vector2(0, 0), 1f, SpriteEffects.None, 0f); + } + + //draw the different segments of the tree + if (Framing.GetTileSafely(i, j).TileFrameX == 18) + { + Texture2D segmentTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineSegments").Value; + int frame = tile.TileFrameY / 18; + + DrawTreeSegments(i, j, segmentTex, new Rectangle(34 * frame, 0, 32, 20), TileOffset.ToWorldCoordinates(), treeSegmentOffset, false); + } + + //draw branch segments + if (Framing.GetTileSafely(i, j).TileFrameX == 54) + { + int frame = tile.TileFrameY / 18; + + //branch drawing stuff + Texture2D leftBranchTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineRibLeft").Value; + Texture2D rightBranchTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineRibRight").Value; + + Vector2 leftBranchOffset = new Vector2((xOff * 2) - (frameOff / 2) + 50, 14); + Vector2 rightBranchOffset = new Vector2((xOff * 2) - (frameOff / 2) + 4, 14); + + //ok so, terraria just does not want to cooperate when i draw a single branch texture on the side of the tree segments + //i changed them into a horitonzal sheet with blanks in it so it gives the illusion of branches being random + //not a good idea if branches are meant to be separate tiles, but here they are purely visual so it doesnt matter + DrawTreeSegments(i, j, leftBranchTex, new Rectangle(38 * frame, 0, 38, 40), TileOffset.ToWorldCoordinates(), leftBranchOffset, false); + DrawTreeSegments(i, j, rightBranchTex, new Rectangle(38 * frame, 0, 38, 40), TileOffset.ToWorldCoordinates(), rightBranchOffset, false); + + //draw segments + Texture2D segmentTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineSegments").Value; + + DrawTreeSegments(i, j, segmentTex, new Rectangle(34 * frame, 0, 32, 20), TileOffset.ToWorldCoordinates(), treeSegmentOffset, false); + } + + //draw top segment + if (Framing.GetTileSafely(i, j).TileFrameX == 36) + { + Texture2D topTex = ModContent.Request("CalamityMod/Tiles/Crags/Tree/SpineTop").Value; + int frame = tile.TileFrameY / 18; + + DrawTreeSegments(i, j, topTex, new Rectangle(26 * frame, 0, 24, 24), TileOffset.ToWorldCoordinates(), topSegmentOffset, false); + } + + return false; + } + + /* + //this is where you can draw any glowmasks, if needed + //literally all you have to do is copy all the code from predraw and just get the glowmask textures instead of the regular ones + public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + { + } + */ + } +} \ No newline at end of file diff --git a/Tiles/Crags/Tree/SpineTree.png b/Tiles/Crags/Tree/SpineTree.png new file mode 100644 index 0000000000000000000000000000000000000000..940dc94972cfd14f01962f45ddde9ef52206a2fb GIT binary patch literal 327 zcmeAS@N?(olHy`uVBq!ia0vp^9zbly!3HE#j^6(Uq!^2X+?^QKos)S9WHWlYIEG|6 zzrDRs^pJrF>xD2yL!Sd$7GVqrxhzst*J&#xu*$49U}WoTa%R!8efa0ZonJK{J>qUx zd;PzqcQ5v+skQyD_n+?8gqlA8vS+E~@3R4>>3euG&wbjkZdS2<+~qlO4nOZIE;zJO za6&^#KpDTr%R?6hCN$Wvr+#l>KMH2==?1c=Uj?!QUNeRU1PFTzbM0Iv%#bF0^Miui zk>-kkC(jNxR|xPwa-8_?ful_a`^N$yX#Qpo@z6-C~!~~BX>h~4t zOj^S~LA%Ix-3il6awkN0Duq9hddc^sD`uj0QEv%5P~zXDnYWo;KAyKz>}p+Lx0Z_` VrMd6+d|=2hc)I$ztaD0e0sx}_i~#@u literal 0 HcmV?d00001 diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index 12d54b5b84..9990ba9897 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -137,6 +137,7 @@ namespace CalamityMod.World while (y < Main.maxTilesY) { //check to place the astral meteor on valid tiles, place automatically on ebonstone walls, and avoid platforms + //TODO: at this point just make a list of invalid tiles the meteor cannot be placed on if (((Main.tile[x, y].HasTile && Main.tileSolid[(int)Main.tile[x, y].TileType]) || Main.tile[x, y].WallType == 3) && !TileID.Sets.Platforms[Main.tile[x, y].TileType]) { int suitableTiles = 0; @@ -454,11 +455,12 @@ namespace CalamityMod.World // WorldGen.gen prevents NewItem from working, and thus prevents a bunch of dumb items from being spawned immediately and deleting the WoF/Aureus loot in the process. WorldGen.gen = true; + // Add the average height of a tree to the Y position to offset trees usually messing with the calculation. + // Then also add 10 blocks because these things seem to always like to appear standing on the floor. + int finalVerticalOffset = 18; bool place = true; int xOffset = WorldGen.dungeonX < Main.maxTilesX / 2 ? WorldGen.genRand.Next(-80, -40) : WorldGen.genRand.Next(40, 80); - bool _ = true; - //TODO: fix weird issue where it decides to place too high up randomly - SchematicManager.PlaceSchematic>(SchematicManager.AstralBeaconKey, new Point(i + xOffset, (int)height + 25), SchematicAnchor.Center, ref _); + SchematicManager.PlaceSchematic>(SchematicManager.AstralBeaconKey, new Point(i + xOffset, (int)height + finalVerticalOffset), SchematicAnchor.Center, ref place); WorldGen.gen = false; } } diff --git a/World/BrimstoneCrag.cs b/World/BrimstoneCrag.cs index aa98778461..4e218c7a79 100644 --- a/World/BrimstoneCrag.cs +++ b/World/BrimstoneCrag.cs @@ -1,5 +1,6 @@ using CalamityMod.Tiles.Crags; using CalamityMod.Tiles.Crags.Spike; +using CalamityMod.Tiles.Crags.Tree; using CalamityMod.Tiles.Ores; using CalamityMod.Walls; using CalamityMod.Schematics; @@ -26,6 +27,8 @@ namespace CalamityMod.World static int lavaLakePlaceDelay = 0; static int lavaLakeBigPlaceDelay = 0; + static int TreeDelay = 0; + //basic terrain (sorry for the excessive amount of loops lmao) private static void GenCrags() { @@ -273,8 +276,11 @@ namespace CalamityMod.World { for (int y = Main.maxTilesY - 200; y <= Main.maxTilesY - 5; y++) { + Tile tile = Main.tile[x, y]; + Tile tileUp = Main.tile[x, y - 1]; + //stalactites and stalagmites - if (Main.tile[x, y].TileType == ModContent.TileType()) + if (tile.TileType == ModContent.TileType()) { if (WorldGen.genRand.Next(32) == 0) { @@ -311,6 +317,20 @@ namespace CalamityMod.World WorldGen.PlaceObject(x, y - 1, WorldGen.genRand.Next(Stalagmites)); } + + //decrease tree delay + if (TreeDelay > 0) + { + TreeDelay--; + } + + //grow spine tree + //TODO: why are they still spawning in lava i literally checked for liquid please terraria why + if (WorldGen.genRand.Next(12) == 0 && tileUp.LiquidAmount == 0 && !tile.IsHalfBlock && TreeDelay == 0) + { + SpineTree.Spawn(x, y - 1, -1, 22, 28, false, -1, false); + TreeDelay = 12; + } } } } @@ -344,6 +364,7 @@ namespace CalamityMod.World { contents.RemoveAt(0); contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); + contents.Insert(1, new ChestItem(ItemID.HellstoneBar, WorldGen.genRand.Next(2, 5))); //temporary fix since removing the first item also removes hellstone bars } for (int i = 0; i < contents.Count; i++)