@@ -51,6 +51,8 @@ public int currentToolIndex {
5151 }
5252 }
5353
54+ public bool shouldPickupDebris { get ; set ; }
55+
5456 internal Vector2 Position { get => farmer . Position ; set => farmer . Position = value ; } // our current position, in pixels
5557 private Vector2 targetPos ; // position we're moving to, in pixels
5658 private int scytheUseFrame = 0 ; // > 0 when using the scythe
@@ -664,6 +666,47 @@ public void Update(GameTime gameTime) {
664666 }
665667
666668 farmer . Update ( gameTime , farmer . currentLocation ) ;
669+ if ( shouldPickupDebris ) PickUpDebris ( farmer , gameTime ) ;
670+ }
671+
672+ public void PickUpDebris ( Farmtronics . Bot . BotFarmer farmer , GameTime gameTime ) {
673+ GameLocation loc = farmer . currentLocation ;
674+ int range = 128 ; // Same as default magnetism of player
675+ float moveSpeed = 400f ; // Speed at which debris moves toward the bot
676+
677+ for ( int i = loc . debris . Count - 1 ; i >= 0 ; i -- ) {
678+ Debris d = loc . debris [ i ] ;
679+
680+ if ( d == null || string . IsNullOrEmpty ( d . itemId ) || d . timeSinceDoneBouncing <= 0 )
681+ continue ; // Skip null or invalid debris
682+
683+ Item item = ItemRegistry . Create ( d . itemId , 1 , d . itemQuality ) ;
684+
685+ if ( item == null || ! farmer . couldInventoryAcceptThisItem ( item ) )
686+ continue ; // Skip if item is null or farmer can't accept it
687+
688+ Vector2 debrisPosition = d . Chunks [ 0 ] . position . Value ;
689+ float distance = Vector2 . Distance ( debrisPosition , Position ) ;
690+
691+ if ( distance < range ) {
692+ // Move each chunk of debris toward the bot
693+ foreach ( var chunk in d . Chunks ) {
694+ Vector2 currentChunkPosition = chunk . position . Value ;
695+ Vector2 direction = ( Position - currentChunkPosition ) ;
696+ direction . Normalize ( ) ;
697+
698+ // Move debris towards the bot
699+ chunk . position . Value += direction * moveSpeed * ( float ) gameTime . ElapsedGameTime . TotalSeconds ;
700+ }
701+
702+ // If debris is close enough, collect it
703+ if ( distance < 10f ) {
704+ item . Stack = d . Chunks . Count ;
705+ Item itemAdded = farmer . addItemToInventory ( item ) ;
706+ loc . debris . RemoveAt ( i ) ; // Remove debris once collected
707+ }
708+ }
709+ }
667710 }
668711
669712 public override bool checkForAction ( Farmer who , bool justCheckingForActivity = false ) {
0 commit comments