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

◆ LoadWorldTiles()

static void Terraria.IO.WorldFile.LoadWorldTiles ( BinaryReader reader,
bool[] importance )
inlinestatic

Definition at line 2365 of file WorldFile.cs.

2366 {
2367 for (int i = 0; i < Main.maxTilesX; i++)
2368 {
2369 float num = (float)i / (float)Main.maxTilesX;
2370 Main.statusText = Lang.gen[51].Value + " " + (int)((double)num * 100.0 + 1.0) + "%";
2371 for (int j = 0; j < Main.maxTilesY; j++)
2372 {
2373 int num2 = -1;
2374 byte b2;
2375 byte b;
2376 byte b3 = (b2 = (b = 0));
2377 Tile tile = Main.tile[i, j];
2378 byte b4 = reader.ReadByte();
2379 bool flag = false;
2380 if ((b4 & 1) == 1)
2381 {
2382 flag = true;
2383 b3 = reader.ReadByte();
2384 }
2385 bool flag2 = false;
2386 if (flag && (b3 & 1) == 1)
2387 {
2388 flag2 = true;
2389 b2 = reader.ReadByte();
2390 }
2391 if (flag2 && (b2 & 1) == 1)
2392 {
2393 b = reader.ReadByte();
2394 }
2395 byte b5;
2396 if ((b4 & 2) == 2)
2397 {
2398 tile.active(active: true);
2399 if ((b4 & 0x20) == 32)
2400 {
2401 b5 = reader.ReadByte();
2402 num2 = reader.ReadByte();
2403 num2 = (num2 << 8) | b5;
2404 }
2405 else
2406 {
2407 num2 = reader.ReadByte();
2408 }
2409 tile.type = (ushort)num2;
2410 if (importance[num2])
2411 {
2412 tile.frameX = reader.ReadInt16();
2413 tile.frameY = reader.ReadInt16();
2414 if (tile.type == 144)
2415 {
2416 tile.frameY = 0;
2417 }
2418 }
2419 else
2420 {
2421 tile.frameX = -1;
2422 tile.frameY = -1;
2423 }
2424 if ((b2 & 8) == 8)
2425 {
2426 tile.color(reader.ReadByte());
2427 }
2428 }
2429 if ((b4 & 4) == 4)
2430 {
2431 tile.wall = reader.ReadByte();
2432 if (tile.wall >= WallID.Count)
2433 {
2434 tile.wall = 0;
2435 }
2436 if ((b2 & 0x10) == 16)
2437 {
2438 tile.wallColor(reader.ReadByte());
2439 }
2440 }
2441 b5 = (byte)((b4 & 0x18) >> 3);
2442 if (b5 != 0)
2443 {
2444 tile.liquid = reader.ReadByte();
2445 if ((b2 & 0x80) == 128)
2446 {
2447 tile.shimmer(shimmer: true);
2448 }
2449 else if (b5 > 1)
2450 {
2451 if (b5 == 2)
2452 {
2453 tile.lava(lava: true);
2454 }
2455 else
2456 {
2457 tile.honey(honey: true);
2458 }
2459 }
2460 }
2461 if (b3 > 1)
2462 {
2463 if ((b3 & 2) == 2)
2464 {
2465 tile.wire(wire: true);
2466 }
2467 if ((b3 & 4) == 4)
2468 {
2469 tile.wire2(wire2: true);
2470 }
2471 if ((b3 & 8) == 8)
2472 {
2473 tile.wire3(wire3: true);
2474 }
2475 b5 = (byte)((b3 & 0x70) >> 4);
2476 if (b5 != 0 && (Main.tileSolid[tile.type] || TileID.Sets.NonSolidSaveSlopes[tile.type]))
2477 {
2478 if (b5 == 1)
2479 {
2480 tile.halfBrick(halfBrick: true);
2481 }
2482 else
2483 {
2484 tile.slope((byte)(b5 - 1));
2485 }
2486 }
2487 }
2488 if (b2 > 1)
2489 {
2490 if ((b2 & 2) == 2)
2491 {
2492 tile.actuator(actuator: true);
2493 }
2494 if ((b2 & 4) == 4)
2495 {
2496 tile.inActive(inActive: true);
2497 }
2498 if ((b2 & 0x20) == 32)
2499 {
2500 tile.wire4(wire4: true);
2501 }
2502 if ((b2 & 0x40) == 64)
2503 {
2504 b5 = reader.ReadByte();
2505 tile.wall = (ushort)((b5 << 8) | tile.wall);
2506 if (tile.wall >= WallID.Count)
2507 {
2508 tile.wall = 0;
2509 }
2510 }
2511 }
2512 if (b > 1)
2513 {
2514 if ((b & 2) == 2)
2515 {
2516 tile.invisibleBlock(invisibleBlock: true);
2517 }
2518 if ((b & 4) == 4)
2519 {
2520 tile.invisibleWall(invisibleWall: true);
2521 }
2522 if ((b & 8) == 8)
2523 {
2524 tile.fullbrightBlock(fullbrightBlock: true);
2525 }
2526 if ((b & 0x10) == 16)
2527 {
2528 tile.fullbrightWall(fullbrightWall: true);
2529 }
2530 }
2531 int num3 = (byte)((b4 & 0xC0) >> 6) switch
2532 {
2533 0 => 0,
2534 1 => reader.ReadByte(),
2535 _ => reader.ReadInt16(),
2536 };
2537 if (num2 != -1)
2538 {
2539 if ((double)j <= Main.worldSurface)
2540 {
2541 if ((double)(j + num3) <= Main.worldSurface)
2542 {
2543 WorldGen.tileCounts[num2] += (num3 + 1) * 5;
2544 }
2545 else
2546 {
2547 int num4 = (int)(Main.worldSurface - (double)j + 1.0);
2548 int num5 = num3 + 1 - num4;
2549 WorldGen.tileCounts[num2] += num4 * 5 + num5;
2550 }
2551 }
2552 else
2553 {
2554 WorldGen.tileCounts[num2] += num3 + 1;
2555 }
2556 }
2557 while (num3 > 0)
2558 {
2559 j++;
2560 Main.tile[i, j].CopyFrom(tile);
2561 num3--;
2562 }
2563 }
2564 }
2565 WorldGen.AddUpAlignmentCounts(clearCounts: true);
2566 if (_versionNumber < 105)
2567 {
2568 WorldGen.FixHearts();
2569 }
2570 }
virtual byte ReadByte()
virtual short ReadInt16()
static bool[] NonSolidSaveSlopes
Definition TileID.cs:109
static readonly ushort Count
Definition WallID.cs:753
static int _versionNumber
Definition WorldFile.cs:117

