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

◆ ShakeTree()

static void Terraria.WorldGen.ShakeTree ( int i,
int j )
inlinestaticprivate

Definition at line 53776 of file WorldGen.cs.

53777 {
53779 {
53780 return;
53781 }
53782 GetTreeBottom(i, j, out var x, out var y);
53783 int num = y;
53784 TreeTypes treeType = GetTreeType(Main.tile[x, y].type);
53785 if (treeType == TreeTypes.None)
53786 {
53787 return;
53788 }
53789 for (int k = 0; k < numTreeShakes; k++)
53790 {
53791 if (treeShakeX[k] == x && treeShakeY[k] == y)
53792 {
53793 return;
53794 }
53795 }
53798 numTreeShakes++;
53799 y--;
53800 while (y > 10 && Main.tile[x, y].active() && TileID.Sets.IsShakeable[Main.tile[x, y].type])
53801 {
53802 y--;
53803 }
53804 y++;
53805 if (!IsTileALeafyTreeTop(x, y) || Collision.SolidTiles(x - 2, x + 2, y - 2, y + 2))
53806 {
53807 return;
53808 }
53809 if (Main.getGoodWorld && genRand.Next(17) == 0)
53810 {
53811 Projectile.NewProjectile(GetProjectileSource_ShakeTree(x, y), x * 16, y * 16, (float)Main.rand.Next(-100, 101) * 0.002f, 0f, 28, 0, 0f, Main.myPlayer, 16f, 16f);
53812 }
53813 else if (genRand.Next(300) == 0 && treeType == TreeTypes.Forest)
53814 {
53815 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 832);
53816 }
53817 else if (genRand.Next(300) == 0 && treeType == TreeTypes.Forest)
53818 {
53819 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 933);
53820 }
53821 else if (genRand.Next(200) == 0 && treeType == TreeTypes.Jungle)
53822 {
53823 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 3360);
53824 }
53825 else if (genRand.Next(200) == 0 && treeType == TreeTypes.Jungle)
53826 {
53827 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 3361);
53828 }
53829 else if (genRand.Next(1000) == 0 && treeType == TreeTypes.Forest)
53830 {
53831 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 4366);
53832 }
53833 else if (genRand.Next(7) == 0 && (treeType == TreeTypes.Forest || treeType == TreeTypes.Snow || treeType == TreeTypes.Hallowed || treeType == TreeTypes.Ash))
53834 {
53835 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 27, genRand.Next(1, 3));
53836 }
53837 else if (genRand.Next(8) == 0 && treeType == TreeTypes.Mushroom)
53838 {
53839 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 194, genRand.Next(1, 2));
53840 }
53841 else if (genRand.Next(35) == 0 && Main.halloween)
53842 {
53843 Item.NewItem(GetItemSource_ShakeTree(x, y), x * 16, y * 16, 16, 16, 1809, genRand.Next(1, 3));
53844 }
53845 else if (genRand.Next(12) == 0)
53846 {
53847 int dropItem = 0;
53848 KillTile_GetItemDrops(i, j, Main.tile[i, j], out dropItem, out var _, out var _, out var _);
53849 Item.NewItem(GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, dropItem, genRand.Next(1, 4));
53850 }
53851 else if (genRand.Next(20) == 0)
53852 {
53853 int type = 71;
53854 int num2 = genRand.Next(50, 100);
53855 if (genRand.Next(30) == 0)
53856 {
53857 type = 73;
53858 num2 = 1;
53859 if (genRand.Next(5) == 0)
53860 {
53861 num2++;
53862 }
53863 if (genRand.Next(10) == 0)
53864 {
53865 num2++;
53866 }
53867 }
53868 else if (genRand.Next(10) == 0)
53869 {
53870 type = 72;
53871 num2 = genRand.Next(1, 21);
53872 if (genRand.Next(3) == 0)
53873 {
53874 num2 += genRand.Next(1, 21);
53875 }
53876 if (genRand.Next(4) == 0)
53877 {
53878 num2 += genRand.Next(1, 21);
53879 }
53880 }
53881 Item.NewItem(GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, type, num2);
53882 }
53883 else if (genRand.Next(15) == 0 && (treeType == TreeTypes.Forest || treeType == TreeTypes.Hallowed))
53884 {
53885 int type2 = genRand.Next(5) switch
53886 {
53887 0 => 74,
53888 1 => 297,
53889 2 => 298,
53890 3 => 299,
53891 _ => 538,
53892 };
53893 if (Player.GetClosestRollLuck(x, y, NPC.goldCritterChance) == 0f)
53894 {
53895 type2 = ((genRand.Next(2) != 0) ? 539 : 442);
53896 }
53897 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, type2);
53898 }
53899 else if (genRand.Next(50) == 0 && treeType == TreeTypes.Hallowed && !Main.dayTime)
53900 {
53901 int type3 = Main.rand.NextFromList(new short[3] { 583, 584, 585 });
53902 if (Main.tenthAnniversaryWorld && Main.rand.Next(4) != 0)
53903 {
53904 type3 = 583;
53905 }
53906 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, type3);
53907 }
53908 else if (genRand.Next(50) == 0 && treeType == TreeTypes.Forest && !Main.dayTime)
53909 {
53910 NPC obj = Main.npc[NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, 611)];
53911 obj.velocity.Y = 1f;
53912 obj.netUpdate = true;
53913 }
53914 else if (genRand.Next(50) == 0 && treeType == TreeTypes.Jungle && Main.dayTime)
53915 {
53916 NPC obj2 = Main.npc[NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, Main.rand.NextFromList(new short[5] { 671, 672, 673, 674, 675 }))];
53917 obj2.velocity.Y = 1f;
53918 obj2.netUpdate = true;
53919 }
53920 else if (genRand.Next(40) == 0 && treeType == TreeTypes.Forest && !Main.dayTime && Main.halloween)
53921 {
53922 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, 301);
53923 }
53924 else if (genRand.Next(50) == 0 && (treeType == TreeTypes.Forest || treeType == TreeTypes.Hallowed))
53925 {
53926 for (int l = 0; l < 5; l++)
53927 {
53928 Point point = new Point(x + Main.rand.Next(-2, 2), y - 1 + Main.rand.Next(-2, 2));
53929 int type4 = ((Player.GetClosestRollLuck(x, y, NPC.goldCritterChance) != 0f) ? Main.rand.NextFromList(new short[3] { 74, 297, 298 }) : 442);
53930 NPC obj3 = Main.npc[NPC.NewNPC(new EntitySource_ShakeTree(x, y), point.X * 16, point.Y * 16, type4)];
53931 obj3.velocity = Main.rand.NextVector2CircularEdge(3f, 3f);
53932 obj3.netUpdate = true;
53933 }
53934 }
53935 else if (genRand.Next(40) == 0 && treeType == TreeTypes.Jungle)
53936 {
53937 for (int m = 0; m < 5; m++)
53938 {
53939 Point point2 = new Point(x + Main.rand.Next(-2, 2), y - 1 + Main.rand.Next(-2, 2));
53940 NPC obj4 = Main.npc[NPC.NewNPC(new EntitySource_ShakeTree(x, y), point2.X * 16, point2.Y * 16, Main.rand.NextFromList(new short[2] { 210, 211 }))];
53941 obj4.ai[1] = 65f;
53942 obj4.netUpdate = true;
53943 }
53944 }
53945 else if (genRand.Next(20) == 0 && (treeType == TreeTypes.Palm || treeType == TreeTypes.PalmCorrupt || treeType == TreeTypes.PalmCrimson || treeType == TreeTypes.PalmHallowed) && !IsPalmOasisTree(x))
53946 {
53947 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, 603);
53948 }
53949 else if (genRand.Next(30) == 0 && (treeType == TreeTypes.Crimson || treeType == TreeTypes.PalmCrimson))
53950 {
53951 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16 + 8, (y - 1) * 16, -22);
53952 }
53953 else if (genRand.Next(30) == 0 && (treeType == TreeTypes.Corrupt || treeType == TreeTypes.PalmCorrupt))
53954 {
53955 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16 + 8, (y - 1) * 16, -11);
53956 }
53957 else if (genRand.Next(30) == 0 && treeType == TreeTypes.Jungle && !Main.dayTime)
53958 {
53959 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, 51);
53960 }
53961 else if (genRand.Next(40) == 0 && treeType == TreeTypes.Jungle)
53962 {
53963 Projectile.NewProjectile(GetProjectileSource_ShakeTree(x, y), x * 16 + 8, (y - 1) * 16, 0f, 0f, 655, 0, 0f, Main.myPlayer);
53964 }
53965 else if (genRand.Next(20) == 0 && (treeType == TreeTypes.Forest || treeType == TreeTypes.Hallowed) && !Main.raining && !NPC.TooWindyForButterflies && Main.dayTime)
53966 {
53967 int type5 = 356;
53968 if (Player.GetClosestRollLuck(x, y, NPC.goldCritterChance) == 0f)
53969 {
53970 type5 = 444;
53971 }
53972 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, type5);
53973 }
53974 else if (genRand.Next(20) == 0 && treeType == TreeTypes.Ash && y > Main.maxTilesY - 250)
53975 {
53976 int num3 = genRand.Next(3);
53977 NPC.NewNPC(new EntitySource_ShakeTree(x, y), x * 16, y * 16, num3 switch
53978 {
53979 0 => 654,
53980 1 => 653,
53981 _ => 655,
53982 });
53983 }
53984 else if (Main.remixWorld && genRand.Next(20) == 0 && treeType == TreeTypes.Ash && y > Main.maxTilesY - 250)
53985 {
53986 Item.NewItem(GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, 965, genRand.Next(20, 41));
53987 }
53988 else if (genRand.Next(12) == 0 && treeType == TreeTypes.Forest)
53989 {
53990 int num4 = genRand.Next(5);
53991 Item.NewItem(GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, num4 switch
53992 {
53993 0 => 4009,
53994 1 => 4293,
53995 2 => 4282,
53996 3 => 4290,
53997 _ => 4291,
53998 });
53999 }
54000 else if (genRand.Next(12) == 0 && treeType == TreeTypes.Snow)
54001 {
54002 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4295 : 4286, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54003 }
54004 else if (genRand.Next(12) == 0 && treeType == TreeTypes.Jungle)
54005 {
54006 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4292 : 4294, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54007 }
54008 else if (genRand.Next(12) == 0 && (treeType == TreeTypes.Palm || treeType == TreeTypes.PalmCorrupt || treeType == TreeTypes.PalmCrimson || treeType == TreeTypes.PalmHallowed) && !IsPalmOasisTree(x))
54009 {
54010 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4287 : 4283, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54011 }
54012 else if (genRand.Next(12) == 0 && (treeType == TreeTypes.Corrupt || treeType == TreeTypes.PalmCorrupt))
54013 {
54014 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4289 : 4284, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54015 }
54016 else if (genRand.Next(12) == 0 && (treeType == TreeTypes.Hallowed || treeType == TreeTypes.PalmHallowed))
54017 {
54018 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4288 : 4297, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54019 }
54020 else if (genRand.Next(12) == 0 && (treeType == TreeTypes.Crimson || treeType == TreeTypes.PalmCrimson))
54021 {
54022 Item.NewItem(Type: (genRand.Next(2) != 0) ? 4285 : 4296, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54023 }
54024 else if (genRand.Next(12) == 0 && treeType == TreeTypes.Ash)
54025 {
54026 Item.NewItem(Type: (genRand.Next(2) != 0) ? 5278 : 5277, source: GetItemSource_FromTreeShake(x, y), X: x * 16, Y: y * 16, Width: 16, Height: 16);
54027 }
54028 int treeHeight = 0;
54029 int treeFrame = 0;
54030 int passStyle = 0;
54031 GetTreeLeaf(x, Main.tile[x, y], Main.tile[x, num], ref treeHeight, out treeFrame, out passStyle);
54032 if (passStyle != -1)
54033 {
54034 if (Main.netMode == 2)
54035 {
54036 NetMessage.SendData(112, -1, -1, null, 1, x, y, 1f, passStyle);
54037 }
54038 if (Main.netMode == 0)
54039 {
54040 TreeGrowFX(x, y, 1, passStyle, hitTree: true);
54041 }
54042 }
54043 }
static bool[] IsShakeable
Definition TileID.cs:93
static int[] treeShakeX
Definition WorldGen.cs:1186
static EntitySource_ShakeTree GetProjectileSource_ShakeTree(int x, int y)
Definition WorldGen.cs:1323
static void KillTile_GetItemDrops(int x, int y, Tile tileCache, out int dropItem, out int dropItemStack, out int secondaryItem, out int secondaryItemStack, bool includeLargeObjectDrops=false)
static int maxTreeShakes
Definition WorldGen.cs:1182
static void TreeGrowFX(int x, int y, int height, int treeGore, bool hitTree=false)
static UnifiedRandom genRand
Definition WorldGen.cs:1215
static int[] treeShakeY
Definition WorldGen.cs:1188
static int numTreeShakes
Definition WorldGen.cs:1184
static void GetTreeBottom(int i, int j, out int x, out int y)
static void GetTreeLeaf(int x, Tile topTile, Tile t, ref int treeHeight, out int treeFrame, out int passStyle)
static bool IsPalmOasisTree(int x)
static EntitySource_ShakeTree GetItemSource_ShakeTree(int x, int y)
Definition WorldGen.cs:1328
static IEntitySource GetItemSource_FromTreeShake(int x, int y)
static bool IsTileALeafyTreeTop(int i, int j)
static TreeTypes GetTreeType(int tileType)

References Terraria.Main.dayTime, Terraria.Player.GetClosestRollLuck(), Terraria.Main.getGoodWorld, Terraria.NPC.goldCritterChance, Terraria.Main.halloween, Terraria.ID.TileID.Sets.IsShakeable, Terraria.Main.myPlayer, Terraria.Item.NewItem(), Terraria.NPC.NewNPC(), Terraria.Projectile.NewProjectile(), Terraria.Main.npc, System.obj, Terraria.Main.rand, Terraria.Collision.SolidTiles(), Terraria.Main.tenthAnniversaryWorld, Terraria.Main.tile, and System.type.