Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DrawTrees()

void Terraria.GameContent.Drawing.TileDrawing.DrawTrees ( )
inlineprivate

Definition at line 6903 of file TileDrawing.cs.

6904 {
6905 Vector2 unscaledPosition = Main.Camera.UnscaledPosition;
6907 int num = 0;
6908 int num2 = _specialsCount[num];
6909 float num3 = 0.08f;
6910 float num4 = 0.06f;
6911 for (int i = 0; i < num2; i++)
6912 {
6913 Point point = _specialPositions[num][i];
6914 int x = point.X;
6915 int y = point.Y;
6916 Tile tile = Main.tile[x, y];
6917 if (tile == null || !tile.active())
6918 {
6919 continue;
6920 }
6921 ushort type = tile.type;
6922 short frameX = tile.frameX;
6923 short frameY = tile.frameY;
6924 bool flag = tile.wall > 0;
6925 WorldGen.GetTreeFoliageDataMethod getTreeFoliageDataMethod = null;
6926 try
6927 {
6928 bool flag2 = false;
6929 switch (type)
6930 {
6931 case 5:
6932 flag2 = true;
6933 getTreeFoliageDataMethod = WorldGen.GetCommonTreeFoliageData;
6934 break;
6935 case 583:
6936 case 584:
6937 case 585:
6938 case 586:
6939 case 587:
6940 case 588:
6941 case 589:
6942 flag2 = true;
6943 getTreeFoliageDataMethod = WorldGen.GetGemTreeFoliageData;
6944 break;
6945 case 596:
6946 case 616:
6947 flag2 = true;
6948 getTreeFoliageDataMethod = WorldGen.GetVanityTreeFoliageData;
6949 break;
6950 case 634:
6951 flag2 = true;
6952 getTreeFoliageDataMethod = WorldGen.GetAshTreeFoliageData;
6953 break;
6954 }
6955 if (flag2 && frameY >= 198 && frameX >= 22)
6956 {
6957 int treeFrame = WorldGen.GetTreeFrame(tile);
6958 switch (frameX)
6959 {
6960 case 22:
6961 {
6962 int treeStyle3 = 0;
6963 int topTextureFrameWidth3 = 80;
6964 int topTextureFrameHeight3 = 80;
6965 int num13 = 0;
6966 int grassPosX = x + num13;
6967 int floorY3 = y;
6969 {
6970 continue;
6971 }
6973 if (treeStyle3 == 14)
6974 {
6975 float num14 = (float)_rand.Next(28, 42) * 0.005f;
6976 num14 += (float)(270 - Main.mouseTextColor) / 1000f;
6977 if (tile.color() == 0)
6978 {
6979 Lighting.AddLight(x, y, 0.1f, 0.2f + num14 / 2f, 0.7f + num14);
6980 }
6981 else
6982 {
6983 Color color5 = WorldGen.paintColor(tile.color());
6984 float r3 = (float)(int)color5.R / 255f;
6985 float g3 = (float)(int)color5.G / 255f;
6986 float b3 = (float)(int)color5.B / 255f;
6987 Lighting.AddLight(x, y, r3, g3, b3);
6988 }
6989 }
6990 byte tileColor3 = tile.color();
6992 Vector2 vector = (vector = new Vector2(x * 16 - (int)unscaledPosition.X + 8, y * 16 - (int)unscaledPosition.Y + 16) + zero);
6993 float num15 = 0f;
6994 if (!flag)
6995 {
6997 }
6998 vector.X += num15 * 2f;
6999 vector.Y += Math.Abs(num15) * 2f;
7000 Color color6 = Lighting.GetColor(x, y);
7001 if (tile.fullbrightBlock())
7002 {
7003 color6 = Color.White;
7004 }
7006 if (type == 634)
7007 {
7008 Texture2D value3 = TextureAssets.GlowMask[316].Value;
7011 }
7012 break;
7013 }
7014 case 44:
7015 {
7016 int treeStyle2 = 0;
7017 int num9 = x;
7018 int floorY2 = y;
7019 int num10 = 1;
7021 {
7022 continue;
7023 }
7024 EmitTreeLeaves(x, y, num9 + num10, floorY2);
7025 if (treeStyle2 == 14)
7026 {
7027 float num11 = (float)_rand.Next(28, 42) * 0.005f;
7028 num11 += (float)(270 - Main.mouseTextColor) / 1000f;
7029 if (tile.color() == 0)
7030 {
7031 Lighting.AddLight(x, y, 0.1f, 0.2f + num11 / 2f, 0.7f + num11);
7032 }
7033 else
7034 {
7035 Color color3 = WorldGen.paintColor(tile.color());
7036 float r2 = (float)(int)color3.R / 255f;
7037 float g2 = (float)(int)color3.G / 255f;
7038 float b2 = (float)(int)color3.B / 255f;
7039 Lighting.AddLight(x, y, r2, g2, b2);
7040 }
7041 }
7042 byte tileColor2 = tile.color();
7044 Vector2 position2 = new Vector2(x * 16, y * 16) - unscaledPosition.Floor() + zero + new Vector2(16f, 12f);
7045 float num12 = 0f;
7046 if (!flag)
7047 {
7049 }
7050 if (num12 > 0f)
7051 {
7052 position2.X += num12;
7053 }
7054 position2.X += Math.Abs(num12) * 2f;
7055 Color color4 = Lighting.GetColor(x, y);
7056 if (tile.fullbrightBlock())
7057 {
7058 color4 = Color.White;
7059 }
7060 Main.spriteBatch.Draw(treeBranchTexture2, position2, new Rectangle(0, treeFrame * 42, 40, 40), color4, num12 * num4, new Vector2(40f, 24f), 1f, SpriteEffects.None, 0f);
7061 if (type == 634)
7062 {
7063 Texture2D value2 = TextureAssets.GlowMask[317].Value;
7065 Main.spriteBatch.Draw(value2, position2, new Rectangle(0, treeFrame * 42, 40, 40), white2, num12 * num4, new Vector2(40f, 24f), 1f, SpriteEffects.None, 0f);
7066 }
7067 break;
7068 }
7069 case 66:
7070 {
7071 int treeStyle = 0;
7072 int num5 = x;
7073 int floorY = y;
7074 int num6 = -1;
7075 if (!getTreeFoliageDataMethod(x, y, num6, ref treeFrame, ref treeStyle, out floorY, out var _, out var _))
7076 {
7077 continue;
7078 }
7079 EmitTreeLeaves(x, y, num5 + num6, floorY);
7080 if (treeStyle == 14)
7081 {
7082 float num7 = (float)_rand.Next(28, 42) * 0.005f;
7083 num7 += (float)(270 - Main.mouseTextColor) / 1000f;
7084 if (tile.color() == 0)
7085 {
7086 Lighting.AddLight(x, y, 0.1f, 0.2f + num7 / 2f, 0.7f + num7);
7087 }
7088 else
7089 {
7090 Color color = WorldGen.paintColor(tile.color());
7091 float r = (float)(int)color.R / 255f;
7092 float g = (float)(int)color.G / 255f;
7093 float b = (float)(int)color.B / 255f;
7094 Lighting.AddLight(x, y, r, g, b);
7095 }
7096 }
7097 byte tileColor = tile.color();
7098 Texture2D treeBranchTexture = GetTreeBranchTexture(treeStyle, 0, tileColor);
7099 Vector2 position = new Vector2(x * 16, y * 16) - unscaledPosition.Floor() + zero + new Vector2(0f, 18f);
7100 float num8 = 0f;
7101 if (!flag)
7102 {
7104 }
7105 if (num8 < 0f)
7106 {
7107 position.X += num8;
7108 }
7109 position.X -= Math.Abs(num8) * 2f;
7110 Color color2 = Lighting.GetColor(x, y);
7111 if (tile.fullbrightBlock())
7112 {
7113 color2 = Color.White;
7114 }
7115 Main.spriteBatch.Draw(treeBranchTexture, position, new Rectangle(42, treeFrame * 42, 40, 40), color2, num8 * num4, new Vector2(0f, 30f), 1f, SpriteEffects.None, 0f);
7116 if (type == 634)
7117 {
7118 Texture2D value = TextureAssets.GlowMask[317].Value;
7120 Main.spriteBatch.Draw(value, position, new Rectangle(42, treeFrame * 42, 40, 40), white, num8 * num4, new Vector2(0f, 30f), 1f, SpriteEffects.None, 0f);
7121 }
7122 break;
7123 }
7124 }
7125 }
7126 if (type == 323 && frameX >= 88 && frameX <= 132)
7127 {
7128 int num16 = 0;
7129 switch (frameX)
7130 {
7131 case 110:
7132 num16 = 1;
7133 break;
7134 case 132:
7135 num16 = 2;
7136 break;
7137 }
7138 int treeTextureIndex = 15;
7139 int num17 = 80;
7140 int num18 = 80;
7141 int num19 = 32;
7142 int num20 = 0;
7143 int palmTreeBiome = GetPalmTreeBiome(x, y);
7144 int y2 = palmTreeBiome * 82;
7145 if (palmTreeBiome >= 4 && palmTreeBiome <= 7)
7146 {
7147 treeTextureIndex = 21;
7148 num17 = 114;
7149 num18 = 98;
7150 y2 = (palmTreeBiome - 4) * 98;
7151 num19 = 48;
7152 num20 = 2;
7153 }
7154 int frameY2 = Main.tile[x, y].frameY;
7155 byte tileColor4 = tile.color();
7157 Vector2 position3 = new Vector2(x * 16 - (int)unscaledPosition.X - num19 + frameY2 + num17 / 2, y * 16 - (int)unscaledPosition.Y + 16 + num20) + zero;
7158 float num21 = 0f;
7159 if (!flag)
7160 {
7162 }
7163 position3.X += num21 * 2f;
7164 position3.Y += Math.Abs(num21) * 2f;
7165 Color color7 = Lighting.GetColor(x, y);
7166 if (tile.fullbrightBlock())
7167 {
7168 color7 = Color.White;
7169 }
7170 Main.spriteBatch.Draw(treeTopTexture2, position3, new Rectangle(num16 * (num17 + 2), y2, num17, num18), color7, num21 * num3, new Vector2(num17 / 2, num18), 1f, SpriteEffects.None, 0f);
7171 }
7172 }
7173 catch
7174 {
7175 }
7176 }
7177 }
static double Abs(double value)
void EmitTreeLeaves(int tilePosX, int tilePosY, int grassPosX, int grassPosY)
int GetPalmTreeBiome(int tileX, int tileY)
Texture2D GetTreeTopTexture(int treeTextureIndex, int treeTextureStyle, byte tileColor)
float GetWindCycle(int x, int y, double windCounter)
Texture2D GetTreeBranchTexture(int treeTextureIndex, int treeTextureStyle, byte tileColor)

