Container inventory populated with duplicate items

Issue #25 resolved
Starwaster created an issue

Chest block inventory space gets populated with a duplicate of the hot bar inventory.

This happens when:

  1. I create a world
  2. put the chest blocks in the world
  3. exit the world
  4. access the block
  5. If I access the items in the inventory space the game sometimes crashes (see attached crash log)

Comments (16)

  1. Starwaster reporter

    More information: It's only happening to blocks whose tile entities I've written data to.

    Example:

    onPlacedByPlayer[6] = "world.setTileEntityIntData(position, 'storedEMC', 0); mod.loadScript('updateRelayNeighbors.js');";

    (the script updateRelayNeighbors() also saves data to the tile entity)

    var coordOffset = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]];
    var EEStoneID = config.getBlockId("BlockEEStone");
    var condenserID = config.getBlockId("condenserID");
    var isValid = false;
    var newPosition = [];
    var adjacentNeighbors = [];
    var blockID;
    
    world.sendMessageToAllPlayers("executing updateRelayNeighbors.js");
    function isValidNeighbor(location)
    {
        var blockID = world.getBlockId(location[0], location[1], location[2]);
        var isValid = false;
    
        if (blockID == condenserID)
        {
            isValid = true;
        }
        else if (blockID == EEStoneID)
        {
    
            world.sendMessageToAllPlayers("Found candidate");
            switch(world.getBlockMetadata(location[0], location[1], location[2]))
            {
            case 0:
                    isValid = true;
                    break;
                case 1:
                    isValid = true;
                    break;
                case 2:
                    isValid = true;
                    break;
            default:
                    isValid = false;
                    break;                  
            }
        }
        return isValid;
    }
    
    //world.sendMessageToAllPlayers("Updating neighbor list. Variables set.");
    for (i in coordOffset)
    {
        newPosition[0] = position.x + coordOffset[i][0];
        newPosition[1] = position.y + coordOffset[i][1];
        newPosition[2] = position.z + coordOffset[i][2];
        //world.sendMessageToAllPlayers("Loop #" + i + " " + newPosition[0] + ", "+ newPosition[1] + ", "+ newPosition[2]);
    
        if (isValidNeighbor(newPosition))
        {
            //world.sendMessageToAllPlayers("found adjacent device at " + JSON.stringify(newPosition));
            adjacentNeighbors.push([newPosition[0], newPosition[1], newPosition[2]]);
            //world.sendMessageToAllPlayers("Added array: " + JSON.stringify(adjacentNeighbors));
        }
    }
    world.sendMessageToAllPlayers("About to write to tile entity string data: " + JSON.stringify(adjacentNeighbors));
    world.setTileEntityStringData(position, "adjacentNeighbors", JSON.stringify(adjacentNeighbors));
    
  2. Starwaster reporter

    Block, TE and GUI files attached.

    Some more information: (addendum to step 4 in repro steps)

    You may need to access multiple blocks. The inventory may display normally when activating the first block. Second block shows some corruption, then third block shows even more. Alternating back and forth sometimes adds an extra row of inventory.

    SOMETIMES this has resulted in actual item duplication, Or it might crash. I have also crashed even just accessing a block even if it doesn't have corrupted inventory. (this was on a world that I put ordinary chest blocks, the 'alchemical chest' and 'condenser', exited and re-entered then accessed block. Neither of those does anything unusual with the tile entities or inventories)

  3. Starwaster reporter

    I made some changes in it while trying to track this down. My earlier assumptions about what's triggering this were wrong. (about it only happening if I wrote data to the tile entity). I've commented out all events other than onActivated so it shouldn't be running any other scripts from those events. Also changed onActivated so it's only trying to open the GUI.

    Currently when I try to test, the bug seems to manifest immediately. GUI doesn't open and inventory gets corrupted.

  4. cubex2 repo owner

    There is a error in your mod.js file. You use "57:0" for mod.addCreativeTab() but you should only use a id for the second argument. I'm not able to reproduce this bug, everything works as intented. Maybe I've already fixed that. I'll release an update in the next minutes. Try this update and tell me if it still happen.

  5. Starwaster reporter

    Thanks for pointing the error out to me, I forgot that the itemBlock object that I was loading there was using strings. However that particular line would get called exactly once, if there isn't already a config file with the item ID I wanted. I guess I never actually tested what would happen if I was running it 'for the first time.'

    However, with regards to the inventory corruption / crashing bug, I am still experiencing it with 10.1. I've tried updating Forge, I'm currently on Forge build 702 (for 1.5.2)

    What versions of Minecraft and Forge did you test with?

  6. Starwaster reporter

    So maybe it's a Forge bug relating to how they deal with inventory array indices. Looking at the error, it seems like the index offset is off by 1 when it crashes. i.e. index 127 on a size 127 inventory array would definitely be out of bounds . Those array sizes by the way correspond exactly to the total size of the chest + player inventory (including hotbar) every time I've checked.

  7. Starwaster reporter

    Just tried falling back to build 685 but it didn't help.

    Although I consider this to be a bug there's clearly something in my mod that I've done to trigger this because shortly after I filed this ticket I tried creating a new barebones mod that does nothing more than add a chest block (tile entity type chestblock) with multiple blocks using meta but couldn't replicate the problem.

  8. cubex2 repo owner

    Okay, I may have fixed this issue but you have to replace all existing blocks to make them work.

  9. Log in to comment