Modding Help Using tools in code

Discussion in 'Mods' started by Oranisagu, Mar 28, 2016.

  1. Oranisagu

    Oranisagu Subatomic Cosmonaut

    Heya

    I've been trying to automate some stuff on the farm I find annoying and am currently stuck on automatic milking.

    while I could try to read out the item id and quality and create a new item I'd rather not do that as I have no idea what else I'd need to take into account. so my approach was using the tool (milking pail) on cows/goats in the hopes the game would then do everything necessary (like resetting quality, daysSinceLay variables etc)

    so far my approaches are like this:
    Code:
                
    if (animal.toolUsedForHarvest == "Milk Pail")
    {
        var pail = Game1.player.getToolFromName("Milk Pail");
        if (pail != null)
        {
            // attempt 1
            pail.beginUsing(animal.home.indoors, animal.getTileX(), animal.getTileY(), Game1.player);
            // attempt 2
            pail.DoFunction(animal.home.indoors, animal.getTileX(), animal.getTileY(), 1, Game1.player);
            // attempt 3
            ((AnimalHouse)animal.home.indoors).performToolAction(pail, animal.getTileX(), animal.getTileY());
        }
    }
    
    the first attempt does nothing, as the second one. when I found the third call I thought it would make sense, but this checks against against the players location, the x/y coordinates are more or less just the direction the player is facing.

    does anyone have an idea how to do this?

    my goal would be to add a milking machine and egg collector item which simply collects this stuff daily and stores it like a chest. next up would be a way to collect stuff from machines (tapper, gem cloner, barrels and so on) and ideally a way to automatically refill those machines if they are connected to a chest (or one of the collectors) with an appropriate unprocessed item in it. I'll need to be able to add items (which act as chests) and recipes, though I think there already are some mods that do that, so I should be able to figure this out by myself.

    thanks in advance for any input
     
    • ThatNorthernMonkey

      ThatNorthernMonkey Aquatic Astronaut

      Hmmm looking at performToolAction the method doesn't seem to even use the tileX and tileY arguments - just the tool. It looks like a leftover remnant of the butchering stuff CA has left in the game.

      http://pastebin.com/N2WXwCig

      Let me look some more.

      Edit: beginUsing() seems to override the int x, int y arguments immediately. Useless lol.

      Edit2: DoFunction() looks like what you're looking for. However, it creates an item and adds it to the players inventory. You may need to break down DoFunction() and do what you previously said you didn't want to. I.e., read the variables to see if they have produce, if so create the object and put it in a chest, reset the variables.
       
        Last edited: Mar 28, 2016
      • Oranisagu

        Oranisagu Subatomic Cosmonaut

        hm, since DoFunction is a very untelling name, I gave up on trial and error and downloaded ILSpy (and it's surprisingly simple to use).

        it seems the creation of the objects is a lot easier than I imagined.
        it just looks at currentProduce, creates the item from it and then sets it to -1 (assuming it will be set again in the night). I thought I'd need to check the quality as well and then use the defaultProduceIndex or deluxeProduceIndex etc.

        so, if anyone else is wondering:
        Code:
        var farmer = Game1.player;
        if (
                animal.currentProduce > 0
                && animal.age >= animal.ageWhenMature
                && farmer.addItemToInventoryBool(
                    new StardewValley.Object(Vector2.Zero, animal.currentProduce, null, false, true, false, false),
                    false)
                )
        {
            animal.currentProduce = -1;
        }
        I removed all unnecessary checks (i.e. if the pail is equipped, since it doesn't make sense being needed if you have a milking machine).

        for now it just adds them to the inventory, so I guess I have to find out how to create a special chest item and crafting recipe.
         
          ThatNorthernMonkey likes this.

        Share This Page