Terraria.IO.WorldFile.LoadWorldTiles C# (CSharp) Method

LoadWorldTiles() private static method

private static LoadWorldTiles ( BinaryReader reader, bool importance ) : void
reader System.IO.BinaryReader
importance bool
return void
        private static void LoadWorldTiles(BinaryReader reader, bool[] importance)
        {
            for (int i = 0; i < Main.maxTilesX; i++)
            {
                float num9 = ((float)i) / ((float)Main.maxTilesX);
                Main.statusText = string.Concat(new object[] { Lang.gen[0x33], " ", (int)((num9 * 100.0) + 1.0), "%" });
                for (int j = 0; j < Main.maxTilesY; j++)
                {
                    byte num3;
                    byte num4;
                    int num8;
                    int index = -1;
                    byte num2 = (byte)(num3 = 0);
                    Tile from = Main.tile[i, j];
                    byte num = reader.ReadByte();
                    if ((num & 1) == 1)
                    {
                        num2 = reader.ReadByte();
                        if ((num2 & 1) == 1)
                        {
                            num3 = reader.ReadByte();
                        }
                    }
                    if ((num & 2) == 2)
                    {
                        from.active(true);
                        if ((num & 0x20) == 0x20)
                        {
                            num4 = reader.ReadByte();
                            index = (reader.ReadByte() << 8) | num4;
                        }
                        else
                        {
                            index = reader.ReadByte();
                        }
                        from.type = (ushort)index;
                        if (importance[index])
                        {
                            from.frameX = reader.ReadInt16();
                            from.frameY = reader.ReadInt16();
                            if (from.type == 0x90)
                            {
                                from.frameY = 0;
                            }
                        }
                        else
                        {
                            from.frameX = -1;
                            from.frameY = -1;
                        }
                        if ((num3 & 8) == 8)
                        {
                            from.color(reader.ReadByte());
                        }
                    }
                    if ((num & 4) == 4)
                    {
                        from.wall = reader.ReadByte();
                        if ((num3 & 0x10) == 0x10)
                        {
                            from.wallColor(reader.ReadByte());
                        }
                    }
                    num4 = (byte)((num & 0x18) >> 3);
                    if (num4 != 0)
                    {
                        from.liquid = reader.ReadByte();
                        if (num4 > 1)
                        {
                            if (num4 == 2)
                            {
                                from.lava(true);
                            }
                            else
                            {
                                from.honey(true);
                            }
                        }
                    }
					var wireFlag = k_WireFlags.WIRE_NONE;
                    if (num2 > 1)
                    {
						if ((num2 & 2) == 2)
							wireFlag |= k_WireFlags.WIRE_RED;
						if ((num2 & 4) == 4)
							wireFlag |= k_WireFlags.WIRE_GREEN;
						if ((num2 & 8) == 8)
							wireFlag |= k_WireFlags.WIRE_BLUE;
                        num4 = (byte)((num2 & 0x70) >> 4);
                        if ((num4 != 0) && Main.tileSolid[from.type])
                        {
                            if (num4 == 1)
                            {
                                from.halfBrick(true);
                            }
                            else
                            {
                                from.slope((byte)(num4 - 1));
                            }
                        }
                    }
                    if (num3 > 0)
                    {
						if ((num3 & 2) == 2)
							wireFlag |= k_WireFlags.WIRE_ACTUATOR;
                        if ((num3 & 4) == 4)
                        {
                            from.inActive(true);
                        }
                    }
					from.k_SetWireFlags(wireFlag, true);
                    switch (((byte)((num & 0xc0) >> 6)))
                    {
                        case 0:
                            num8 = 0;
                            break;

                        case 1:
                            num8 = reader.ReadByte();
                            break;

                        default:
                            num8 = reader.ReadInt16();
                            break;
                    }
                    if (index != -1)
                    {
                        if (j <= Main.worldSurface)
                        {
                            if ((j + num8) <= Main.worldSurface)
                            {
                                WorldGen.tileCounts[index] += (num8 + 1) * 5;
                            }
                            else
                            {
                                int num10 = (int)((Main.worldSurface - j) + 1.0);
                                int num11 = (num8 + 1) - num10;
                                WorldGen.tileCounts[index] += (num10 * 5) + num11;
                            }
                        }
                        else
                        {
                            WorldGen.tileCounts[index] += num8 + 1;
                        }
                    }
                    while (num8 > 0)
                    {
                        j++;
                        Main.tile[i, j].CopyFrom(from);
                        num8--;
                    }
                }
            }
            WorldGen.AddUpAlignmentCounts(true);
            if (versionNumber < 0x69)
            {
                WorldGen.FixHearts();
            }
        }