@@ -461,10 +461,29 @@ public int PlaceItem() {
461
461
return 0 ;
462
462
}
463
463
464
- public void MoveForward ( ) {
464
+ public static int DxForDirection ( int direction ) {
465
+ if ( direction == 1 ) return 1 ;
466
+ if ( direction == 3 ) return - 1 ;
467
+ return 0 ;
468
+ }
469
+
470
+ public static int DyForDirection ( int direction ) {
471
+ if ( direction == 2 ) return 1 ;
472
+ if ( direction == 0 ) return - 1 ;
473
+ return 0 ;
474
+ }
475
+
476
+ public void Move ( int dColumn , int dRow ) {
477
+ // Face in the specified direction
478
+ if ( dRow < 0 ) farmer . faceDirection ( 0 ) ;
479
+ else if ( dRow > 0 ) farmer . faceDirection ( 2 ) ;
480
+ else if ( dColumn < 0 ) farmer . faceDirection ( 3 ) ;
481
+ else if ( dColumn > 0 ) farmer . faceDirection ( 1 ) ;
482
+
483
+ // make sure the terrain in that direction isn't blocked
484
+ Vector2 newTile = farmer . getTileLocation ( ) + new Vector2 ( dColumn , dRow ) ;
485
+
465
486
// make sure the terrain in that direction isn't blocked
466
- Location newTileLoc = farmer . nextPositionTile ( ) ;
467
- Vector2 newTile = newTileLoc . ToVector2 ( ) ;
468
487
bool isPassable = TileInfo . IsPassable ( currentLocation , newTile ) ;
469
488
if ( ! isPassable ) {
470
489
ModEntry . instance . Monitor . Log ( $ "MoveForward: tile { newTile } is not passable") ;
@@ -474,7 +493,7 @@ public void MoveForward() {
474
493
475
494
// start moving
476
495
targetPos = newTile . GetAbsolutePosition ( ) ;
477
- ModEntry . instance . Monitor . Log ( $ "MoveForward: Position: { Position } / targetPos: { targetPos } ") ;
496
+ ModEntry . instance . Monitor . Log ( $ "MoveForward: Facing: { facingDirection } ; Position: { Position } ; newTile: { newTile } ; targetPos: { targetPos } ") ;
478
497
479
498
// Do collision actions (shake the grass, etc.)
480
499
if ( currentLocation . terrainFeatures . ContainsKey ( newTile ) ) {
@@ -484,6 +503,10 @@ public void MoveForward() {
484
503
feature . doCollisionAction ( posRect , farmer . Speed , newTile , farmer , currentLocation ) ;
485
504
}
486
505
}
506
+
507
+ public void MoveForward ( ) {
508
+ Move ( DxForDirection ( farmer . FacingDirection ) , DyForDirection ( farmer . FacingDirection ) ) ;
509
+ }
487
510
488
511
public bool IsMoving ( ) {
489
512
return ( Position != targetPos ) ;
@@ -492,7 +515,7 @@ public bool IsMoving() {
492
515
public void Rotate ( int stepsClockwise ) {
493
516
farmer . faceDirection ( ( farmer . FacingDirection + 4 + stepsClockwise ) % 4 ) ;
494
517
data . Update ( ) ;
495
- // ModEntry.instance.Monitor.Log($"{Name} Rotate({stepsClockwise}): now facing {farmer.FacingDirection}");
518
+ ModEntry . instance . Monitor . Log ( $ "{ Name } Rotate({ stepsClockwise } ): now facing { farmer . FacingDirection } ") ;
496
519
}
497
520
498
521
void ApplyScytheToTile ( ) {
@@ -572,8 +595,10 @@ public void Update(GameTime gameTime) {
572
595
// face target position
573
596
float dx = targetPos . X - Position . X ;
574
597
float dy = targetPos . Y - Position . Y ;
598
+ int prevDir = farmer . FacingDirection ;
575
599
if ( MathF . Abs ( dx ) > MathF . Abs ( dy ) ) farmer . FacingDirection = dx > 0 ? 1 : 3 ;
576
600
else farmer . FacingDirection = dy > 0 ? 2 : 0 ;
601
+ if ( farmer . FacingDirection != prevDir ) ModEntry . instance . Monitor . Log ( $ "Update: changed facing from { prevDir } to { farmer . FacingDirection } because dx={ dx } , dy={ dy } ") ;
577
602
// try to move; if fail, abandon movement
578
603
var oldPos = farmer . Position ;
579
604
farmer . tryToMoveInDirection ( farmer . FacingDirection , false , 0 , false ) ;
0 commit comments