Line 25: |
Line 25: |
| ==Locations== | | ==Locations== |
| The ''GameLocation'' is a representation of any place in the game (e.g. Farm, Town) | | The ''GameLocation'' is a representation of any place in the game (e.g. Farm, Town) |
− | This it a good starting point for many things such as modifying tiles, etc.
| + | |
| + | The list of current locations is stored in ''Game1.currentLocations'' |
| + | |
| + | '''Important Caveat''': In 1.3 onwards, the ''Game1.currentLocations'' is not reliable for farmhands in MP. |
| + | |
| ===Map Properties=== | | ===Map Properties=== |
− | You can edit many properties of the current map and the tiles in the map. This is already documented here [[Modding:Maps]] //todo link to Map Properties | + | You can edit many properties of the current map and the tiles in the map. This is already documented here [[Modding:Maps]] |
| + | |
| ===Tiles=== | | ===Tiles=== |
− | ''terrainFeatures'' contains information about the tiles. (e.g. dirt, grass) | + | ''terrainFeatures'' contains information about the tiles. (e.g. dirt, grass, crops, etc.) |
| | | |
| ''objects'' contains information about objects on top of tiles. (e.g. crops, stones) | | ''objects'' contains information about objects on top of tiles. (e.g. crops, stones) |
− | ====Valid Position==== | + | |
| + | ===Handling TerrainFeatures=== |
| + | |
| + | As ''terrainFeatures'' is a NetField, always use .Pairs to access it for enumeration. The .Key value of this stores the location, and the .Value contains the terrainFeature itself. As a note, this includes items spawned off the map, which is usually cleared at end of day. |
| + | |
| + | If you need to access just crops, this snippet will be of use: |
| + | |
| <source lang="c#"> | | <source lang="c#"> |
− | terrainFeatures.ContainsKey(Vector2) | + | |
− | objects.ContainsKey(Vector2)
| + | foreach (var tf in Game1.getFarm().terrainFeatures.Pairs) |
| + | { |
| + | if ((tf.Value is HoeDirt hd) && hd.crop != null) |
| + | { |
| + | // do crop like things here. |
| + | } |
| + | } |
| </source> | | </source> |
− | ====HoeDirt====
| + | |
− | <source lang="c#">
| + | If you need some other location, sub that out for Game1.getFarm(). Note this doesn't null check Farm! Make sure Farm is loaded. |
− | terrainFeatures[Vector2] is HoeDirt hd
| |
− | </source>
| |
− | Check if there crops on this dirt with ''hd.crops''
| |
| | | |
| ==Player== | | ==Player== |