Modding Help Unable To Load Custom Interior (GameLocation) Initially

Discussion in 'Mods' started by GlassArrow, May 17, 2017.

  1. GlassArrow

    GlassArrow Orbital Explorer

    I've been working on a mod that gives the ability to add custom farm buildings to the game. One of the features of it is that you can see the interior before you build it, but this seems to cause a problem. Once I'm ingame I open the build menu and when I click to see the interior I get this error:

    [03:03:23 ERROR SMAPI] An error occured in the overridden draw loop: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.​

    Important things to note:
    1. If I build the building the game loads the interior correctly.
    2. If I load a game that has the building built and go inside said building, when I access the building menu I can see the interior without that error. AKA it works.
    3. I used SMAPI 1.12 initially, but from reading the forums it seems that weird errors have been occurring so I reverted back to 1.10 to make sure it wasn't SMAPI and I get the same error regardless.
    4. I tried to load maps that were already in the base game to see if they would work with my interior screen. Farm, FarmHouse, Forest, and Town worked. Hospital and Club did not. BUT when I entered the hospital (and left) the hospital would load on the interior screen.
    5. I used ALL's code as an example on how to load custom maps and tilesheets, etc. This is generally what I do:

    GameLocation interior;
    StardewValleyCustomMod.ContentRegistry.RegisterXnb(interiorPath, interiorPath);
    xTile.Map map = Game1.content.Load<xTile.Map>(interiorPath);
    interior.isOutdoors = this.interiorOutdoor;
    interior.isFarm = this.interiorFarmable;
    interior.objects = new SerializableDictionary<Microsoft.Xna.Framework.Vector2, StardewValley.Object>();
    Game1.locations.Add(interior);

    6. I preview the interior the same way the game shows the farm when selecting where to place a building. The current state of the code for that is this (the code in 5 (above) is what get buildingInterior from):

    GameLocation buildingInterior = GetGameLocationFromBlueprint(this.CurrentBlueprint);
    Game1.currentLocation.cleanupBeforePlayerExit();
    this.hoverText = "";
    Game1.currentLocation = buildingInterior;
    Game1.currentLocation.resetForPlayerEntry();
    Game1.globalFadeToClear((Game1.afterFadeFunction)null, 0.02f);
    this.onFarm = true;
    this.cancelButton.bounds.X = Game1.viewport.Width - Game1.tileSize * 2;
    this.cancelButton.bounds.Y = Game1.viewport.Height - Game1.tileSize * 2;
    Game1.displayHUD = false;
    Game1.viewportFreeze = true;
    Game1.viewport.Location = new Location(49 * Game1.tileSize, 5 * Game1.tileSize);
    Game1.panScreen(0, 0);
    this.drawBG = false;
    this.freeze = false;
    Game1.displayFarmer = false;

    As far as I can tell the game does something I need to do when loading maps initially since the interior is displayed after I enter the corresponding building. I've looked through the decompiled code and I don't see anything that I don't already do and I've spent way too much time on this and need others thoughts.

    Thanks and let me know if you need more info!
     

      Attached Files:

    Share This Page