Example #1
0
    /// <summary>
    /// Checks if the itemstack could be put on the tile, or inside the present tile addition
    /// </summary>
    /// <param name="stack"></param>
    /// <returns></returns>
    public bool CanAddItemStackToTile(ItemStack stack)
    {
        if (Addition != null)
        {
            // First try to put the itemstack in the tile addition if possible
            if (Addition.CanAddItemStackToTileAddition(stack))
            {
                return(true);
            }

            if (!Addition.CanContainItemOnTile(stack))
            {
                // Now that the tile addition is full, can we put the stack on top?
                // if not end the execution here
                return(false);
            }
            // Else we continue to try and put the itemstack on top of the tile
        }

        // At this point the item will end up on the floor, if the floor is full the item just gets deleted

        // If there is an itemstack, try to merge them, if the resulting itemstack (meaning some items weren't merged) is not null
        // The item stack wasn't fully added to this tile so return false
        if (ItemStack != null)
        {
            return(ItemStack.MergeResult(stack) == null);
        }

        // If we haven't returned at this point the tile contained no items and no tile addition that holds the item
        // Any regular tile can contain an itemstack (for now, for example if we add in a water tile this might not be possible)
        return(true);
    }