@@ -117,7 +117,7 @@ private void OnUpdateTicked(object? sender, UpdateTickedEventArgs e)
117
117
{
118
118
foreach ( NPC ? character in loc . characters )
119
119
{
120
- if ( character . isVillager ( ) )
120
+ if ( character . IsVillager )
121
121
{
122
122
_townsfolk . Add ( character ) ;
123
123
}
@@ -311,13 +311,18 @@ private static void DrawNPC(NPC character, List<string> namesToShow)
311
311
}
312
312
313
313
Rectangle headShot = character . GetHeadShot ( ) ;
314
- MapAreaPosition ? mapPosition =
315
- WorldMapManager . GetPositionData (
316
- Game1 . player . currentLocation ,
317
- new Point ( ( int ) location . Value . X , ( int ) location . Value . Y )
318
- ) ??
319
- WorldMapManager . GetPositionData ( Game1 . getFarm ( ) , Point . Zero ) ;
320
- MapRegion ? mapRegion = mapPosition . Region ;
314
+ MapAreaPosition ? mapPosition = Tools . GetMapPositionDataSafe (
315
+ Game1 . player . currentLocation ,
316
+ new Point ( ( int ) location . Value . X , ( int ) location . Value . Y )
317
+ ) ;
318
+
319
+ if ( mapPosition is null )
320
+ {
321
+ ModEntry . MonitorObject . LogOnce ( $ "Unable to draw headshot for { character . Name } ") ;
322
+ return ;
323
+ }
324
+
325
+ MapRegion mapRegion = mapPosition . Region ;
321
326
Rectangle mapBounds = mapRegion . GetMapPixelBounds ( ) ;
322
327
var offsetLocation = new Vector2 (
323
328
location . Value . X + mapBounds . X - headShot . Width ,
@@ -356,21 +361,18 @@ private static void DrawNPC(NPC character, List<string> namesToShow)
356
361
private static Vector2 ? GetMapCoordinatesForNPC ( NPC character )
357
362
{
358
363
var playerNormalizedTile = new Point ( Math . Max ( 0 , Game1 . player . TilePoint . X ) , Math . Max ( 0 , Game1 . player . TilePoint . Y ) ) ;
359
- MapAreaPosition playerMapAreaPosition =
360
- WorldMapManager . GetPositionData ( Game1 . player . currentLocation , playerNormalizedTile ) ??
361
- WorldMapManager . GetPositionData ( Game1 . getFarm ( ) , Point . Zero ) ;
364
+ MapAreaPosition ? playerMapAreaPosition = Tools . GetMapPositionDataSafe ( Game1 . player . currentLocation , playerNormalizedTile ) ;
362
365
// ^^ Regarding that ?? clause... If the player is in the farmhouse or barn or any building on the farm, GetPositionData is
363
366
// going to return null. Thus the fallback to pretending the player is on the farm. However, it seems to me that
364
367
// Game1.player.currentLocation.GetParentLocation() would be the safer long-term bet. But rule number 1 of modding is this:
365
368
// the game code is always right, even when it's wrong.
366
369
367
370
var characterNormalizedTile = new Point ( Math . Max ( 0 , character . TilePoint . X ) , Math . Max ( 0 , character . TilePoint . Y ) ) ;
368
- MapAreaPosition characterMapAreaPosition =
369
- WorldMapManager . GetPositionData ( character . currentLocation , characterNormalizedTile ) ;
371
+ MapAreaPosition ? characterMapAreaPosition = Tools . GetMapPositionDataSafe ( character . currentLocation , characterNormalizedTile ) ;
370
372
371
373
if ( playerMapAreaPosition != null &&
372
374
characterMapAreaPosition != null &&
373
- ! ( characterMapAreaPosition . Region . Id != playerMapAreaPosition . Region . Id ) )
375
+ characterMapAreaPosition . Region . Id == playerMapAreaPosition . Region . Id )
374
376
{
375
377
return characterMapAreaPosition . GetMapPixelPosition ( character . currentLocation , characterNormalizedTile ) ;
376
378
}
0 commit comments