First you have to make code changes, build and reload the mod, wait for the world to finish generating, then explore the newly generated world to see the end result. Testing world generation code can be very time consuming. For example, the tile outlined in red has frameX of 36 and frameY or 0, meaning that the 16x16 section of the sprite starting at the pixel coordinates 36, 0 is drawn for this Tile. Here we can see how tiles use frameX and frameY to determine the portion of their spritesheet to draw. If you ever see tiles like this in-game, then you have buggy code. In this example, all the gemspark blocks have ameX and ameY values of 0. ExampleSolution.cs shows a situation where tile framing and syncing is needed.
If you are changing Tiles in-game, you do need to tell the game to frame nearby tiles. In world generation code, you do not need to worry about framing because the game frames all tiles automatically when loading the world.
Framingįraming is the process where the game adjusts the ameX and ameY values of tiles to adjust their look to fit their context. Attempting to manually place FrameImportant tiles or replace them is much harder. The important thing to know is that replacing Framed tiles with other Framed tiles is easy, simply set Tile.type to the new Tile type. The other tiles, known as FrameImportant or multitiles, have a defined look that doesn't change. For example, placing a gemspark block next to an existing gemspark block tile changes the look of the original gemspark block and makes them look like a single deposit of ore. Terrain tiles are known as "Framed" tiles because the game adjusts their look depending on nearby tiles. There are normal terrain tiles like dirt, ores, and stone, and there are tiles that are not terrain tiles, like trees, anvils, paintings, and so on. It is vital to remember that tiles in Terraria come in two basic varieties. See Tile Class Documentation for more details on the various fields and methods of the Tile class. The most important fields are type and wall, which represent the TileType and WallType present at the location. The Tile class contains all the data at the tile it represents. To avoid this, use the WorldGen.InWorld method. Be mindful that negative numbers or coordinates outside the bounds of the world will lead to errors. If you are checking tiles in-game, you must use Tile tile = Framing.GetTileSafely(x, y) because the Tile object might be null. You can directly access the Tile object at a specific x and y coordinate during worldgen by writing Tile tile = Main.tile. Main.tile is an 2D array containing all the tiles in the world. We need multiple pairs of variables because many times we are working with coordinates derived from other coordinates. By convention, we use x and y or i and j in code for tile coordinates. These coordinates directly map into Main.tile. The very top left of the world is located at 0, 0 in tile coordinates, and the bottom right at Main.maxTilesX, Main.maxTilesY. The term Task could be equivalent to Pass, but we will avoid that term in this guide since Task has another meaning that we will need later on in the guide. For example, a Pass that makes a biome could be composed of 2 steps, the first step digging holes, and the 2nd step placing trees. World Generation is composed of Passes, and Passes are composed of Steps.
In this guide, the term step will refer to individual sections of code that make up a pass. When a world is generated, the game runs each pass in order. In addition, using an IDE with edit and continue support like Visual Studio is highly recommended. It is recommended to familiarize yourself when the following sections before jumping straight into the code. World generation is a fairly complex topic, and a good understanding of many topics is required to work effectively. The vast majority of this guide will focus on world generation during world creation, but in-game considerations will also be detailed. World Generation is done in two places, during world creation and in-game. World Generation is the act of programmatically placing and removing tiles from the world.