References Terraria.GameContent.Drawing.TileDrawing._rand, Terraria.GameContent.Drawing.TileDrawing._specialPositions, Terraria.GameContent.Drawing.TileDrawing._specialsCount, Terraria.GameContent.Drawing.TileDrawing._treeWindCounter, System.Math.Abs(), Terraria.Tile.active(), Terraria.Lighting.AddLight(), Terraria.Main.Camera, Terraria.Tile.color(), Terraria.GameContent.Drawing.TileDrawing.EmitTreeLeaves(), Terraria.Tile.frameX, Terraria.Tile.frameY, Terraria.Tile.fullbrightBlock(), Terraria.WorldGen.GetAshTreeFoliageData(), Terraria.Lighting.GetColor(), Terraria.WorldGen.GetCommonTreeFoliageData(), Terraria.WorldGen.GetGemTreeFoliageData(), Terraria.GameContent.Drawing.TileDrawing.GetPalmTreeBiome(), Terraria.GameContent.Drawing.TileDrawing.GetTreeBranchTexture(), Terraria.WorldGen.GetTreeFrame(), Terraria.GameContent.Drawing.TileDrawing.GetTreeTopTexture(), Terraria.WorldGen.GetVanityTreeFoliageData(), Terraria.GameContent.Drawing.TileDrawing.GetWindCycle(), Terraria.GameContent.TextureAssets.GlowMask, Terraria.Main.mouseTextColor, Terraria.Utilities.UnifiedRandom.Next(), Terraria.WorldGen.paintColor(), Terraria.Main.spriteBatch, Terraria.Main.tile, System.type, Terraria.Tile.type, System.value, Microsoft.Xna.Framework.Graphics.Vector2, Microsoft.Xna.Framework.Color.White, Microsoft.Xna.Framework.Point.X, Microsoft.Xna.Framework.Point.Y, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.GameContent.Drawing.TileDrawing.PostDrawTiles().