First Mod - dropObject not working

sully9191

Newcomer
Hi - I tried searching for this issue but didn't find any results.
I'm reading up on how to create mods at https://stardewvalleywiki.com/Modding and following the examples for creating a first project. The sample code to print any key-press to the Console is working fine. But when I paste in the sample code to drop an item on the ground, it doesn't work.

I followed other instructions on the wiki to unpack XNB files, and inside ObjectInformation I found a few different itemId's and tried them with the linked dropObject example above, but none are causing the item to drop on the ground. I've attached Visual Studio's debugger, and I can see that the itemId's are resolving to the correct items using the 'new Object( itemId, ... )' constructor. But the call to 'dropObject' always returns false, which I'm guessing means it failed.

Could the problem be the Vector2 playerLocation that I plugged into the sample code? I have tried player.GetTileLocation() and player.GetDropLocation(). I have also tried removing the code that multiplies it by 64 (Game1.tileSize). But none of those changes led to success either.

My code is below. Platform is Windows 10.

if (e.Button == SButton.Q)
{
// Concrete code for spawning:
var playerLocation = Game1.player.getTileLocation(); // also tried: player.GetDropLocation()
var itemId = 768; //solar essence
var item = new StardewValley.Object(itemId, 1, false, -1, 0);
bool result = Game1.getLocationFromName("Farm").dropObject(item, playerLocation * Game1.tileSize, Game1.viewport, true, (Farmer)null);
}
 
Last edited:
Top