References Terraria.IO.WorldFile._versionNumber, Terraria.Tile.active(), Terraria.Tile.actuator(), Terraria.WorldGen.AddUpAlignmentCounts(), Terraria.Tile.color(), Terraria.ID.WallID.Count, Terraria.WorldGen.FixHearts(), Terraria.Tile.fullbrightBlock(), Terraria.Tile.fullbrightWall(), Terraria.Lang.gen, Terraria.Tile.halfBrick(), Terraria.Tile.honey(), Terraria.Tile.inActive(), Terraria.Tile.invisibleBlock(), Terraria.Tile.invisibleWall(), Terraria.Tile.lava(), Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.ID.TileID.Sets.NonSolidSaveSlopes, System.IO.BinaryReader.ReadByte(), System.IO.BinaryReader.ReadInt16(), Terraria.Tile.shimmer(), Terraria.Tile.slope(), Terraria.Main.tile, Terraria.WorldGen.tileCounts, Terraria.Main.tileSolid, Terraria.Tile.type, Terraria.Tile.wall, Terraria.Tile.wallColor(), Terraria.Tile.wire(), Terraria.Tile.wire2(), Terraria.Tile.wire3(), Terraria.Tile.wire4(), and Terraria.Main.worldSurface.

Referenced by Terraria.IO.WorldFile.LoadWorld_Version2().